Async hardware reads in system interface (ros2_controls)
I'm porting my hardware interfaces to the new ros2_controls hardware system interface. We are to implement the read() and write() method overrides. However, we often don't have a low latency connection to our joints so how should we handle reads without blocking the main controller manager executor thread? Here are some possibilities I am thinking about:
The bus is a low-latency (bot not insignificant) serial connection with about 2ms round trip.
- Simple. Block read in the read() method.
- Initiate async query command on the bus immediately after the command write in the write() method. Expect the data may be available during the next read() call.
- Create a new executor thread (or pthread) and implement our own control loop for both state and commands. The overridden read() and write() methods are then only updating class variables.
What is recommended here? I don't like 1. Two depends on internal implementation and I cant control the timing between read()/write() even though my hardware timing is pretty well known. Seems like 3 is the best way, and I probably should implement a realtime barrier as well.
Thanks ahead for your time and consideration.
Colin