mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-21 07:14:22 +08:00
move out FOC voltage out of loop
This commit is contained in:
@@ -877,19 +877,7 @@ __attribute__((unused)) void FOC_voltage_loop(Motor_t* motor, float v_d, float v
|
||||
osSignalWait(M_SIGNAL_PH_CURRENT_MEAS, osWaitForever);
|
||||
update_rotor(motor);
|
||||
|
||||
float phase = get_rotor_phase(motor);
|
||||
float c = arm_cos_f32(phase);
|
||||
float s = arm_sin_f32(phase);
|
||||
float v_alpha = c * v_d - s * v_q;
|
||||
float v_beta = c * v_q + s * v_d;
|
||||
queue_voltage_timings(motor, v_alpha, v_beta);
|
||||
|
||||
// Check we meet deadlines after queueing
|
||||
motor->last_cpu_time = check_timing(motor);
|
||||
if (!(motor->last_cpu_time < motor->control_deadline)) {
|
||||
motor->error = ERROR_FOC_VOLTAGE_TIMING;
|
||||
return;
|
||||
}
|
||||
FOC_voltage(motor, v_d, v_q);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1155,6 +1143,21 @@ void queue_voltage_timings(Motor_t* motor, float v_alpha, float v_beta) {
|
||||
queue_modulation_timings(motor, mod_alpha, mod_beta);
|
||||
}
|
||||
|
||||
void FOC_voltage(Motor_t* motor, float v_d, float v_q) {
|
||||
float phase = get_rotor_phase(motor);
|
||||
float c = arm_cos_f32(phase);
|
||||
float s = arm_sin_f32(phase);
|
||||
float v_alpha = c*v_d - s*v_q;
|
||||
float v_beta = c*v_q + s*v_d;
|
||||
queue_voltage_timings(motor, v_alpha, v_beta);
|
||||
|
||||
// Check we meet deadlines after queueing
|
||||
if (!(check_timing(motor) < motor->control_deadline)) {
|
||||
motor->error = ERROR_FOC_VOLTAGE_TIMING;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool FOC_current(Motor_t* motor, float Id_des, float Iq_des) {
|
||||
Current_control_t* ictrl = &motor->current_control;
|
||||
|
||||
|
||||
@@ -237,6 +237,7 @@ void update_brake_current();
|
||||
void set_brake_current(float brake_current);
|
||||
void queue_modulation_timings(Motor_t* motor, float mod_alpha, float mod_beta);
|
||||
void queue_voltage_timings(Motor_t* motor, float v_alpha, float v_beta);
|
||||
void FOC_voltage(Motor_t* motor, float v_d, float v_q);
|
||||
bool FOC_current(Motor_t* motor, float Id_des, float Iq_des);
|
||||
void control_motor_loop(Motor_t* motor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user