Skip to content

Commit

Permalink
Refactor abnormal voltage check to be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
yconst committed Jul 29, 2024
1 parent 0ffd022 commit 49a2ea3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 0 additions & 2 deletions firmware/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#define PWM_FREQ_HZ (20000)
#define SYSTICK_FREQ_HZ (1000)

#define MAX_CALIBRATION_POWER 30.0f // W

// Control parameters
#define PWM_LIMIT (0.8f)
#define I_INTEGRATOR_DECAY_FACTOR (0.995f)
Expand Down
3 changes: 2 additions & 1 deletion firmware/src/motor/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ bool motor_calibrate_resistance(void)
{
ADC_get_phase_currents(&I_phase_meas);

if (powf(V_setpoint, 2) / MAX_PHASE_RESISTANCE > MAX_CALIBRATION_POWER)
//
if (V_setpoint > MAX_CALIBRATION_VOLTAGE && I_phase_meas.A < MIN_CALIBRATION_CURRENT)
{
uint8_t *error_ptr = motor_get_error_ptr();
*error_ptr |= MOTOR_ERRORS_ABNORMAL_CALIBRATION_VOLTAGE;
Expand Down
4 changes: 4 additions & 0 deletions firmware/src/motor/motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
#define MAX_PHASE_RESISTANCE (1.0f)
#define MIN_PHASE_INDUCTANCE (5e-6f)
#define MAX_PHASE_INDUCTANCE (1e-3f)
#define MAX_CALIBRATION_VOLTAGE (0.5f) // V
#define MIN_CALIBRATION_CURRENT (0.2f) // A
#elif defined BOARD_REV_M5
#define MIN_PHASE_RESISTANCE (0.5f)
#define MAX_PHASE_RESISTANCE (20.0f)
#define MIN_PHASE_INDUCTANCE (1e-5f)
#define MAX_PHASE_INDUCTANCE (1e-2f)
#define MAX_CALIBRATION_VOLTAGE (5.0f) // V
#define MIN_CALIBRATION_CURRENT (0.1f) // A
#endif

#define CAL_R_LEN (2 * PWM_FREQ_HZ)
Expand Down

0 comments on commit 49a2ea3

Please sign in to comment.