|
|
|
@ -50,7 +50,7 @@ static void motor_control_task(void *pvParameters) {
|
|
|
|
|
|
|
|
|
|
|
|
if (m_ctrl.enabled) {
|
|
|
|
if (m_ctrl.enabled) {
|
|
|
|
|
|
|
|
|
|
|
|
actual_speed = get_roller_speed(m_id);
|
|
|
|
actual_speed = get_roller_speed((roller_id_t)m_id);
|
|
|
|
error = m_ctrl.desired_speed - actual_speed;
|
|
|
|
error = m_ctrl.desired_speed - actual_speed;
|
|
|
|
m_status[m_id].i_error += error * MC_ITERATION_TIME;
|
|
|
|
m_status[m_id].i_error += error * MC_ITERATION_TIME;
|
|
|
|
d_error = (error - m_status[m_id].last_error) / MC_ITERATION_TIME;
|
|
|
|
d_error = (error - m_status[m_id].last_error) / MC_ITERATION_TIME;
|
|
|
|
@ -101,27 +101,27 @@ static void motor_control_task(void *pvParameters) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set_motor_control(int motor_id, motor_control_t new_control) {
|
|
|
|
void set_motor_control(motor_id_t motor_id, motor_control_t new_control) {
|
|
|
|
xQueueOverwrite(motor_control_queue[motor_id], &new_control);
|
|
|
|
xQueueOverwrite(motor_control_queue[motor_id], &new_control);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set_motor_params(int motor_id, motor_parameters_t new_params) {
|
|
|
|
void set_motor_params(motor_id_t motor_id, motor_parameters_t new_params) {
|
|
|
|
xQueueOverwrite(motor_parameters_queue[motor_id], &new_params);
|
|
|
|
xQueueOverwrite(motor_parameters_queue[motor_id], &new_params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
motor_control_t get_motor_control(int motor_id) {
|
|
|
|
motor_control_t get_motor_control(motor_id_t motor_id) {
|
|
|
|
motor_control_t current_motor_control;
|
|
|
|
motor_control_t current_motor_control;
|
|
|
|
xQueuePeek(motor_control_queue[motor_id], ¤t_motor_control, 0);
|
|
|
|
xQueuePeek(motor_control_queue[motor_id], ¤t_motor_control, 0);
|
|
|
|
return current_motor_control;
|
|
|
|
return current_motor_control;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
motor_parameters_t get_motor_parameters(int motor_id) {
|
|
|
|
motor_parameters_t get_motor_parameters(motor_id_t motor_id) {
|
|
|
|
motor_parameters_t current_motor_params;
|
|
|
|
motor_parameters_t current_motor_params;
|
|
|
|
xQueuePeek(motor_parameters_queue[motor_id], ¤t_motor_params, 0);
|
|
|
|
xQueuePeek(motor_parameters_queue[motor_id], ¤t_motor_params, 0);
|
|
|
|
return current_motor_params;
|
|
|
|
return current_motor_params;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float get_motor_duty(int motor_id) {
|
|
|
|
float get_motor_duty(motor_id_t motor_id) {
|
|
|
|
motor_status_t motor_status;
|
|
|
|
motor_status_t motor_status;
|
|
|
|
|
|
|
|
|
|
|
|
xQueuePeek(motor_status_queue[motor_id], &motor_status, 0);
|
|
|
|
xQueuePeek(motor_status_queue[motor_id], &motor_status, 0);
|
|
|
|
@ -139,12 +139,13 @@ void motor_control_setup(void) {
|
|
|
|
// Prime queues - these are single item queues, and so functions reading from them just
|
|
|
|
// Prime queues - these are single item queues, and so functions reading from them just
|
|
|
|
// assume something is there.
|
|
|
|
// assume something is there.
|
|
|
|
// TODO - this is where we'd read in the saved motor params from flash.
|
|
|
|
// TODO - this is where we'd read in the saved motor params from flash.
|
|
|
|
motor_control_t init_motor_control;
|
|
|
|
|
|
|
|
motor_parameters_t init_motor_params;
|
|
|
|
|
|
|
|
motor_status_t blank_motor_status;
|
|
|
|
motor_status_t blank_motor_status;
|
|
|
|
|
|
|
|
motor_control_t default_motor_control = {.enabled = false, .desired_speed = 0.0};
|
|
|
|
|
|
|
|
motor_parameters_t default_motor_parameters = {
|
|
|
|
|
|
|
|
.kp = DEFAULT_KP, .ki = DEFAULT_KI, .kd = DEFAULT_KD, .min_duty = DEFAULT_MIN_DUTY};
|
|
|
|
|
|
|
|
|
|
|
|
xQueueOverwrite(motor_control_queue[m_id], &init_motor_control);
|
|
|
|
xQueueOverwrite(motor_control_queue[m_id], &default_motor_control);
|
|
|
|
xQueueOverwrite(motor_parameters_queue[m_id], &init_motor_params);
|
|
|
|
xQueueOverwrite(motor_parameters_queue[m_id], &default_motor_parameters);
|
|
|
|
xQueueOverwrite(motor_status_queue[m_id], &blank_motor_status);
|
|
|
|
xQueueOverwrite(motor_status_queue[m_id], &blank_motor_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|