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

How to add some condition for two callbacks and based on that, execute code?

asked 2020-12-31 01:06:00 -0600

Navid A Mulla gravatar image

I mean I get two callbacks in my subscribed node (callback1 and callback 2) ... I want to print "Hello" only when both callbacks are triggered.... for example if callback 1 is received data but callback2 dint received any data then "Hello" should not print on terminal log

is it possible?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-12-31 14:55:40 -0600

SmallJoeMan gravatar image

Have you seen message filters? http://wiki.ros.org/message_filters

You can attach a callback to run when two messages are received.

Alternatively you can store a state variable that is set by one callback and checked and cleared by a second (with an optional timeout).

edit flag offensive delete link more

Comments

there are tho only two ways, with the local var you have to proper protet the variable with an mutex, otherwise magic can happen

duck-development gravatar image duck-development  ( 2021-01-01 09:41:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-12-30 23:44:09 -0600

Seen: 193 times

Last updated: Dec 31 '20