[ros-users] How to get copy of message using MessageEvent callback?

Josh Faust jfaust at willowgarage.com
Mon Oct 25 17:51:05 UTC 2010


On Mon, Oct 25, 2010 at 10:32 AM, Patrick Bouffard <
bouffard at eecs.berkeley.edu> wrote:

> Thanks Josh. I did try a lot of versions of the callback declaration
> and the getMessage line, taking away that const for instance but still
> could not get it to work. What still puzzles me is that my code is
> basically copy & paste from the documentation page that I cited, the
> only difference being the message type is control_mode_status (my own
> message type) and not std_msgs::String as in the example in the docs.
>
>
You have two sets of errors there, one of which is unrelated to the
MessageEvent.  Did you maybe fix one problem but not the other?

And, just to be sure, did you try:
const control_mode_statusConstPtr& msg = event.getMessage();

?

In a quick test, both:
void chatterCallback(const ros::MessageEvent<std_msgs::String const>& evt)
{
  const std_msgs::StringConstPtr msg = evt.getMessage();
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}

and

void chatterCallback(const ros::MessageEvent<std_msgs::String>& evt)
{
  const std_msgs::StringPtr msg = evt.getMessage();
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}

work fine.

Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20101025/ef793dc0/attachment-0003.html>


More information about the ros-users mailing list