Closed iamrobusto closed 1 year ago
I found one way : simply have the subscriber callbacks set a class var, say self.command, with the appropriate command. Then, in the main loop call the handy send() coroutine with self.command if it is not empty. Set self.command to blank after a command is sent.
How does one implement rospy subscriber callbacks with asyncio?
I've tried both
create_task
andrun_coroutine_threadsafe
suggested here https://answers.ros.org/question/362598/asyncawait-in-subscriber-callback/ without success.run_coroutine_threadsafe
looks like the solution but I can't make it work.. Have you had experience with your library of inserting a coroutine into the main loop from another thread?Example:
ROS works on a publisher-subscriber topic model. In this case , when a message (Empty) is published (by another program running simultaneously) to the topic 'takeoff', takeoff-callback() is called. This cannot be a coroutine, so cannot be async; hence, the use of run_coroutine_threadsafe. This call never returns and myTakeOff() is not called. Any ideas what is wrong? Note: Execution does pass to the callback, "taking off" is printed. myTakeOff() runs successfully when called directly from the the main loop with await.