Getting multiple values of Scan from Callback Function
I have made a subscriber to pioneer/laser/scan for the scan values of laser on P3AT.
When I run the subscriber, it just doesn't stop. It keeps on running. I want only a single value of the scan i.e. the ranges[] array even if the robot is standing.
And also the value of any index in ranges[] array fluctuates ranges[i] - 0.2 to ranges[i] + 0.2
How to get a single valued array ranges[] when the robot is not moving? I need only one value for one index so that I can process it further.
P.S. I am using these lines of code and obstaclesCallBack is my function for printing the scan values. I am attaching an image where I am printing the ranges[180] value. Notice that it is fluctuating even if the robot is standing.
ros::NodeHandle laser_n;
ros::Subscriber sub = laser_n.subscribe<sensor_msgs::LaserScan>("pioneer/laser/scan", 1000, obstaclesCallback);
void obstaclesCallback(const sensor_msgs::LaserScan::ConstPtr& msg) {
std::cout<<msg->ranges[180]<<"\n";
}