Open vincentl98 opened 4 years ago
Agree-- I originally realized this only after publishing the API, and implemented the (admittedly hacky) field_access
feature flag to be able to mutate the period for each sample update without a breaking releases.
It would be nice to satisfy both fixed and dynamic sample periods, but without separate implementations I fear it might have a performance impact (e.g., passing in a Option<N>
and doing the mutation check internally). So unless a more elegant solution can be determined, the best option is probably just to do like you suggest and force the caller to manage period.
Eventually, it would be nice to add implementations for Unscented, Extended, etc. Fortunately those should also be compatible with the updated Ahrs
trait.
I am also interested in this feature. Could you have a second method update_dynamic(self, gyroscope, accelerometer, magnetometer, dt)
that internally mutates the sample rate and then calls update
. I know that this might not be the desired api, so I am happy to fork this and edit (just for my own personal use, I won't publish on crates.io).
I can think of three sensible approaches for handling a dynamic time delta.
dt
to the Ahrs
trait interface seems like the most graceful solution to me. It is easy enough for users to keep track of their own fixed time delta.dt
parameter are also a reasonably graceful solution- update_dynamic()
and update_imu_dynamic()
.dt(dt)
setter seems more graceful than the field_access
feature. The setter could even be set up for method chaining, although this is probably not conventional.
attitude = ahrs.dt(dt).update(gyroscope, accelerometer, magnetometer);
Both Madgwick and Mahony filter implementations are using a fixed
sample_period
. However in non real-time systems, it is more accurate to directly pass the time delta between two measurements:would become in that case: