Using RPLidar Scan Result Data
Hi, I am using the RPLidar ROS SDK on ROS Kinetic Kame on Ubuntu 16.04. This code outputs laser scan data from the RPlidar.
include "ros/ros.h"
#include "sensor_msgs/LaserScan.h"
#define RAD2DEG(x) ((x)*180./M_PI)
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan)
{
int count = scan->scan_time / scan->time_increment;
ROS_INFO("I heard a laser scan %s[%d]:", scan->header.frame_id.c_str(), count);
ROS_INFO("angle_range, %f, %f", RAD2DEG(scan->angle_min), RAD2DEG(scan->angle_max));
for(int i = 0; i < count; i++) {
float degree = RAD2DEG(scan->angle_min + scan->angle_increment * i);
ROS_INFO(": [%f, %f]", degree, scan->ranges[i]);
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "rplidar_node_client");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe<sensor_msgs::LaserScan>("/scan", 1000, scanCallback);
ros::spin();
return 0;
}
So here is my question, I want to use the "scan->ranges[i])" data in my Int main for a robot I am using to avoid objects. I never programmed in ROS and C++ before so I am at a loss. I want my if statement to do something like
if(scan->ranges[i] > 1.5){ robotstop; }