Ask Your Question
0

Getting multiple values of Scan from Callback Function

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

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

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 -0600

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 imageJoshMarino ( 2016-10-16 07:44:54 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 142 times

Last updated: Oct 16 '16