Ask Your Question
0

How can I use the data from the LaserScan.msg inside the callback function?

asked 2019-03-01 07:39:01 -0500

Sanat gravatar image

updated 2019-03-01 08:10:19 -0500

Delb gravatar image

So I have this call back function where I want to do something with the range_max value.

 void LaserCallback(const sensor_msgs::LaserScan::ConstPtr& scan){
   float x = range_max;

//and then use that for anything or do I have to do anything else before that line? 
}

someone at this ( https://answers.ros.org/question/6023... )answer suggested something called AutoExp::processLaserScan, but how do I know which heades to include?

Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-03-01 08:17:21 -0500

Delb gravatar image

The answer you linked is just an example where the person didn't modify his code. AutoExp::processLaserScan just means that this person created a method processLaserScan (exactly how you defined LaserCallback) within a class named AutoExp.

The relevant part of the answer is :

//scan->ranges[] are laser readings

You need to use the field ranges to get the laser scan data. For your question, you want to use the field range_max so you just have to do this :

void LaserCallback(const sensor_msgs::LaserScan::ConstPtr& scan)
{
   float x = scan->range_max;
}

You can see here all the fields from sensor_msgs/LaserScan.msg.

edit flag offensive delete link more
0

answered 2019-03-01 08:21:37 -0500

harshal gravatar image

Quick answer:

float x = scan -> range_max;

The callback function receives a 'LaserScan' message as a parameter. In order to access its fields, you need to resolve/access it correctly.

Alternatively, were you to access, say the 'seq', int i = scan -> header.seq

In the answer linked, "scan->ranges[] are laser readings" refers to the data from the message that you would process.

edit flag offensive delete link more

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: 2019-03-01 07:39:01 -0500

Seen: 613 times

Last updated: Mar 01 '19