nasa-jpl / fastcat

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

Better simulation time support #117

Closed kwehage closed 1 year ago

kwehage commented 1 year ago

Follow-on to https://github.com/nasa-jpl/fastcat/pull/89

Fixes use of simulation time for computing actuator behavior durations, which were still using the jsd_time_get_time_sec and jsd_get_mono_time_sec internally.

Adds new DeviceState field monotonic_time. If simulation mode is used, time and monotonic_time are both set to the provided simulation time. If not in a simulation, time uses Linux time (seconds since the epoch), and monotonic_time uses monotonic clock, (seconds since computer was switched on). Monotonic time is guaranteed to be monotonically increasing and therefore may be more reliable for computing durations, especially when computing short durations.

Allow optionally passing in simulation time to device's ConfigFromYAML method to allow optionally passing in a startup time to a device.

Update logic to test for simulation time to:

if(external_time < 0) {
  // we are in online mode
} else {
  // we are in simulation
}

which allows passing in a zero value for initial start up time in simulation mode.

kwehage commented 1 year ago

Closing in favor of https://github.com/nasa-jpl/fastcat/pull/118