Ask Your Question

Having trouble with the chattercallback function in a ROS subscriber?

asked 2014-02-18 07:29:10 -0500

randylewis7 gravatar image

updated 2014-02-18 07:36:35 -0500

ahendrix gravatar image

Hello, I'm trying to write a ROS subscriber to subscribe to some of the data from the kinect sensor on a turtlebot. I started by copying the subscriber part of the tutorial here: h t t p : / / w i k i . r o s . o r g / R O S / T u t o r i a l s / W r i t i n g P u b l i s h e r S u b s c r i b e r % 2 8 c % 2 B % 2 B % 2 9, and then copying and modifying the various parts of the program to fit the topics that I'm trying to subscribe to. For example, one of the topics I'm trying to subscribe to is /odom, and my code for this part is as follows: //(outside the main class) void blabberingEavesdropper(const std_msgs::String::ConstPtr& msg) //modification of the chatterCallback function { ROS_INFO("I heard: [%s]", msg->data.c_str()); } //(inside the main class) ros::Subscriber odomSub = n.subscribe("/odom", 1000, blabberingEavesdropper);

When I catkin_make, the node compiles without errors, but then when I start up the turtlebot (turn it on as well as run minimal.launch and 3dsensor.launch), I get the following error (at least for the /odom part): Since I get a similar error message for each topic, and they all say that the subscriber wants the topic to have the same data type (std_msgs/String/some_random_number), I think my problem is with the chatterCallBack functions (renamed blabberingEvasedropper). I can't figure out exactly what to put in the arguments that will not cause this error, and that won't cause errors when I try to catkin_make my program. My goal is just to have the blabberingEvasedropper function print out the message it received on the screen. Anyone know how to do this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-02-19 19:01:54 -0500

hamid gravatar image

updated 2014-02-21 04:47:55 -0500

try this:

 void blabberingEavesdropper(nav_msgs::Odometry& msg)

for subscribe the laser scanner data:

void laser(const sensor_msgs::LaserScan& msg)
    for(int i=0;i<msg.ranges.size();i++)
edit flag offensive delete link more


Ok cool, I did that and it worked. However, now I'm trying to extrapolate this solution to the others topics, and again I'm running into problems. Right now I have: void blabberingEavesdropperLaserScan(const sensor_msgs::LaserScan scanner) { for (r=0;r++;r<=length(scan.ranges)) { ROS_INFO("Ranges[%d]: %f", r,scan.ranges(r); } for (i=0;i++;i<=length(scan.intensities)) { ROS_INFO("Intensities[%d]: %f", i,scan.intensities(i)); } } (sorry, don't know how to use code tags here), but when I try to compile, ros tells me that 'sensor_msgs' does not name a type.

randylewis7 gravatar imagerandylewis7 ( 2014-02-20 12:52:15 -0500 )edit

Great, that worked again, thank you!

randylewis7 gravatar imagerandylewis7 ( 2014-02-24 15:39:49 -0500 )edit

Looks like your problem has been solver. Hence, please select this answer (checker symbol) thereby marking your question as anwered.

bit-pirate gravatar imagebit-pirate ( 2014-03-30 17:29:19 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2014-02-18 07:29:10 -0500

Seen: 710 times

Last updated: Feb 21 '14