|
26 | 26 | #include "timeout.h" // To reset the timeout |
27 | 27 | #include "commands.h" |
28 | 28 | #include "imu/imu.h" |
29 | | -#include "imu/ahrs.h" |
30 | 29 | #include "utils.h" |
31 | 30 | #include "datatypes.h" |
32 | 31 | #include "comm_can.h" |
@@ -117,18 +116,6 @@ static systime_t brake_timeout; |
117 | 116 | static float switch_warn_buzz_erpm; |
118 | 117 | static bool is_dual_switch; |
119 | 118 |
|
120 | | -// Feature: bump compensation / IMU correction |
121 | | -extern bool balance_bump_correction; |
122 | | -extern float balance_bump_adjuster; |
123 | | -extern float bump_correction_intensity; |
124 | | -static float pitch_change_aggregate; |
125 | | -static int pitch_steady_count; |
126 | | -static int pitch_change_count; |
127 | | -static int bump_count; |
128 | | -static systime_t correction_sustain; |
129 | | -static float correction_sustain_duration; |
130 | | -static bool balance_bump_beep; |
131 | | - |
132 | 119 | // Debug values |
133 | 120 | static int debug_render_1, debug_render_2; |
134 | 121 | static int debug_sample_field, debug_sample_count, debug_sample_index; |
@@ -200,24 +187,6 @@ void app_balance_configure(balance_config *conf, imu_config *conf2) { |
200 | 187 | if (angular_rate_kp >= 1) |
201 | 188 | angular_rate_kp = 0; |
202 | 189 |
|
203 | | - // Bump compensation |
204 | | - bump_correction_intensity = 1.5; |
205 | | - correction_sustain_duration = 500; |
206 | | - |
207 | | - if (balance_conf.yaw_current_clamp == 0.01) { |
208 | | - bump_correction_intensity = 0; |
209 | | - correction_sustain_duration = 0; |
210 | | - } |
211 | | - else { |
212 | | - if (balance_conf.yaw_current_clamp > 5) |
213 | | - bump_correction_intensity = 1.5; |
214 | | - else |
215 | | - bump_correction_intensity = balance_conf.yaw_current_clamp; |
216 | | - |
217 | | - correction_sustain_duration = fmaxf(50, balance_conf.roll_steer_erpm_kp); |
218 | | - balance_bump_beep = (balance_conf.roll_steer_kp == 0); |
219 | | - } |
220 | | - |
221 | 190 | // Variable nose angle adjustment / tiltback (setting is per 1000erpm, convert to per erpm) |
222 | 191 | tiltback_variable = balance_conf.tiltback_variable / 1000; |
223 | 192 | if (tiltback_variable > 0) { |
@@ -328,10 +297,6 @@ static void reset_vars(void){ |
328 | 297 | last_time = 0; |
329 | 298 | diff_time = 0; |
330 | 299 | brake_timeout = 0; |
331 | | - |
332 | | - // Bump compensation |
333 | | - bump_count = 0; |
334 | | - balance_bump_correction = false; |
335 | 300 | } |
336 | 301 |
|
337 | 302 | static float get_setpoint_adjustment_step_size(void){ |
@@ -614,101 +579,6 @@ static THD_FUNCTION(balance_thread, arg) { |
614 | 579 | abs_roll_angle_sin = sinf(DEG2RAD_f(abs_roll_angle)); |
615 | 580 | imu_get_gyro(gyro); |
616 | 581 |
|
617 | | - float pitch_change = pitch_angle - last_pitch_angle; |
618 | | - float pitch_change_abs = fabsf(pitch_change); |
619 | | - float correction_sustain_scaling = 1.0; |
620 | | - if (pitch_change_abs > 0.04) { |
621 | | - if (pitch_change_aggregate == 0) { |
622 | | - pitch_change_aggregate = pitch_change; |
623 | | - pitch_change_count = 1; |
624 | | - } |
625 | | - else if (SIGN(pitch_change_aggregate) == SIGN(pitch_change)) { |
626 | | - pitch_change_count++; |
627 | | - pitch_change_aggregate += pitch_change; |
628 | | - } |
629 | | - else { |
630 | | - if (pitch_change_count > 4) { |
631 | | - if (pitch_change_aggregate > 1.0) { |
632 | | - correction_sustain_scaling = 1.3; |
633 | | - } |
634 | | - else if (pitch_change_aggregate < 0.4) { |
635 | | - correction_sustain_scaling = 0.7; |
636 | | - } |
637 | | - // change has reversed sign, it's considered a bump if the change was severe enough |
638 | | - if ((fabsf(pitch_change_aggregate) > 0.2) && (pitch_change_count < 20)) { |
639 | | - if (fabsf(pitch_change_aggregate) > 0.8) { |
640 | | - // harsh bumps: |
641 | | - if (ST2MS(current_time - correction_sustain) < correction_sustain_duration) { |
642 | | - // harsh bumps count double if we've already been correcting |
643 | | - bump_count += 2; |
644 | | - } |
645 | | - else { |
646 | | - // first harsh bump (e.g. bonk) gets discounted |
647 | | - bump_count += 1; |
648 | | - } |
649 | | - } |
650 | | - else { |
651 | | - // moderate bumps: |
652 | | - bump_count++; |
653 | | - } |
654 | | - } |
655 | | - else if ((fabsf(pitch_change_aggregate) > 0.8) && (pitch_change_count < 30)) { |
656 | | - // bigger but slower bump (may not be rider action?) |
657 | | - bump_count += 1; |
658 | | - } |
659 | | - } |
660 | | - pitch_change_aggregate = pitch_change; |
661 | | - pitch_change_count = 1; |
662 | | - } |
663 | | - pitch_steady_count = 0; |
664 | | - } |
665 | | - else { |
666 | | - pitch_steady_count++; |
667 | | - if (pitch_steady_count > 15) { |
668 | | - pitch_change_count = 0; |
669 | | - pitch_change_aggregate = 0; |
670 | | - if (pitch_steady_count > 30) { |
671 | | - bump_count = 0; |
672 | | - pitch_steady_count = 30; |
673 | | - } |
674 | | - else { |
675 | | - if (bump_count > 1) { |
676 | | - bump_count = bump_count >> 1; // Divide by 2 |
677 | | - } |
678 | | - } |
679 | | - } |
680 | | - } |
681 | | - |
682 | | - // pitch error is in radians, not degrees! |
683 | | - float pitch_error = imu_ref_get_pitch() - imu_get_pitch(); |
684 | | - if (bump_count > 1) { |
685 | | - balance_bump_correction = true; |
686 | | - float boost = 1 + 0.1 * fminf(5, bump_count); |
687 | | - balance_bump_adjuster = pitch_error * bump_correction_intensity * boost; |
688 | | - if (balance_bump_beep) |
689 | | - beep_alert(1, false); |
690 | | - } |
691 | | - else { |
692 | | - if (balance_bump_correction && (bump_count > 0)) { |
693 | | - // keep correcting but by half the amount |
694 | | - balance_bump_adjuster = pitch_error * bump_correction_intensity; |
695 | | - correction_sustain = current_time; |
696 | | - } |
697 | | - else { |
698 | | - if (ST2MS(current_time - correction_sustain) < correction_sustain_duration * correction_sustain_scaling) { |
699 | | - balance_bump_adjuster = pitch_error * bump_correction_intensity * 0.8; |
700 | | - } |
701 | | - else { |
702 | | - if (balance_bump_correction) { |
703 | | - if (balance_bump_beep) |
704 | | - beep_off(true); |
705 | | - } |
706 | | - balance_bump_correction = false; |
707 | | - balance_bump_adjuster = 0; |
708 | | - } |
709 | | - } |
710 | | - } |
711 | | - |
712 | 582 | duty_cycle = mc_interface_get_duty_cycle_now(); |
713 | 583 | abs_duty_cycle = fabsf(duty_cycle); |
714 | 584 | erpm = mc_interface_get_rpm(); |
|
0 commit comments