Escolar Documentos
Profissional Documentos
Cultura Documentos
http://ftp.isr.ist.utl.pt/pub/roswiki/navigation(2f)Tutorials(2f...
navigation/Tutorials/RobotSetup/Sensors
[Documentation] [TitleIndex] [WordIndex] Note: This tutorial assumes that you have completed the Transform Configuration tutorial. All the code for this tutorial is available in the laser_scan_publisher_tutorial and point_cloud_publisher_tutorial packages..
1 of 8
05/20/2013 05:11 PM
navigation/Tutorials/RobotSetup/Sensors
http://ftp.isr.ist.utl.pt/pub/roswiki/navigation(2f)Tutorials(2f...
2 of 8
05/20/2013 05:11 PM
navigation/Tutorials/RobotSetup/Sensors
http://ftp.isr.ist.utl.pt/pub/roswiki/navigation(2f)Tutorials(2f...
float32 scan_time # time between scans [seconds] float32 range_min # minimum range value [m] float32 range_max # maximum range value [m] float32[] ranges # range data [m] (Note: values < range_min or > range_max should be discarded) float32[] intensities # intensity data [device-specific units]
Hopefully, the names/comments above make most of the fields in the Message clear. To make things concrete, let's write a simple laser scan publisher to demonstrate how things work.
3 of 8
05/20/2013 05:11 PM
navigation/Tutorials/RobotSetup/Sensors 39 40 41 42 43 44 45 46 } 47 } 48
http://ftp.isr.ist.utl.pt/pub/roswiki/navigation(2f)Tutorials(2f...
Here, we include the sensor_msgs/LaserScan message that we want to send over the wire.
Toggle line numbers
8 ros::Publisher scan_pub = n.advertise<sensor_msgs::LaserScan> ("scan", 50); 9
This code creates a ros::Publisher that is later used to send LaserScan messages using ROS.
Toggle line numbers
10 11 12 13 14 unsigned int num_readings = 100; double laser_frequency = 40; double ranges[num_readings]; double intensities[num_readings];
Here we're just setting up storage for the dummy data that we're going to use to populate our scan. A real application would pull this data from their laser driver.
Toggle line numbers
18 19 20 21 22 23 24 //generate some fake data for our laser scan for(unsigned int i = 0; i < num_readings; ++i){ ranges[i] = count; intensities[i] = 100 + count; } ros::Time scan_time = ros::Time::now();
Populate the dummy laser data with values that increase by one every second.
4 of 8
05/20/2013 05:11 PM
navigation/Tutorials/RobotSetup/Sensors
http://ftp.isr.ist.utl.pt/pub/roswiki/navigation(2f)Tutorials(2f...
Create a scan_msgs::LaserScan message and fill it with the data that we've generated in preparation to send it over the wire.
Toggle line numbers
43 44 scan_pub.publish(scan);
5 of 8
05/20/2013 05:11 PM
http://ftp.isr.ist.utl.pt/pub/roswiki/navigation(2f)Tutorials(2f...
6 of 8
05/20/2013 05:11 PM
navigation/Tutorials/RobotSetup/Sensors 3
http://ftp.isr.ist.utl.pt/pub/roswiki/navigation(2f)Tutorials(2f...
Creates the ros::Publisher that we'll use to send PointCloud messages out over the wire.
Toggle line numbers
15 16 17 18 sensor_msgs::PointCloud cloud; cloud.header.stamp = ros::Time::now(); cloud.header.frame_id = "sensor_frame";
Fill in the header of the PointCloud message that we'll send out with the relevant frame and timestamp information.
Toggle line numbers
19 20 cloud.set_points_size(num_points);
Set the number of points in the point cloud so that we can populate them with dummy data.
Toggle line numbers
21 22 23 24 25 //we'll also add an intensity channel to the cloud cloud.set_channels_size(1); cloud.channels[0].name = "intensities"; cloud.channels[0].set_values_size(num_points);
Adds a channel called "intensity" to the PointCloud and sizes it to match the number of points that we'll have in the cloud.
Toggle line numbers
26 27 28 29 30 31 32 33 //generate some fake data for our point cloud for(unsigned int i = 0; i < num_points; ++i){ cloud.points[i].x = 1 + count; cloud.points[i].y = 2 + count; cloud.points[i].z = 3 + count; cloud.channels[0].values[i] = 100 + count; }
7 of 8
05/20/2013 05:11 PM
navigation/Tutorials/RobotSetup/Sensors
http://ftp.isr.ist.utl.pt/pub/roswiki/navigation(2f)Tutorials(2f...
Populates the PointCloud message with some dummy data. Also, populates the intensity channel with dummy data.
Toggle line numbers
34 35 cloud_pub.publish(cloud);
8 of 8
05/20/2013 05:11 PM