Call a callback without a timer
I'm trying to find a solution to be able to create and call a callback from elsewhere inside my node spinned when I want in ROS2 (currently the alternative I found is to create a timer (see below), and then destroy this timer inside its callback but I'm sure there is a better solution)
def MyNode(Node):
def __init__(self):
[...]
self.execute_once_when_I_want = self.create_timer(1, self.execute_once_callback)
[...]
def self.execute_once_when_I_want(self):
if (my_condition is True):
self.execute_once_when_I_want.destroy()
do_some_others_stuff()