correll / advancedrobotics

Advanced Robotics class repository
GNU General Public License v2.0
13 stars 5 forks source link

Publish Sensor Streams Over ROS #47

Closed bryanbocao closed 8 years ago

bryanbocao commented 8 years ago

RobotSetup 2.3 Sensor Information (sensor sources)

Publish Sensor Streams Over ROS

Sub-issue of #36

bryanbocao commented 8 years ago

Navigate to /home/ubuntu/catkin_ws/src, create a catkin package sensor_driver by command:

ubuntu@tegra-ubuntu:~$  cd /home/ubuntu/catkin_ws/src
ubuntu@tegra-ubuntu:~/catkin_ws/src$ catkin_create_pkg sensor_driver roscpp std_msgs sensor_msgs

Creating a publisher node ("laser_scan_publisher"):

Navigate to /home/ubuntu/catkin_ws/src/sensor_driver/src, create LaserScan_Publisher.cpp with the code in 4.2 Writing Code to Publish a LaserScan Message in Publishing Sensor Streams Over ROS.

A publisher node ("laser_scan_publisher") will be created and initialized by running the following code in LaserScan_Publisher.cpp:

   5   ros::init(argc, argv, "laser_scan_publisher");
   6 
   7   ros::NodeHandle n;
   8   ros::Publisher scan_pub = n.advertise<sensor_msgs::LaserScan>("scan", 50);

Creating a publisher node ("point_cloud_publisher"):

Navigate to /home/ubuntu/catkin_ws/src/sensor_driver/src, create PointCloud_Publisher.cpp with the code in 5.2 Writing Code to Publish a PointCloud Message in Publishing Sensor Streams Over ROS.

A publisher node ("point_cloud_publisher") will be created and initialized by running the following code in PointCloud_Publisher.cpp:

   5   ros::init(argc, argv, "point_cloud_publisher");
   6 
   7   ros::NodeHandle n;
   8   ros::Publisher cloud_pub = n.advertise<sensor_msgs::PointCloud>("cloud", 50);

Building the code:

Add the following lines to the bottom of the CMakeLists.txt file in /home/ubuntu/catkin_ws/src/sensor_driver:

add_executable(LaserScan_Publisher src/LaserScan_Publisher.cpp)
add_executable(PointCloud_Publisher src/PointCloud_Publisher.cpp)
target_link_libraries(LaserScan_Publisher ${catkin_LIBRARIES})
target_link_libraries(PointCloud_Publisher ${catkin_LIBRARIES})

Build the package by

ubuntu@tegra-ubuntu:~$ cd /home/ubuntu/catkin_ws
ubuntu@tegra-ubuntu:~/catkin_ws$ catkin_make