DCM Synchronization methods

See also

Overview | API | Tutorial


“onPreProcess” and “onPostProcess”

Warning

These callbacks are dangerous. Use them with care and only if you are comfortable with real-time, multithread, and precise timing.

The DCM provides a simple way to synchronize to its real time thread.

You can define a callback function called by the DCM just after its sleep (PreProcess), or just before going back to sleep (PostProcess).

onPreProcess is useful because it’s called just before the computation of orders sent to the chestboard (USB). Sending commands at this level means that you have the shortest delay to your command.

onPostProcess is called just after all value are updated in the ALMemory, and so at this time you have the newest values of all sensors.

These two callbacks can’t send/receive information, you still need to use the DCM API to send commands, and read the ALMemory to get sensors values.

Real-time and timing consideration:

Being called by the DCM thread means that your function is now real time. To keep the real time efficient and to avoid delay in the DCM cycle, you must:

  • Avoid all kind of memory allocation
  • Avoid all kind of printf, cout,... and file access
  • Of course avoid all system calls that yield and/or can possibly use a lot of time
  • Return from the call back after a short time, a few ms max
  • Your function must have a mostly constant timing every cycle. If your call back last for 1ms, then 10ms, then 1ms... this will give bad result on joint control loop

Note

You can find an example of callback in the fastgetsetexample folder in the sdk.