ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to read message from ros::MessageEvent object

asked 2012-12-13 03:55:40 -0500

Subhash gravatar image

updated 2014-01-28 17:14:33 -0500

ngrennan gravatar image

I am trying to extract content of the message from ros::MessageEvent object.

The parameter ros::MessageEvent<topic_tools::shapeshifter const=""> msg_event is passed to subscription callback function. We know the message type and definition. How can we extract the content of message from ShapeShifter object?

I am trying to do this. But I am stuck about how extract the information further. boost::shared_ptr<topic_tools::shapeshifter const=""> pose = msg_event.getMessage();


edit retag flag offensive close merge delete


Unfortunately, you failed to provide some information which makes it hard to be helpful. Please provide real code and the actual error messages you get. Additionally, always provide your Ubuntu version and the ROS version you are using. Read

Lorenz gravatar image Lorenz  ( 2012-12-16 21:45:43 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-12-16 21:52:47 -0500

Lorenz gravatar image

updated 2012-12-16 21:53:33 -0500

I don't know how your code exactly looks like or what exactly you are trying to do but in order to instantiate a real message from a shape shifter message, you need to know its type and and you need to include the corresponding header files. For instance, to instantiate a geometry_msgs::Pose message:

#include <geometry_msgs/Pose.h>

void pose_subscriber(const boost::shared_ptr<const topic_tools::ShapeShifter> message) {
  boost::shared_ptr<geometry_msgs::Pose> pose = message.instantiate<geometry_msgs::Pose>();
  // Do stuff...

// The subscriber somewhere in your code...
ros::Subscriber subscriber = node_handle.subscribe<topic_tools::ShapeShifter>("pose_topic", 1, &pose_subscriber);
edit flag offensive delete link more

Question Tools


Asked: 2012-12-13 03:55:40 -0500

Seen: 1,125 times

Last updated: Dec 16 '12