Ask Your Question
0

Using subscriber to subscribe the Lidar's signal Topic

asked 2015-12-30 00:43:15 -0500

Terry Su gravatar image

updated 2015-12-30 01:02:11 -0500

Akif gravatar image

Hello ROS users, I am using a subscriber to subscribe lidar's signal. I have watched the subscriber and publisher example(C++) tutorial's video and use catkin_ws to build a package, and I make a sick_listen roscpp file which the coding is copied from the listener in the tutorial. And I modify the coding for using it to subscribe the my lidar's signal topic. The coding as below is what I modified and my spec of my ROS

include "ros/ros.h"

include "std_msgs/String.h"

void laser_msg_Callback(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, "sick_listener"); 

  ros::NodeHandle n;

  ros::Subscriber sub = n.subscribe("scan", 811, laser_msg_Callback);

  ros::spin();

  return 0;

}

Spec: ubuntu 14.04LTS, Jade ROS, sick tim 561 lidar

And These are the message type of the "lidar's topic" and "talker's topic which is from the tutorial" comparison:

 1. terry@terry-All-Series:~$ rostopic type  /chatter std_msgs/String
 2. terry@terry-All-Series:~$ rostopic type  /scan sensor_msgs/LaserScan

When I run the code of sick_listen, it shows the error as below:

[ INFO] [1451458683.021191460]: Waiting 50 seconds for device to connect.
[ INFO] [1451458683.021602292]: Succesfully connected to 192.168.1.144:2111
[ERROR] [1451458683.224815412]: Client [/sick_listener] wants topic /scan to have datatype/md5sum [std_msgs/String/992ce8a1687cec8c8bd883ec73ca41d1], but our version has [sensor_msgs/LaserScan/90c7ef2dc6895d81024acba2ac42f369]. Dropping connection.

I am a niewbe in the ROS and not to familiar to the c code,so do I need to use the other header of the code for the lidar? I would be thankful if someone can give me some direction.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
4

answered 2015-12-30 01:06:47 -0500

Akif gravatar image

updated 2015-12-30 01:08:22 -0500

As the error tells, your message types are inconsistent. Try the correct message type which is sensor_msgs::LaserScan instead of std_msgs::String.

void laser_msg_Callback(const sensor_msgs::LaserScan::ConstPtr& scan)
{
  //you can get readings with scan->ranges[]
}

And also of course you should add #include "sensor_msgs/LaserScan.h".

edit flag offensive delete link more

Comments

Hello Akif, when I follow your advice to add the header and "scan->ranges[]", it has an error as: expected primary-expression before ‘]’ token ROS_INFO("I heard: [%s]", scan->ranges[]);

Terry Su gravatar imageTerry Su ( 2015-12-30 02:17:50 -0500 )edit

@Terry Su, You should also write your index of data. Like scan->ranges[0], scan->ranges[1] etc. , whichever reading you want to get.

Akif gravatar imageAkif ( 2015-12-30 02:43:29 -0500 )edit

@Akif, It is really works! Thank you so much! Could you please tell me that the index meaning in the braket of "range[]", I search it after you told me to input the index, but nothing. Finally, thank you.

Terry Su gravatar imageTerry Su ( 2015-12-30 04:01:37 -0500 )edit

index will depend on the sensor. For example, if it is measuring 180 deg. with 1 deg. resolution, then your ranges array size will be probably 181, i.e., each range measurement depending on the angle. You can check the size of ranges. Also, if your problem solved please mark answer as correct.

Akif gravatar imageAkif ( 2015-12-30 04:44:16 -0500 )edit

@Akif, My lidar's scan range is 270 deg with 0.333 deg resolution, so the index what I need is ranges[811] because 270/0.33=811,its right? And the subscriber's receive data what terminal shows is like: - [ INFO] [1451481162.429434168]: I heard: [P?j] - [ INFO] [1451481162.429434168]: I heard:[?]

Terry Su gravatar imageTerry Su ( 2015-12-30 07:15:26 -0500 )edit

Is this because the value is array, so that shows up the strange value as "[P?j]", "[?]" or something like that?

Terry Su gravatar imageTerry Su ( 2015-12-30 07:21:38 -0500 )edit

Are you printing with %s? I think you should try %f for float.

Akif gravatar imageAkif ( 2015-12-30 07:37:58 -0500 )edit

@ Akif, Yes! Thank you so much. But when I change the index to range[811], it just show 1 value of distance. But when I use the "rostopic echo /scan", it shows 811 values. I also search the "range[]" in the website and ROS, but just see the laser msg type.

Terry Su gravatar imageTerry Su ( 2015-12-30 08:26:31 -0500 )edit
1

answered 2015-12-30 01:10:35 -0500

you need to import the definition for the type of message you are receiving, and create a callback that takes that format of message (LaserScan rather than String)

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2015-12-30 00:43:15 -0500

Seen: 721 times

Last updated: Dec 30 '15