How can I use the data from the LaserScan.msg inside the callback function?
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/60239/how-to-extract-and-use-laser-data-from-scan-topic-in-ros-using-c/ )answer suggested something called AutoExp::processLaserScan, but how do I know which heades to include?
Thank you.
Asked by Sanat on 2019-03-01 08:39:01 UTC
Answers
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.
Asked by Delb on 2019-03-01 09:17:21 UTC
Comments
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.
Asked by harshal on 2019-03-01 09:21:37 UTC
Comments