From 9dbee3e78bb65db95d69527ddbe113c0a348b2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= Date: Wed, 25 Dec 2024 20:04:36 +0100 Subject: [PATCH] Negative Variable Tiltback configured by negative rate Fix: Configure negative Variable Tiltback via negative rate, not maximum > This will cause negative Variable Tiltback configured through the maximum to disappear. In such case users need to configure it again. --- src/conf/settings.xml | 4 ++-- src/main.c | 25 +++++++------------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/conf/settings.xml b/src/conf/settings.xml index dabeff7..330dd13 100644 --- a/src/conf/settings.xml +++ b/src/conf/settings.xml @@ -809,7 +809,7 @@ p, li { white-space: pre-wrap; } 1 0 5 - 0 + -5 0 0.05 0.1 @@ -831,7 +831,7 @@ p, li { white-space: pre-wrap; } 1 0 20 - -20 + 0 0 0.5 0 diff --git a/src/main.c b/src/main.c index 11c0c26..a24c996 100644 --- a/src/main.c +++ b/src/main.c @@ -265,14 +265,9 @@ static void reconfigure(data *d) { d->startup_step_size = d->float_conf.startup_speed / d->float_conf.hertz; d->noseangling_step_size = d->float_conf.noseangling_speed / d->float_conf.hertz; d->startup_pitch_trickmargin = d->float_conf.startup_dirtylandings_enabled ? 10 : 0; - d->tiltback_variable = d->float_conf.tiltback_variable / 1000; - if (d->tiltback_variable > 0) { - d->tiltback_variable_max_erpm = - fabsf(d->float_conf.tiltback_variable_max / d->tiltback_variable); - } else { - d->tiltback_variable_max_erpm = 100000; - } + d->tiltback_variable_max_erpm = + fabsf(d->float_conf.tiltback_variable_max / d->tiltback_variable); motor_data_configure(&d->motor, d->float_conf.atr_filter / d->float_conf.hertz); balance_filter_configure(&d->balance_filter, &d->float_conf); @@ -853,17 +848,11 @@ static void calculate_setpoint_target(data *d) { } static void apply_noseangling(data *d) { - // Nose angle adjustment, add variable then constant tiltback - float noseangling_target = 0; - - // Variable Tiltback looks at ERPM from the reference point of the set minimum ERPM - float variable_erpm = fmaxf(0, d->motor.abs_erpm - d->float_conf.tiltback_variable_erpm); - if (variable_erpm > d->tiltback_variable_max_erpm) { - noseangling_target = d->float_conf.tiltback_variable_max * d->motor.erpm_sign; - } else { - noseangling_target = d->tiltback_variable * variable_erpm * d->motor.erpm_sign * - sign(d->float_conf.tiltback_variable_max); - } + // Variable Tiltback: looks at ERPM from the reference point of the set minimum ERPM + float variable_erpm = clampf( + d->motor.abs_erpm - d->float_conf.tiltback_variable_erpm, 0, d->tiltback_variable_max_erpm + ); + float noseangling_target = d->tiltback_variable * variable_erpm * d->motor.erpm_sign; if (d->motor.abs_erpm > d->float_conf.tiltback_constant_erpm) { noseangling_target += d->float_conf.tiltback_constant * d->motor.erpm_sign;