Proper use of ros_control's RealtimeBuffer
I am new to real-time programming, and I am trying to learn how to properly use realtime_tools::RealtimeBuffer
in my ros_control controller by looking at source code from related packages. After looking at the source code of RealtimeBuffer
, effort_controllers::JointPositionController
, and forward_command_controller::ForwardJointGroupCommandController
, I am still confused about three things.
First, JointPositionController
uses the buffer to share command data between the RT and non-RT threads, but command_struct_
, the member variable used to set the buffer, is also accessed by both threads. Is it safe to access command_struct_
in this way? If it is safe, why is this the case?
Second, in ForwardJointGroupCommandController
, why is RealtimeBuffer
not used at all? My controller has several joints and I was thinking on using RealtimeBuffer
to protect a vector. In order to pre-allocate the buffer internally, I was thinking on passing a vector with dummy values to RealtimeBuffer::initRT()
in the init()
method of the controller (I don't know the size of the vector until this point). Then call initRT()
again in starting()
with appropriate values.
Third, why doesn't RealtimeBuffer::initRT()
check the lock of the mutex? Under the context of the JointPositionController
, I can imagine messages published to the command topic even before the controller is started. Would this be safe?
Source code: RealtimeBuffer, JointPositionController, ForwardJointGroupCommandController.