ROS2: callback queue priorities

asked 2019-08-19 11:56:43 -0500

heumchri gravatar image

I'm trying to implement a simple trajectory following robot in rclpy that receives

  • odometry messages at very high frequency
  • trajectory messages at a lower frequency

The robot should follow the most recent trajectory during the odometry callbacks. The trajectory callbacks should be executed as soon as a new trajectory message arrives, odometry callbacks should be executed only if there is no new trajectory message. What is the preferred way to get this to work?

What I've tried so far:

  1. Use QoS profile to limit callback queue size to 1

    However, due to the odometry messages coming in at such a fast rate, there is always a new message in the queue right after executing the last. Often, the callback for the new odometry message is executed even though a new trajectory message has arrived before.

  2. Use Multithreaded executors I've split the subscribers for odometry and trajectory messages into 2 nodes, because if I've understood correctly, callbacks from the same node cannot me multithreaded. But the problem still remains. As soon as the odometry callback is assigned to a thread, there is already a new odometry message available which can be assigned next even though a trajectory message has been received before.

How do I tackle this problem?

edit retag flag offensive close merge delete