Skip to Content
ROS Programming: Building Powerful Robots
book

ROS Programming: Building Powerful Robots

by Anil Mahtani, Luis Sanchez, Enrique Fernandez, Aaron Martinez, Lentin Joseph
March 2018
Intermediate to advanced content levelIntermediate to advanced
1396 pages
42h 14m
English
Packt Publishing
Content preview from ROS Programming: Building Powerful Robots

Accessing the laser data and modifying it

Now, we are going to make a node get the laser data, do something with it, and publish the new data. Perhaps, this will be useful at a later date, and with this example, you will learn how to do it.

Copy the following code snippet to the c8_laserscan.cpp file in your /chapter8_tutorials/src directory:

#include <ros/ros.h> 
#include "std_msgs/String.h" 
#include <sensor_msgs/LaserScan.h> 
 
#include<stdio.h> 
using namespace std; 
class Scan2{ 
  public: 
  Scan2(); 
  private: 
  ros::NodeHandle n; 
  ros::Publisher scan_pub; 
  ros::Subscriber scan_sub; 
  void scanCallBack(const sensor_msgs::LaserScan::ConstPtr&  scan2); }; Scan2::Scan2() { scan_pub = n.advertise<sensor_msgs::LaserScan>("/scan2",1); scan_sub = n.subscribe<sensor_msgs::LaserScan>("/scan",1, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Robots with ROS

Programming Robots with ROS

Morgan Quigley, Brian Gerkey, William D. Smart
Machine Learning Design Patterns

Machine Learning Design Patterns

Valliappa Lakshmanan, Sara Robinson, Michael Munn

Publisher Resources

ISBN: 9781788627436Supplemental Content