mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-26 01:00:36 +08:00
refactor(timesync): swap exp -> expf to save flash
This is the only double-precision exp in the codebase, and occupies a hefty chunk of flash. Relevant history: - https://github.com/PX4/PX4-Autopilot/pull/9365 /39bb65ffd7- Timesync algorithm is initially added with this "sigmoid" function calculated completely in float - but _filter_alpha / _filter_beta are double, presumably to be compatible with adjusting _time_offset in add_sample which is a double (which it needs to be to represent large offsets coming from int64_t) - https://github.com/PX4/PX4-Autopilot/pull/9809 /cf74166801- to silence warnings, the expf is swapped for an exp and the entire sigmoid calculation is now in double I would say the better fix to silence the promotion warning is to keep the sigmoid function in float (precision not needed) and cast to double right after, to not accidentally change anything depending on double.
This commit is contained in:
1 parent
14be323bb2
commit
7b19bbf75f
1 file changed
+2
-2
@@ -76,8 +76,8 @@ void Timesync::update(const uint64_t now_us, const int64_t remote_timestamp_ns,
|
||||
// Filter gain scheduling
|
||||
if (!sync_converged()) {
|
||||
// Interpolate with a sigmoid function
|
||||
double progress = (double)_sequence / (double)CONVERGENCE_WINDOW;
|
||||
double p = 1.0 - exp(0.5 * (1.0 - 1.0 / (1.0 - progress)));
|
||||
const float progress = (float) _sequence / (float) CONVERGENCE_WINDOW;
|
||||
double p = (double)(1.f - expf(0.5f * (1.f - 1.f / (1.f - progress))));
|
||||
_filter_alpha = p * ALPHA_GAIN_FINAL + (1.0 - p) * ALPHA_GAIN_INITIAL;
|
||||
_filter_beta = p * BETA_GAIN_FINAL + (1.0 - p) * BETA_GAIN_INITIAL;
|
||||
|
||||
|
||||
Reference in new issue
Block a user