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

Revision history [back]

The subscriber in your code is still expecting a message type of std_msgs/String as defined in the function declaration here, which is why the node is producing the error message:

 void chatterCallback(const std_msgs::String::ConstPtr& msg)

You need to change this so it matches the type of the topic you're trying to subscribe to, in this case a visualization_msgs/MarkerArray. The new function declaration will look like this:

 void chatterCallback(const visualization_msgs::MarkerArray::ConstPtr& msg)

However there are two more changes you need to make to your code and one that you should.

First, you're currently including the Marker message header not the MarkerArray header, so this should be:

#include <visualization_msgs/MarkerArray.h>

Second, the MarkerArray message type doesn't have a string member called data as string does, so you'll need to print some other information out to test this or the code won't compile. You could for example print out the number of markers in the array:

ROS_INFO("I received a MarkerArray with [%s] markers", (int)msg->markers.size());

Finally you should remove the #include "std_msgs/String.h" header because it's no longer used.

Hope this helps.

The subscriber in your code is still expecting a message type of std_msgs/String as defined in the function declaration here, which is why the node is producing the error message:

 void chatterCallback(const std_msgs::String::ConstPtr& msg)

You need to change this so it matches the type of the topic you're trying to subscribe to, in this case a visualization_msgs/MarkerArray. The new function declaration will look like this:

 void chatterCallback(const visualization_msgs::MarkerArray::ConstPtr& msg)

However there are two more changes you need to make to your code and one that you should.

First, you're currently including the Marker message header not the MarkerArray header, so this should be:

#include <visualization_msgs/MarkerArray.h>

Second, the MarkerArray message type doesn't have a string member called data as string does, so you'll need to print some other information out to test this or the code won't compile. You could for example print out the number of markers in the array:

ROS_INFO("I received a MarkerArray with [%s] markers", (int)msg->markers.size());

Finally you should remove the #include "std_msgs/String.h" "std_msgs/String.h" header because it's no longer used.

Hope this helps.