Skip to content

Commit

Permalink
Conditional parking brake checks for erpm sign now
Browse files Browse the repository at this point in the history
If rider jumps off the board and the board changes direction after
jumping off, it is assumed that the parking brake should be on.

Fix: don't let board roll downhill after jumping off at low speed
  • Loading branch information
surfdado committed Dec 22, 2024
1 parent 4789b74 commit ea98b2e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ static bool check_faults(data *d) {
// allow turning it off by engaging foot sensors
state_stop(&d->state, STOP_SWITCH_HALF);
return true;
} else {
d->motor.last_erpm_sign = d->motor.erpm_sign;
}
} else {
bool disable_switch_faults = d->float_conf.fault_moving_fault_disabled &&
Expand Down Expand Up @@ -592,6 +594,7 @@ static bool check_faults(data *d) {
}
} else {
d->fault_switch_timer = d->current_time;
d->motor.last_erpm_sign = d->motor.erpm_sign;
}

// Feature: Reverse-Stop
Expand Down Expand Up @@ -1453,9 +1456,7 @@ static void refloat_thd(void *arg) {
break;
}

motor_control_apply(
&d->motor_control, d->motor.abs_erpm_smooth, d->state.state, d->current_time
);
motor_control_apply(&d->motor_control, &d->motor, d->state.state, d->current_time);
VESC_IF->sleep_us(d->loop_time_us);
}
}
Expand Down
30 changes: 20 additions & 10 deletions src/motor_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ void motor_control_configure(MotorControl *mc, const RefloatConfig *config) {
mc->click_current = config->startup_click_current;
mc->parking_brake_mode = config->parking_brake_mode;
mc->main_freq = config->hertz / 2;

// set parking brake true/false here instead of each cycle
if (mc->parking_brake_mode == PARKING_BRAKE_ALWAYS) {
mc->parking_brake_active = true;
} else {
mc->parking_brake_active = false;
}
}

void motor_control_request_current(MotorControl *mc, float current) {
Expand All @@ -51,14 +58,7 @@ static inline void reset_tone(MotorControl *mc) {
mc->tone_high = 0;
}

void motor_control_apply(MotorControl *mc, float abs_erpm, RunState state, float time) {
if (mc->parking_brake_mode == PARKING_BRAKE_ALWAYS ||
(mc->parking_brake_mode == PARKING_BRAKE_IDLE && state != STATE_RUNNING && abs_erpm < 50)) {
mc->parking_brake_active = true;
} else if (mc->parking_brake_mode == PARKING_BRAKE_NEVER || state == STATE_RUNNING) {
mc->parking_brake_active = false;
}

void motor_control_apply(MotorControl *mc, MotorData *md, RunState state, float time) {
if (mc->tone_ticks > 0) {
mc->current_requested = true;

Expand Down Expand Up @@ -87,7 +87,17 @@ void motor_control_apply(MotorControl *mc, float abs_erpm, RunState state, float
VESC_IF->mc_set_current(mc->requested_current);
} else {
// Brake logic
if (abs_erpm > ERPM_MOVING_THRESHOLD) {
if (mc->parking_brake_mode == PARKING_BRAKE_IDLE) {
// only evaluate parking brake each cycle if pbmode is IDLE
if ((state != STATE_RUNNING) &&
((md->abs_erpm_smooth < 50) || (md->last_erpm_sign != md->erpm_sign))) {
mc->parking_brake_active = true;
} else {
mc->parking_brake_active = false;
}
}

if (md->abs_erpm_smooth > ERPM_MOVING_THRESHOLD) {
mc->brake_timeout = time + 1.0f;
}

Expand All @@ -97,7 +107,7 @@ void motor_control_apply(MotorControl *mc, float abs_erpm, RunState state, float
return;
}

if (mc->parking_brake_active && abs_erpm < 2000) {
if (mc->parking_brake_active && md->abs_erpm_smooth < 2000) {
// Duty Cycle mode has better holding power (phase-shorting on 6.05)
VESC_IF->mc_set_duty(0);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/motor_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdint.h>

#include "conf/datatypes.h"
#include "motor_data.h"
#include "state.h"

typedef struct {
Expand Down Expand Up @@ -48,7 +49,7 @@ void motor_control_configure(MotorControl *mc, const RefloatConfig *config);

void motor_control_request_current(MotorControl *mc, float current);

void motor_control_apply(MotorControl *mc, float abs_erpm, RunState state, float time);
void motor_control_apply(MotorControl *mc, MotorData *md, RunState state, float time);

void motor_control_play_tone(MotorControl *mc, uint16_t frequency, float intensity);

Expand Down
1 change: 1 addition & 0 deletions src/motor_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef struct {
float abs_erpm_smooth;
float last_erpm;
int8_t erpm_sign;
int8_t last_erpm_sign; // last erpm sign prior to footpads disengaging

float current;
bool braking;
Expand Down

0 comments on commit ea98b2e

Please sign in to comment.