Ask Your Question
0

Subscriber callback function

asked 2016-03-23 01:18:11 -0500

Arpit gravatar image

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.

And also the value of any index in ranges[] array fluctuates ranges[i] - .2 to ranges[i] + .2

How to get only a single array ranges[] when subscribing to the scan?

P.S. I am using these lines of code and obstaclesCallBack is my function for printing the scan values.

ros::NodeHandle laser_n;
ros::Subscriber sub = laser_n.subscribe<sensor_msgs::LaserScan>("pioneer/laser/scan", 1000, obstaclesCallback);
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-03-23 03:58:44 -0500

gvdhoorn gravatar image

When I run the subscriber, it just doesn't stop. It keeps on running.

That is the normal (and desired) behaviour of subscribers, yes.

I want only a single value of the scan i.e. the ranges[] array.

Easiest is probably to use ros::topic::waitForMessage(..) for that.

edit flag offensive delete link more
0

answered 2016-03-23 06:09:49 -0500

YingHua gravatar image

Do you mean you only want to show range array message?

How about show me your callback function?

here is my idea,maybe helpful :)

image description

image description

edit flag offensive delete link more

Comments

Do I need to do anything else if I want to use the range_max value from the LaserScan.msg inside the Callback function? I want to use that value to drive my robot to the maximum distance possible.

Basically I am trying to make the turtlebot drive out through the door of a room. Thanks.

Sanat gravatar imageSanat ( 2019-03-01 07:28:10 -0500 )edit
Sanat gravatar imageSanat ( 2019-03-01 07:40:43 -0500 )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-03-23 01:18:11 -0500

Seen: 627 times

Last updated: Mar 23 '16