|
|
|
@ -9,11 +9,6 @@
|
|
|
|
#include "freertos/queue.h"
|
|
|
|
#include "freertos/queue.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define MOTOR_PWM_FREQ 1000 // PWM frequency in Hz
|
|
|
|
|
|
|
|
#define MOTOR_CONTROL_PERIOD_MS 100 // Period of the motor control loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_DUTY_RAMP 5.0 // max change in duty per second - where 1.0 is full duty
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MC_ITERATION_TIME 1.0 / MOTOR_CONTROL_PERIOD_MS
|
|
|
|
#define MC_ITERATION_TIME 1.0 / MOTOR_CONTROL_PERIOD_MS
|
|
|
|
|
|
|
|
|
|
|
|
#define MC_TASK_STACK_SIZE 2048
|
|
|
|
#define MC_TASK_STACK_SIZE 2048
|
|
|
|
@ -55,7 +50,7 @@ static void motor_control_task(void *pvParameters) {
|
|
|
|
xLastWakeTime = xTaskGetTickCount();
|
|
|
|
xLastWakeTime = xTaskGetTickCount();
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
|
|
|
|
for (int m_id = 0; m_id < 1; m_id++) {
|
|
|
|
for (int m_id = 0; m_id < 3; m_id++) {
|
|
|
|
// Get the latest motor settings
|
|
|
|
// Get the latest motor settings
|
|
|
|
xQueuePeek(motor_settings_queue[m_id], &m_set, 0);
|
|
|
|
xQueuePeek(motor_settings_queue[m_id], &m_set, 0);
|
|
|
|
|
|
|
|
|
|
|
|
@ -121,11 +116,42 @@ void set_motor_1(bool enabled, float desired_speed) {
|
|
|
|
xQueueOverwrite(motor_settings_queue[0], &new_settings);
|
|
|
|
xQueueOverwrite(motor_settings_queue[0], &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_1_duty() {
|
|
|
|
motor_status_t motor_status;
|
|
|
|
motor_status_t motor_status;
|
|
|
|
|
|
|
|
|
|
|
|
xQueuePeek(motor_status_queue[0], &motor_status, 0);
|
|
|
|
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);
|
|
|
|
return motor_status.duty;
|
|
|
|
return motor_status.duty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -160,9 +186,13 @@ void motor_control_setup(void) {
|
|
|
|
.counter_mode = MCPWM_UP_COUNTER,
|
|
|
|
.counter_mode = MCPWM_UP_COUNTER,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);
|
|
|
|
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);
|
|
|
|
|
|
|
|
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config);
|
|
|
|
|
|
|
|
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_2, &pwm_config);
|
|
|
|
|
|
|
|
|
|
|
|
// Bind to output
|
|
|
|
// Bind to output
|
|
|
|
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_ROLLER1_PWM);
|
|
|
|
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_ROLLER1_PWM);
|
|
|
|
|
|
|
|
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1A, GPIO_ROLLER2_PWM);
|
|
|
|
|
|
|
|
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM2A, GPIO_ROLLER3_PWM);
|
|
|
|
|
|
|
|
|
|
|
|
// Setup EN pins
|
|
|
|
// Setup EN pins
|
|
|
|
gpio_set_level(GPIO_ROLLER1_EN, 0);
|
|
|
|
gpio_set_level(GPIO_ROLLER1_EN, 0);
|
|
|
|
|