|
|
|
@ -44,7 +44,6 @@ static void motor_control_task(void *pvParameters) {
|
|
|
|
float actual_speed;
|
|
|
|
float actual_speed;
|
|
|
|
float error;
|
|
|
|
float error;
|
|
|
|
float d_error;
|
|
|
|
float d_error;
|
|
|
|
// float duty_correction;
|
|
|
|
|
|
|
|
float mapped_duty;
|
|
|
|
float mapped_duty;
|
|
|
|
|
|
|
|
|
|
|
|
xLastWakeTime = xTaskGetTickCount();
|
|
|
|
xLastWakeTime = xTaskGetTickCount();
|
|
|
|
@ -66,7 +65,8 @@ static void motor_control_task(void *pvParameters) {
|
|
|
|
|
|
|
|
|
|
|
|
old_motor_duty = m_status[m_id].duty;
|
|
|
|
old_motor_duty = m_status[m_id].duty;
|
|
|
|
|
|
|
|
|
|
|
|
m_status[m_id].duty = m_param.kp * error + m_param.ki * m_status[m_id].i_error + m_param.kd * d_error;
|
|
|
|
m_status[m_id].duty = (m_param.kp * error) + (m_param.ki * m_status[m_id].i_error) +
|
|
|
|
|
|
|
|
(m_param.kd * d_error) + m_param.op_offset;
|
|
|
|
|
|
|
|
|
|
|
|
// Clip duty correction to the maximum allowed ramp
|
|
|
|
// Clip duty correction to the maximum allowed ramp
|
|
|
|
if ((m_status[m_id].duty - old_motor_duty) > (MAX_DUTY_RAMP * MC_ITERATION_TIME)) {
|
|
|
|
if ((m_status[m_id].duty - old_motor_duty) > (MAX_DUTY_RAMP * MC_ITERATION_TIME)) {
|
|
|
|
@ -92,8 +92,11 @@ static void motor_control_task(void *pvParameters) {
|
|
|
|
m_status[m_id].i_error = new_i_error;
|
|
|
|
m_status[m_id].i_error = new_i_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Map duty to fit between min and tri-phase limit for actual motor PWM
|
|
|
|
// Map the control output to actual motor duty between MIN_DUTY and MAX_DUTY.
|
|
|
|
mapped_duty = 0.33 * (m_status[m_id].duty * (MAX_DUTY - m_param.min_duty) + m_param.min_duty);
|
|
|
|
// These are still phase synchronised 33% apart, so MAX_DUTY needs to be less than 33% if we want to
|
|
|
|
|
|
|
|
// avoid running two at once.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapped_duty = (m_status[m_id].duty * (MAX_DUTY - MIN_DUTY)) + MIN_DUTY;
|
|
|
|
// This function takes duty as a float percent...
|
|
|
|
// This function takes duty as a float percent...
|
|
|
|
mcpwm_set_duty(MCPWM_UNIT_0, motor_timer[m_id], MCPWM_GEN_A, mapped_duty * 100.0);
|
|
|
|
mcpwm_set_duty(MCPWM_UNIT_0, motor_timer[m_id], MCPWM_GEN_A, mapped_duty * 100.0);
|
|
|
|
|
|
|
|
|
|
|
|
@ -173,7 +176,7 @@ void motor_control_setup(void) {
|
|
|
|
|
|
|
|
|
|
|
|
motor_control_t default_motor_control = {.enabled = false, .desired_speed = 0.0};
|
|
|
|
motor_control_t default_motor_control = {.enabled = false, .desired_speed = 0.0};
|
|
|
|
motor_parameters_t default_motor_parameters = {
|
|
|
|
motor_parameters_t default_motor_parameters = {
|
|
|
|
.kp = DEFAULT_KP, .ki = DEFAULT_KI, .kd = DEFAULT_KD, .min_duty = DEFAULT_MIN_DUTY};
|
|
|
|
.kp = DEFAULT_KP, .ki = DEFAULT_KI, .kd = DEFAULT_KD, .op_offset = DEFAULT_OP_OFFSET};
|
|
|
|
motor_status_t blank_motor_status;
|
|
|
|
motor_status_t blank_motor_status;
|
|
|
|
|
|
|
|
|
|
|
|
xQueueOverwrite(motor_control_queue[m_id], &default_motor_control);
|
|
|
|
xQueueOverwrite(motor_control_queue[m_id], &default_motor_control);
|
|
|
|
@ -189,7 +192,7 @@ void motor_control_setup(void) {
|
|
|
|
if (err == ESP_OK) {
|
|
|
|
if (err == ESP_OK) {
|
|
|
|
xQueueOverwrite(motor_parameters_queue[m_id], &stored_motor_parameters);
|
|
|
|
xQueueOverwrite(motor_parameters_queue[m_id], &stored_motor_parameters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Setup MCPWM timers.
|
|
|
|
// Setup MCPWM timers.
|
|
|
|
mcpwm_config_t pwm_config = {
|
|
|
|
mcpwm_config_t pwm_config = {
|
|
|
|
|