ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Calling other callback from callback class

asked 2013-08-15 23:42:12 -0500

hvn gravatar image

Hi,

I'm using the callback class like class X{ callback(){} X(){ros::publisher sub1 = n.subscribe(&callback); callback();} run()};

but can you do from this callback method: callback(){ ros::publisher sub2 = n.subscribe(&callback2); callback2():}. I couldn't find about this.

I hope the question is clear. Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-08-15 23:59:50 -0500

dornhege gravatar image

Your code is a bit fuzzy and won't compile, but in principle yes, you can do all of that.

A callback is just a method that you can call manually if you need to. You can also create subscriptions whenever you want.

There is only one flaw in your code: The subscribers/publishers are declared locally, so once the function is done, they will be destroyed.

edit flag offensive delete link more

Comments

You say the code won't compile. Assuming you don't mean my example code (which indeed won't compile), can you please explain why ?

hvn gravatar image hvn  ( 2013-08-16 00:12:25 -0500 )edit

For example, you're assigning a publisher to the result of a subscribe call...

dornhege gravatar image dornhege  ( 2013-08-16 03:46:17 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-08-15 23:42:12 -0500

Seen: 238 times

Last updated: Aug 15 '13