From 0763285b09f2d6712f0bb9e8d6a58bf5da2e917c Mon Sep 17 00:00:00 2001 From: Nico Aleman Date: Sat, 1 Nov 2025 23:45:05 -0700 Subject: [PATCH 1/4] Workflow: Update CI clang-tools reference --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76d9be5..d47a640 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - uses: cachix/install-nix-action@v25 - uses: rrbutani/use-nix-shell-action@v1 with: - flakes: nixpkgs#clang-tools_18, nixpkgs#lefthook + flakes: nixpkgs#llvmPackages_18.clang-tools, nixpkgs#lefthook - name: Run clang-format id: clang-format From dcd92bd3003da24775ffae0a0289045f09e58a10 Mon Sep 17 00:00:00 2001 From: Nico Aleman Date: Fri, 10 Oct 2025 12:57:16 -0700 Subject: [PATCH 2/4] ATR: Refactor implementation No behavior changes, just re-structuring in preparation for further updates. --- src/atr.c | 86 +++++++++++++++++++++---------------------------------- 1 file changed, 33 insertions(+), 53 deletions(-) diff --git a/src/atr.c b/src/atr.c index 960c93f..d7e2083 100644 --- a/src/atr.c +++ b/src/atr.c @@ -133,60 +133,40 @@ void atr_update(ATR *atr, const MotorData *motor, const RefloatConfig *config) { // We want to react quickly to changes, but we don't want to overreact to glitches in // acceleration data or trigger oscillations... float atr_step_size = 0; - const float TT_BOOST_MARGIN = 2; - if (forward) { - if (atr->setpoint < 0) { - // downhill - if (atr->setpoint < atr->target) { - // to avoid oscillations we go down slower than we go up - atr_step_size = atr->off_step_size; - if (atr->target > 0 && atr->target - atr->setpoint > TT_BOOST_MARGIN && - motor->abs_erpm > 2000) { - // boost the speed if tilt target has reversed (and if there's a significant - // margin) - atr_step_size = atr->off_step_size * config->atr_transition_boost; - } - } else { - // ATR is increasing - atr_step_size = atr->on_step_size * response_boost; - } - } else { - // uphill or other heavy resistance (grass, mud, etc) - if (atr->target > -3 && atr->setpoint > atr->target) { - // ATR winding down (current ATR is bigger than the target) - // normal wind down case: to avoid oscillations we go down slower than we go up - atr_step_size = atr->off_step_size; - } else { - // standard case of increasing ATR - atr_step_size = atr->on_step_size * response_boost; - } - } + + float atr_tb_step_size = atr->off_step_size * config->atr_transition_boost; + float atr_on_step_size = atr->on_step_size * response_boost; + + const float TT_BOOST_UPHILL_MARGIN = 2; + const float TT_BOOST_DOWNHILL_THRESHOLD = 3; + + // Winding Down: Setpoint is moving toward 0 + bool is_winding_down = (atr->setpoint < 0 && atr->setpoint < atr->target) || + (atr->setpoint > 0 && atr->setpoint > atr->target); + + bool should_transition_boost; + if (atr->target * atr->setpoint >= 0) { + // If Target and Setpoint are of same sign or 0, we are not transitioning + should_transition_boost = false; + } else if (forward ? (atr->setpoint < 0 && atr->target > 0) + : (atr->setpoint > 0 && atr->target < 0)) { + // Transitioning Downhill to Uphill: check margin between target and setpoint, + // with a minimum ERPM threshold + should_transition_boost = (fabsf(atr->target - atr->setpoint) > TT_BOOST_UPHILL_MARGIN) && + (motor->abs_erpm > 2000); + } else { + // Transitioning Uphill to Downhill: check target magnitude (stricter condition); + // Instead of transition boost, use on_step_size (typically faster than off_step_size) + should_transition_boost = false; + is_winding_down = fabsf(atr->target) < TT_BOOST_DOWNHILL_THRESHOLD; + } + + if (is_winding_down) { + // ATR is decreasing (boost if transitioning to strong Uphill ATR) + atr_step_size = should_transition_boost ? atr_tb_step_size : atr->off_step_size; } else { - if (atr->setpoint > 0) { - // downhill - if (atr->setpoint > atr->target) { - // to avoid oscillations we go down slower than we go up - atr_step_size = atr->off_step_size; - if (atr->target < 0 && atr->setpoint - atr->target > TT_BOOST_MARGIN && - motor->abs_erpm > 2000) { - // boost the speed if tilt target has reversed (and if there's a significant - // margin) - atr_step_size = atr->off_step_size * config->atr_transition_boost; - } - } else { - // ATR is increasing - atr_step_size = atr->on_step_size * response_boost; - } - } else { - // uphill or other heavy resistance (grass, mud, etc) - if (atr->target < 3 && atr->setpoint < atr->target) { - // normal wind down case: to avoid oscillations we go down slower than we go up - atr_step_size = atr->off_step_size; - } else { - // standard case of increasing torquetilt - atr_step_size = atr->on_step_size * response_boost; - } - } + // ATR is increasing (or transitioning quickly from Uphill to Downhill ATR) + atr_step_size = atr_on_step_size; } if (motor->abs_erpm < 500) { From 0cbc656eae1a4889b9a0fa483d33cf72b78950b2 Mon Sep 17 00:00:00 2001 From: Nico Aleman Date: Sun, 2 Nov 2025 01:23:38 -0700 Subject: [PATCH 3/4] ATR: Rework Tilt Speed Conditions Unify the tilt speed selection between Uphill and Downhill. Rather than Down -> Up boosting with Transition Boost, and Up -> Down "boosting" with On_Step_Size, both states use the faster of the two tilt speeds. The ERPM Threshold unique to Down -> Up was also deemed unnecessary and removed. Fix: Rework ATR to more effectively boost tilt speeds in fast transitions --- src/atr.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/atr.c b/src/atr.c index d7e2083..1a97405 100644 --- a/src/atr.c +++ b/src/atr.c @@ -137,35 +137,34 @@ void atr_update(ATR *atr, const MotorData *motor, const RefloatConfig *config) { float atr_tb_step_size = atr->off_step_size * config->atr_transition_boost; float atr_on_step_size = atr->on_step_size * response_boost; + // When Transition Boost condition is met, use the highest allowed step size + float atr_transition_step_size = fmaxf(atr_tb_step_size, atr_on_step_size); + const float TT_BOOST_UPHILL_MARGIN = 2; const float TT_BOOST_DOWNHILL_THRESHOLD = 3; - // Winding Down: Setpoint is moving toward 0 - bool is_winding_down = (atr->setpoint < 0 && atr->setpoint < atr->target) || - (atr->setpoint > 0 && atr->setpoint > atr->target); - bool should_transition_boost; if (atr->target * atr->setpoint >= 0) { // If Target and Setpoint are of same sign or 0, we are not transitioning should_transition_boost = false; } else if (forward ? (atr->setpoint < 0 && atr->target > 0) : (atr->setpoint > 0 && atr->target < 0)) { - // Transitioning Downhill to Uphill: check margin between target and setpoint, - // with a minimum ERPM threshold - should_transition_boost = (fabsf(atr->target - atr->setpoint) > TT_BOOST_UPHILL_MARGIN) && - (motor->abs_erpm > 2000); + // Transitioning Downhill to Uphill: check margin between target and setpoint + should_transition_boost = fabsf(atr->target - atr->setpoint) >= TT_BOOST_UPHILL_MARGIN; } else { - // Transitioning Uphill to Downhill: check target magnitude (stricter condition); - // Instead of transition boost, use on_step_size (typically faster than off_step_size) - should_transition_boost = false; - is_winding_down = fabsf(atr->target) < TT_BOOST_DOWNHILL_THRESHOLD; + // Transitioning Uphill to Downhill: check target magnitude (stricter condition) + should_transition_boost = fabsf(atr->target) >= TT_BOOST_DOWNHILL_THRESHOLD; } + // Winding Down: Setpoint is moving toward 0 + bool is_winding_down = (atr->setpoint < 0 && atr->setpoint < atr->target) || + (atr->setpoint > 0 && atr->setpoint > atr->target); + if (is_winding_down) { - // ATR is decreasing (boost if transitioning to strong Uphill ATR) - atr_step_size = should_transition_boost ? atr_tb_step_size : atr->off_step_size; + // ATR is decreasing (boost if transitioning to strong ATR of opposite sign) + atr_step_size = should_transition_boost ? atr_transition_step_size : atr->off_step_size; } else { - // ATR is increasing (or transitioning quickly from Uphill to Downhill ATR) + // ATR is increasing atr_step_size = atr_on_step_size; } From 3294e77e431d44202ce2a8c0c225590f09f72032 Mon Sep 17 00:00:00 2001 From: Nico Aleman Date: Sun, 2 Nov 2025 01:24:10 -0700 Subject: [PATCH 4/4] ATR: Account for ATR Thresholds in Boost margin Fix: High ATR Thresholds no longer make Transition Boost harder to trigger --- src/atr.c | 15 ++++++++++----- src/atr.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/atr.c b/src/atr.c index 1a97405..e6e4b4a 100644 --- a/src/atr.c +++ b/src/atr.c @@ -26,6 +26,8 @@ void atr_init(ATR *atr) { atr->on_step_size = 0.0f; atr->off_step_size = 0.0f; atr->speed_boost_mult = 0.0f; + atr->tt_boost_uphill_margin = 0.0f; + atr->tt_boost_downhill_threshold = 0.0f; atr_reset(atr); } @@ -48,6 +50,12 @@ void atr_configure(ATR *atr, const RefloatConfig *config) { // most +6000 for 100% speed boost atr->speed_boost_mult = 1.0f / ((fabsf(config->atr_speed_boost) - 0.4f) * 5000 + 3000.0f); } + + // If ATR Thresholds are in place, they should be negated from the Transition Boost margin + // for the effective condition (change in accel_diff needed) to be the same + atr->tt_boost_uphill_margin = + fmaxf(0, 2 - config->atr_threshold_down - config->atr_threshold_up); + atr->tt_boost_downhill_threshold = fmaxf(0, 3 - config->atr_threshold_down); } void atr_update(ATR *atr, const MotorData *motor, const RefloatConfig *config) { @@ -140,9 +148,6 @@ void atr_update(ATR *atr, const MotorData *motor, const RefloatConfig *config) { // When Transition Boost condition is met, use the highest allowed step size float atr_transition_step_size = fmaxf(atr_tb_step_size, atr_on_step_size); - const float TT_BOOST_UPHILL_MARGIN = 2; - const float TT_BOOST_DOWNHILL_THRESHOLD = 3; - bool should_transition_boost; if (atr->target * atr->setpoint >= 0) { // If Target and Setpoint are of same sign or 0, we are not transitioning @@ -150,10 +155,10 @@ void atr_update(ATR *atr, const MotorData *motor, const RefloatConfig *config) { } else if (forward ? (atr->setpoint < 0 && atr->target > 0) : (atr->setpoint > 0 && atr->target < 0)) { // Transitioning Downhill to Uphill: check margin between target and setpoint - should_transition_boost = fabsf(atr->target - atr->setpoint) >= TT_BOOST_UPHILL_MARGIN; + should_transition_boost = fabsf(atr->target - atr->setpoint) >= atr->tt_boost_uphill_margin; } else { // Transitioning Uphill to Downhill: check target magnitude (stricter condition) - should_transition_boost = fabsf(atr->target) >= TT_BOOST_DOWNHILL_THRESHOLD; + should_transition_boost = fabsf(atr->target) >= atr->tt_boost_downhill_threshold; } // Winding Down: Setpoint is moving toward 0 diff --git a/src/atr.h b/src/atr.h index caff97e..13f6928 100644 --- a/src/atr.h +++ b/src/atr.h @@ -25,6 +25,8 @@ typedef struct { float on_step_size; float off_step_size; float speed_boost_mult; + float tt_boost_uphill_margin; + float tt_boost_downhill_threshold; float accel_diff; float speed_boost;