Skip to content

Commit e9d262b

Browse files
committed
Remove complete balance bump compensation logic
This hack is no longer needed since we now have Mitch's Z-axis acc lowpass filter Signed-off-by: Dado Mista <dadomista@gmail.com>
1 parent 9dc8a90 commit e9d262b

File tree

2 files changed

+0
-137
lines changed

2 files changed

+0
-137
lines changed

applications/app_balance.c

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "timeout.h" // To reset the timeout
2727
#include "commands.h"
2828
#include "imu/imu.h"
29-
#include "imu/ahrs.h"
3029
#include "utils.h"
3130
#include "datatypes.h"
3231
#include "comm_can.h"
@@ -117,18 +116,6 @@ static systime_t brake_timeout;
117116
static float switch_warn_buzz_erpm;
118117
static bool is_dual_switch;
119118

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-
132119
// Debug values
133120
static int debug_render_1, debug_render_2;
134121
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) {
200187
if (angular_rate_kp >= 1)
201188
angular_rate_kp = 0;
202189

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-
221190
// Variable nose angle adjustment / tiltback (setting is per 1000erpm, convert to per erpm)
222191
tiltback_variable = balance_conf.tiltback_variable / 1000;
223192
if (tiltback_variable > 0) {
@@ -328,10 +297,6 @@ static void reset_vars(void){
328297
last_time = 0;
329298
diff_time = 0;
330299
brake_timeout = 0;
331-
332-
// Bump compensation
333-
bump_count = 0;
334-
balance_bump_correction = false;
335300
}
336301

337302
static float get_setpoint_adjustment_step_size(void){
@@ -614,101 +579,6 @@ static THD_FUNCTION(balance_thread, arg) {
614579
abs_roll_angle_sin = sinf(DEG2RAD_f(abs_roll_angle));
615580
imu_get_gyro(gyro);
616581

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-
712582
duty_cycle = mc_interface_get_duty_cycle_now();
713583
abs_duty_cycle = fabsf(duty_cycle);
714584
erpm = mc_interface_get_rpm();

imu/ahrs.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ static float m_kp = 0.3;
2424
static float m_ki = 0.0;
2525
static float m_beta = 0.1;
2626

27-
bool balance_bump_correction = false;
28-
float balance_bump_adjuster = 0.0;
29-
float bump_correction_intensity = 0.0;
30-
3127
// Private functions
3228
static float invSqrt(float x);
3329
static float calculateAccConfidence(float acc_confidence_decay, float accMag, float *accMagP);
@@ -167,9 +163,6 @@ void ahrs_update_mahony_imu(float *gyroXYZ, float *accelXYZ, float dt, ATTITUDE_
167163
gy += twoKp * halfey;
168164
gz += twoKp * halfez;
169165
}
170-
if (balance_bump_correction) {
171-
gy += balance_bump_adjuster;
172-
}
173166

174167
// Integrate rate of change of quaternion
175168
gx *= (0.5f * dt); // pre-multiply common factors

0 commit comments

Comments
 (0)