Ask Your Question

how to bind a callback to include a MessageEvent [closed]

asked 2011-03-28 11:41:18 -0500

aleeper gravatar image

updated 2022-02-22 11:29:33 -0500

lucasw gravatar image

I am trying to use MessageEvent to get topic information in a callback. While I have referred to the example here

and here

I can't figure out how to use boost::bind to tell the subscriber to give me both the PointCloud message and the MessageEvent. Is there an example of this somewhere? Here is what I have, which is definitely wrong:

  sub_cloud_ = nh_.subscribe<sensor_msgs::PointCloud2>
              (input_topic_, 1, 
                boost::bind(&HapticNode::cloudCallback, this, _1, _2));

  void HapticNode::cloudCallback(const sensor_msgs::PointCloud2ConstPtr &input, 
                       const ros::MessageEvent<std_msgs::String const>& event)
    std::string topic;
    const std::string& publisher_name = event.getPublisherName();
    ros::M_string connection_header = event.getConnectionHeader();
    topic = connection_header["topic"];

    ROS_INFO("Got a cloud on topic %s in frame %s with %d points!",
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by aleeper
close date 2015-06-24 19:22:57.869080

1 Answer

Sort by ┬╗ oldest newest most voted

answered 2011-03-28 19:40:50 -0500

I think you want to use the getMessage method of the MessageEvent instance that you have. Adapting the example from the documentation,

void callback(const ros::MessageEvent<sensor_msgs::PointCloud2 const>& event)
  const std::string& publisher_name = event.getPublisherName();
  const ros::M_string& header = event.getConnectionHeader();
  ros::Time receipt_time = event.getReceiptTime();

  const sensor_msgs::PointCloud2& input = event.getMessage();

  ROS_INFO("Got a cloud on topic %s in frame %s with %d points!",
edit flag offensive delete link more

Question Tools


Asked: 2011-03-28 11:41:18 -0500

Seen: 1,844 times

Last updated: Mar 28 '11