From 84e22bc48861aa1912891284f8a713030eea794a Mon Sep 17 00:00:00 2001 From: Richie <2837357W@student.gla.ac.uk> Date: Fri, 13 Oct 2023 17:44:57 +0800 Subject: [PATCH] modified speed function; prep for pid --- frtos/car/rtos_car.c | 2 +- frtos/car/wheel.h | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/frtos/car/rtos_car.c b/frtos/car/rtos_car.c index 2b925b3..c46b6e5 100644 --- a/frtos/car/rtos_car.c +++ b/frtos/car/rtos_car.c @@ -64,7 +64,7 @@ main (void) sleep_ms(2000); set_wheel_direction(DIRECTION_RIGHT_FORWARD); - set_wheel_speed(1.f); + set_wheel_speed(1.f, 1u); launch(); diff --git a/frtos/car/wheel.h b/frtos/car/wheel.h index 9a46b99..b9932cc 100644 --- a/frtos/car/wheel.h +++ b/frtos/car/wheel.h @@ -101,16 +101,27 @@ set_wheel_direction (uint32_t direction) gpio_set_mask(direction); } +/*! + * @brief Set the speed of the wheels; can use bitwise OR to set both + * @param speed in range [0.0, 1.0] + * @param side 0 for left, 1 for right + */ void -set_wheel_speed (float speed) +set_wheel_speed (float speed, uint8_t side) { - pwm_set_chan_level(g_slice_num_left, - PWM_CHAN_A, - (short) (PWM_WRAP * speed)); + if (side == 0U) + { + pwm_set_chan_level(g_slice_num_left, + PWM_CHAN_A, + (short) (PWM_WRAP * speed)); + } + else + { + pwm_set_chan_level(g_slice_num_right, + PWM_CHAN_B, + (short) (PWM_WRAP * speed)); + } - pwm_set_chan_level(g_slice_num_right, - PWM_CHAN_B, - (short) (PWM_WRAP * speed)); } void