How can i get infomation of the subscription of a node
I have to write code to get the simulation of a robot that explores certains worlds with the stage simulator. The point is that i want to get information of the laser scanner and i don't know how to do it...
I have the subscription...
// Create a subscriber object
ros::Subscriber sub = nh.subscribe("/base_scan", 1000, processScanCallback);
where processScanCallback
is:
void processScanCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
int n_ranges = msg->ranges.size();
double nearest = *(std::min_element(msg->ranges.begin(),msg->ranges.end()));
ROS_INFO_STREAM("I've a total of " << n_ranges << " measurements to process! Are you ready? Nearest=" nearest );
}
and i call ros::SpinOnce();
inside a while-loop (where the robot is constantly doing measures and moving randomly), but those measurements are inside the function processScanCallback
in the varible nearest
. So, i have messages in the rosout node every time that the robot do a measure, but i can't do something with that value because is not returned...
How can i receive the value nearest
from the processScanCallback
function?
Is it possible to change the processScanCallback signature ? (void processScanCallback(const sensor_msgs::LaserScan::ConstPtr& msg, double& nearest) and you declare the variable "nearest" in your main)
No, the only thing that i can do is declare
nearest
as a global variable..