Ask Your Question
0

Subscriber issue

asked 2013-03-18 23:33:16 -0500

camilla gravatar image

What should I do if I want that the callBack function of a subscriber returns a value. In particular I have a subscriber that receive sensor_msgs/Range and I want the callBack function to return the range value that is in the message but I don't now how to implement it.
Any suggestion?

Thanks in advance

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-03-19 01:33:58 -0500

dornhege gravatar image

Callback cannot return values.

Where would you want to have that value returned to?

edit flag offensive delete link more

Comments

You could take an example from the talker tutorial, to communicate to the sender of the original message.

aimc gravatar image aimc  ( 2013-03-19 01:47:30 -0500 )edit

That's what services are for.

dornhege gravatar image dornhege  ( 2013-03-19 02:28:12 -0500 )edit

I want it returned in the main where I declare the subscriber

camilla gravatar image camilla  ( 2013-03-19 04:56:59 -0500 )edit

You just want to have the message value available in the main? You could write it to a global variable or better use boost::bind for the callback and pass in a reference to the value to write to.

dornhege gravatar image dornhege  ( 2013-03-19 06:00:23 -0500 )edit
1

answered 2013-03-18 23:41:03 -0500

Victor_ocv2 gravatar image

updated 2013-03-19 07:49:01 -0500

If you just want to get the value, declare the callback as member function of a class. Then, you can write the received data into that class, in example (pseudocode):

void Robot::LaserCallback(const sensor_msgs::LaserScan::ConstPtr& msg){

for ( range_data in msg) {
    this->rangedata = msg->ranges
    }
}

In this way from your main you could just call a get method to obtain the latest data available.

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

Stats

Asked: 2013-03-18 23:33:16 -0500

Seen: 167 times

Last updated: Mar 19 '13