Skip to content

Commit

Permalink
filter max speed for kbemf estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Nov 4, 2024
1 parent 748dce7 commit d061502
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion firmware/src/BSP/actuator_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ float volatile current_to_actuatorTq;

volatile int16_t phase_R = 3000; // mOhm
volatile int16_t phase_L = 3230; // uH
volatile int16_t motor_k_bemf = 1333; // mV/(rev/s)
volatile int16_t motor_k_bemf = 1380; // mV/(rev/s)
// note, when motor_k_bemf is too low, the motor can have higher top speed when unloaded (unintentional field weakening via I_d), but power and torque will not be accurate
static float motor_k_torque; //Nm/A

// specify gearing parameters here:
Expand Down
19 changes: 12 additions & 7 deletions firmware/src/BSP/calibration.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,21 +329,26 @@ uint16_t StepperCtrl_calibrateEncoder(bool verifyOnly){
return maxError;
}

// Estimate motor k_bemf with no load
int8_t Estimate_motor_k_bemf() {
StepperCtrl_setMotionMode(STEPCTRL_OFF);
if (GetMotorVoltage() < MIN_SUPPLY_VOLTAGE) {
return -1;
}

// make sure U_d is 0
phase_L = 0;
// make sure U_d is 0 by forcing phase_L=0 since we know there is no load
phase_L = 0; // todo restore/learn later

//accelerate
StepperCtrl_setMotionMode(STEPCTRL_FEEDBACK_TORQUE);
StepperCtrl_setCurrent(INT16_MAX);
delay_ms(300);
//measure base speed
uint32_t base_speed = fastAbs(speed_slow);
//accelerate and observe (maximum) base speed
uint32_t base_speed = 0;
for (uint16_t i = 0; i < 300U; ++i) {
base_speed = max(base_speed, fastAbs(speed_slow));
delay_ms(1);
}

if (base_speed / ANGLE_STEPS < 1){ //require at least 1rev/s
// failed to accelerate sufficiently
StepperCtrl_setMotionMode(STEPCTRL_OFF);
Expand Down Expand Up @@ -373,15 +378,15 @@ int8_t Estimate_motor_k_bemf() {

StepperCtrl_setCurrent(0);
int16_t i = 0;
while ((fastAbs(speed_slow) > base_speed * 9 / 10) && (i < 10)) {
while ((fastAbs(speed_slow) > base_speed / 2) && (i < 100)) {
++i;
delay_ms(100);
// decay motor_k_bemf
motor_k_bemf = (int16_t)((int32_t)motor_k_bemf * 999 / 1000);
}
delay_ms(200);
}

update_actuator_parameters();
StepperCtrl_setMotionMode(STEPCTRL_OFF);
return motor_k_bemf;
}

0 comments on commit d061502

Please sign in to comment.