-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I am writing some tight control loops (modulating the speed/current based on the position of the motor) and while I use sleep and its okay it really should be synchronized to the control loop or pid loop otherwise there is a variable latency between the timing of the position read, the lisp control update and the actual application of that command to the motor. The way it would probably be done is using the events system. It would even be nice if lisp code could send custom events but thats a tangent.
Also I am using this pattern:
(loopwhile t (progn
(sleep (- 0.01 (secs-since last-ctrl-loop)))
(setq last-ctrl-loop (systime))
To make sure the loop is actually running at 100hz, since sleep 0.01 would actually run slightly less due to the loop itself taking some time. I think this pattern should be formalized in a single function since its usually what a user actually wants when writing a sleep loop. Something like
(loopevery 0.01 (body))