From c7950d3ec6cf2d80e80cc3ac489d90dbe12e4df7 Mon Sep 17 00:00:00 2001 From: Richie <2837357W@student.gla.ac.uk> Date: Sat, 21 Oct 2023 00:04:13 +0800 Subject: [PATCH] merged left and right speed sensor isr into one handler --- frtos/motor/motor_speed.h | 19 ++++++++++++------- frtos/motor/motor_test.c | 6 ++---- frtos/rtos_car.c | 5 ++--- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/frtos/motor/motor_speed.h b/frtos/motor/motor_speed.h index cc989e0..3d4db12 100644 --- a/frtos/motor/motor_speed.h +++ b/frtos/motor/motor_speed.h @@ -27,29 +27,26 @@ set_wheel_speed(float speed, uint8_t side) } } +/*! + * @brief Interrupt handler for the wheel sensor + */ void -h_left_wheel_sensor_isr_handler(void) +h_wheel_sensor_isr_handler(void) { if (gpio_get_irq_event_mask(SPEED_PIN_LEFT) & GPIO_IRQ_EDGE_FALL) { gpio_acknowledge_irq(SPEED_PIN_LEFT, GPIO_IRQ_EDGE_FALL); - // printf("left motor sensor isr\n"); BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(g_wheel_speed_sem_left, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } -} -void -h_right_wheel_sensor_isr_handler(void) -{ if (gpio_get_irq_event_mask(SPEED_PIN_RIGHT) & GPIO_IRQ_EDGE_FALL) { gpio_acknowledge_irq(SPEED_PIN_RIGHT, GPIO_IRQ_EDGE_FALL); - // printf("right motor sensor isr\n"); BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(g_wheel_speed_sem_right, &xHigherPriorityTaskWoken); @@ -57,6 +54,14 @@ h_right_wheel_sensor_isr_handler(void) } } +/*! + * @brief Compute the control signal using PID controller + * @param target_speed The target speed of the wheel + * @param current_speed The current speed of the wheel + * @param integral The integral term of the PID controller + * @param prev_error The previous error of the PID controller + * @return The control signal + */ float compute_pid(float target_speed, float current_speed, diff --git a/frtos/motor/motor_test.c b/frtos/motor/motor_test.c index 7c58ee1..4a5e236 100644 --- a/frtos/motor/motor_test.c +++ b/frtos/motor/motor_test.c @@ -11,13 +11,11 @@ launch() { // isr to detect right motor slot gpio_set_irq_enabled(SPEED_PIN_RIGHT, GPIO_IRQ_EDGE_FALL, true); - gpio_add_raw_irq_handler(SPEED_PIN_RIGHT, - h_right_wheel_sensor_isr_handler); + gpio_add_raw_irq_handler(SPEED_PIN_RIGHT, h_wheel_sensor_isr_handler); // isr to detect left motor slot gpio_set_irq_enabled(SPEED_PIN_LEFT, GPIO_IRQ_EDGE_FALL, true); - gpio_add_raw_irq_handler(SPEED_PIN_LEFT, - h_left_wheel_sensor_isr_handler); + gpio_add_raw_irq_handler(SPEED_PIN_LEFT, h_wheel_sensor_isr_handler); irq_set_enabled(IO_IRQ_BANK0, true); diff --git a/frtos/rtos_car.c b/frtos/rtos_car.c index 2b9e283..56453dd 100644 --- a/frtos/rtos_car.c +++ b/frtos/rtos_car.c @@ -24,12 +24,11 @@ launch() // isr to detect right motor slot gpio_set_irq_enabled(SPEED_PIN_RIGHT, GPIO_IRQ_EDGE_FALL, true); gpio_add_raw_irq_handler(SPEED_PIN_RIGHT, - h_right_wheel_sensor_isr_handler); + h_wheel_sensor_isr_handler); // isr to detect left motor slot gpio_set_irq_enabled(SPEED_PIN_LEFT, GPIO_IRQ_EDGE_FALL, true); - gpio_add_raw_irq_handler(SPEED_PIN_LEFT, - h_left_wheel_sensor_isr_handler); + gpio_add_raw_irq_handler(SPEED_PIN_LEFT, h_wheel_sensor_isr_handler); irq_set_enabled(IO_IRQ_BANK0, true);