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

Subscriber not generating output!! [closed]

asked 2014-12-06 05:29:48 -0600

Aarif gravatar image

Hello, I am making a simple subscriber which will subscribe to /lms200 topic on which Laser Data is being published.

I went through the ROS tutorial Writing a Simple Publisher and Subscriber (C++), and wrote the following subscriber node, it has been complied successfully but neither it generate any output not any error.

Here is my sample code:

#include "ros/ros.h"
#include "std_msgs/String.h"

void chatterCallback(const std_msgs::String::ConstPtr& msg)
    ROS_INFO("I heard: [%s]", msg->data.c_str());

int main(int argc, char **argv)
    ros::init(argc, argv, "redirector");
    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe("lms200", 1000, chatterCallback);
    return 0;

following is the output when i executes the $rospotic echo /lms200

  seq: 296
    secs: 1417864716
    nsecs: 451817364
  frame_id: lms200
angle_min: -1.5707000494
angle_max: 1.5707000494
angle_increment: 0.0174000002444
time_increment: 0.0
scan_time: 0.0
range_min: 0.10000000149
range_max: 20.0
ranges: [9.380000114440918, 9.380000114440918, 9.380000114440918, 9.390000343322754, 9.390000343322754, 9.399999618530273, 9.420000076293945, 9.430000305175781, 9.449999809265137, 9.470000267028809, 9.5, 9.529999732971191, 9.5600004196167, 9.59000015258789, 9.630000114440918, 9.670000076293945, 1.7699999809265137, 1.7699999809265137]
intensities: []

and following is the output when i executes the following command:-

cr-lab-tu@crlabtu-HP-Z800-Workstation:~$ rostopic info /lms200
Type: sensor_msgs/LaserScan

 * /RosSim (http://crlabtu-HP-Z800-Workstation:55152/)

 * /redirector (http://crlabtu-HP-Z800-Workstation:40278/)


Please help me out to solve the problem.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Aarif
close date 2014-12-06 13:02:41.552287

1 Answer

Sort by » oldest newest most voted

answered 2014-12-06 05:49:41 -0600

bvbdort gravatar image

updated 2014-12-06 12:15:35 -0600

Add message type to subscriber and correct message type in call back. check 1,2,3 comments

//2. recieves message of laserscan type
void chatterCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
    ROS_INFO("I heard: [%s]", msg->header.seq); // 3.prints sequence number of scan

int main(int argc, char **argv)
    ros::init(argc, argv, "redirector");
    ros::NodeHandle n;
   //1. add message type sensor_msgs::LaserScan to subbscriber
    ros::Subscriber sub = n.subscribe<sensor_msgs::LaserScan>("lms200", 1000, chatterCallback); 

    return 0;
edit flag offensive delete link more


hello @bvbdort, thanks a lot for looking into it, i have followed your code and also included "sensor_msgs/LaserScan.h" file, but it is generating following at comment 3:-

const struct sensor_msgs::LaserScan_<std::allocator<void> >’ has no member named ‘seq

how can i resolve this, Thank you :)

Aarif gravatar image Aarif  ( 2014-12-06 11:52:46 -0600 )edit

sorry, i missed that seq is member of header. i updated it

bvbdort gravatar image bvbdort  ( 2014-12-06 12:16:13 -0600 )edit

thank you so much @bvbdort for your kind help, it was giving 1 more warning as:

format ‘%s’ expects argument of type ‘char*’, but argument 8 has type ‘std_msgs::Header_<std::allocator<void> >::_seq_type {aka unsigned int}’ [-Wformat]

I've fixed it by using %d instead of %s in comment 3


Aarif gravatar image Aarif  ( 2014-12-06 13:01:38 -0600 )edit

its working now!!!

Aarif gravatar image Aarif  ( 2014-12-06 13:01:57 -0600 )edit

Question Tools

1 follower


Asked: 2014-12-06 05:29:48 -0600

Seen: 690 times

Last updated: Dec 06 '14