ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How can i get infomation of the subscription of a node

asked 2016-02-05 08:35:02 -0500

updated 2016-02-07 05:37:26 -0500

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?

edit retag flag offensive close merge delete


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)

F.Brosseau gravatar image F.Brosseau  ( 2016-02-08 03:02:54 -0500 )edit

No, the only thing that i can do is declare nearest as a global variable..

egr gravatar image egr  ( 2016-02-12 05:21:23 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2016-02-13 11:08:07 -0500

I declare nearest as a global variable and after that i can use this variable in the main function.

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


Asked: 2016-02-05 08:35:02 -0500

Seen: 182 times

Last updated: Feb 13 '16