Skip to content

Commit

Permalink
Use smooth duty universally
Browse files Browse the repository at this point in the history
Duty cycle can spike a lot, the purposes it's used for can all benefit
from the mild smoothing we already have. Unify the usage and only use
smooth duty for everything.
  • Loading branch information
lukash committed Sep 14, 2024
1 parent 564eee7 commit 7f82603
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,13 +849,13 @@ static void add_surge(data *d) {
if (d->surge_enable) {
float surge_now = 0;

if (d->motor.duty_smooth > d->float_conf.surge_duty_start + 0.04) {
if (d->motor.duty_cycle > d->float_conf.surge_duty_start + 0.04) {
surge_now = d->surge_angle3;
beep_alert(d, 3, 1);
} else if (d->motor.duty_smooth > d->float_conf.surge_duty_start + 0.02) {
} else if (d->motor.duty_cycle > d->float_conf.surge_duty_start + 0.02) {
surge_now = d->surge_angle2;
beep_alert(d, 2, 1);
} else if (d->motor.duty_smooth > d->float_conf.surge_duty_start) {
} else if (d->motor.duty_cycle > d->float_conf.surge_duty_start) {
surge_now = d->surge_angle;
beep_alert(d, 1, 1);
}
Expand Down
5 changes: 1 addition & 4 deletions src/motor_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <math.h>

void motor_data_reset(MotorData *m) {
m->duty_smooth = 0;

m->acceleration = 0;
m->accel_idx = 0;
for (int i = 0; i < 40; i++) {
Expand All @@ -52,8 +50,7 @@ void motor_data_update(MotorData *m) {
m->current = VESC_IF->mc_get_tot_current_directional_filtered();
m->braking = m->abs_erpm > 250 && sign(m->current) != m->erpm_sign;

m->duty_cycle = fabsf(VESC_IF->mc_get_duty_cycle_now());
m->duty_smooth = m->duty_smooth * 0.9f + m->duty_cycle * 0.1f;
m->duty_cycle = m->duty_cycle * 0.9f + fabsf(VESC_IF->mc_get_duty_cycle_now()) * 0.1f;

float current_acceleration = m->erpm - m->last_erpm;
m->last_erpm = m->erpm;
Expand Down
1 change: 0 additions & 1 deletion src/motor_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ typedef struct {
bool braking;

float duty_cycle;
float duty_smooth;

// an average calculated over last ACCEL_ARRAY_SIZE values
float acceleration;
Expand Down

0 comments on commit 7f82603

Please sign in to comment.