|
|
|
|
@ -56,7 +56,7 @@ static void motor_control_task(void *pvParameters) {
|
|
|
|
|
|
|
|
|
|
if (m_set.enabled) {
|
|
|
|
|
|
|
|
|
|
actual_speed = getRoller1Speed();
|
|
|
|
|
actual_speed = get_roller_speed(m_id);
|
|
|
|
|
error = m_set.desired_speed - actual_speed;
|
|
|
|
|
m_stat[m_id].i_error += error * MC_ITERATION_TIME;
|
|
|
|
|
d_error = (error - m_stat[m_id].last_error) / MC_ITERATION_TIME;
|
|
|
|
|
@ -107,51 +107,21 @@ static void motor_control_task(void *pvParameters) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_motor_1(bool enabled, float desired_speed) {
|
|
|
|
|
void set_motor(int motor_id, bool enabled, float desired_speed) {
|
|
|
|
|
motor_settings_t new_settings;
|
|
|
|
|
|
|
|
|
|
xQueuePeek(motor_settings_queue[0], &new_settings, 0);
|
|
|
|
|
// Get copy of current settings
|
|
|
|
|
xQueuePeek(motor_settings_queue[motor_id], &new_settings, 0);
|
|
|
|
|
new_settings.enabled = enabled;
|
|
|
|
|
new_settings.desired_speed = desired_speed;
|
|
|
|
|
xQueueOverwrite(motor_settings_queue[0], &new_settings);
|
|
|
|
|
// Send new modified settings
|
|
|
|
|
xQueueOverwrite(motor_settings_queue[motor_id], &new_settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_motor_2(bool enabled, float desired_speed) {
|
|
|
|
|
motor_settings_t new_settings;
|
|
|
|
|
|
|
|
|
|
xQueuePeek(motor_settings_queue[1], &new_settings, 0);
|
|
|
|
|
new_settings.enabled = enabled;
|
|
|
|
|
new_settings.desired_speed = desired_speed;
|
|
|
|
|
xQueueOverwrite(motor_settings_queue[1], &new_settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_motor_3(bool enabled, float desired_speed) {
|
|
|
|
|
motor_settings_t new_settings;
|
|
|
|
|
|
|
|
|
|
xQueuePeek(motor_settings_queue[2], &new_settings, 0);
|
|
|
|
|
new_settings.enabled = enabled;
|
|
|
|
|
new_settings.desired_speed = desired_speed;
|
|
|
|
|
xQueueOverwrite(motor_settings_queue[2], &new_settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float get_motor_1_duty() {
|
|
|
|
|
float get_motor_duty(int motor_id) {
|
|
|
|
|
motor_status_t motor_status;
|
|
|
|
|
|
|
|
|
|
xQueuePeek(motor_status_queue[0], &motor_status, 0);
|
|
|
|
|
return motor_status.duty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float get_motor_2_duty() {
|
|
|
|
|
motor_status_t motor_status;
|
|
|
|
|
|
|
|
|
|
xQueuePeek(motor_status_queue[1], &motor_status, 0);
|
|
|
|
|
return motor_status.duty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float get_motor_3_duty() {
|
|
|
|
|
motor_status_t motor_status;
|
|
|
|
|
|
|
|
|
|
xQueuePeek(motor_status_queue[2], &motor_status, 0);
|
|
|
|
|
xQueuePeek(motor_status_queue[motor_id], &motor_status, 0);
|
|
|
|
|
return motor_status.duty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -189,6 +159,18 @@ void motor_control_setup(void) {
|
|
|
|
|
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config);
|
|
|
|
|
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_2, &pwm_config);
|
|
|
|
|
|
|
|
|
|
// Set Timer 0 to generate sync signal when it reaches the top
|
|
|
|
|
mcpwm_set_timer_sync_output(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SWSYNC_SOURCE_TEP);
|
|
|
|
|
|
|
|
|
|
mcpwm_sync_config_t sync_conf = {
|
|
|
|
|
.sync_sig = MCPWM_SELECT_TIMER0_SYNC,
|
|
|
|
|
.timer_val = 333,
|
|
|
|
|
.count_direction = MCPWM_TIMER_DIRECTION_UP,
|
|
|
|
|
};
|
|
|
|
|
mcpwm_sync_configure(MCPWM_UNIT_0, MCPWM_TIMER_1, &sync_conf);
|
|
|
|
|
sync_conf.timer_val = 666;
|
|
|
|
|
mcpwm_sync_configure(MCPWM_UNIT_0, MCPWM_TIMER_2, &sync_conf);
|
|
|
|
|
|
|
|
|
|
// Bind to output
|
|
|
|
|
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_ROLLER1_PWM);
|
|
|
|
|
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1A, GPIO_ROLLER2_PWM);
|
|
|
|
|
|