ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Getting multiple values of Scan from Callback Function

asked 2016-10-16 01:58:45 -0500

updated 2016-10-16 02:03:00 -0500

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";
}

image description

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-10-16 05:37:30 -0500

NEngelhard gravatar image

If you only want a single message, you could use waitformessage. This is a bit slower as a new subscriber has to be created, but it gives you a single message without having to define a callback.

edit flag offensive delete link more

Comments

Another option is only using the callback message once when the robot is not moving, then wait until you move again to use the callback message. This can be accomplished with flags in the callback message that update when you move or stop moving.

JoshMarino gravatar image JoshMarino  ( 2016-10-16 07:44:54 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-16 01:58:45 -0500

Seen: 272 times

Last updated: Oct 16 '16