March 2018
Intermediate to advanced
1396 pages
42h 14m
English
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, ...