nasa-jpl / fastcat

C++ EtherCAT Device Command & Control Library
Other
47 stars 11 forks source link

Round up for actuator loop period #77

Closed davidinkyu-kim closed 1 year ago

davidinkyu-kim commented 1 year ago

Elmo actuator was not working correctly(position tracking error when profiled traj is commanded) with loop rate of power of 2.

While converting target_loop_rate into egd configuration which is INT8 type, round up should be done.

Tested with 128hz, 256hz and working as expected without error.

alex-brinkman commented 1 year ago

It's unclear to me why this would solve anything. Checkout this compiler explorer example to see the difference between round and not-rounded results: https://godbolt.org/z/cdf39P87n

Mind helping me understand why this works?

alex-brinkman commented 1 year ago

This does solve a bug for rates above 2000hz as 0.0005 sec in msec would round down to zero in the current implementation

davidinkyu-kim commented 1 year ago

loop_rate is converted into jsd_egd_config_t/loop_period_ms which is int8_t type: https://github.com/nasa-jpl/jsd/blob/master/src/jsd_egd_types.h#L249

Without round up, for example of loop rate 128hz, loop_period_ms is set to 7ms. And fcat runs at 7.8126ms period which is slower than the Elmo control rate. When Elmo's host control loop(0x60C2 ) is set faster than actual, Elmo cause a position tracking error: Reference to the figure: https://fornat1.jpl.nasa.gov/sts/sta/clark/bringup/-/issues/16#note_25908

With the roundup, host control loop rate is set at '8ms' in case of fcat@128hz, which is slower than actual control loop. Elmo works okay in that setup.

And for 2000hz case, anything faster than 1000hz the loop_period_ms will be set to 1: https://github.com/nasa-jpl/jsd/blob/master/src/jsd_egd.c#L804

alex-brinkman commented 1 year ago

ahhh very nuianced interaction! Can you put in a comment describing the bug and why it needs to round up before you merge and close out this issue? You have my full approval, great sleuthing!