From f8f009dd39b6c276b80e728cf2b31e127df3c562 Mon Sep 17 00:00:00 2001 From: Richie <2837357W@student.gla.ac.uk> Date: Mon, 20 Nov 2023 14:47:51 +0800 Subject: [PATCH] test+++ --- frtos/motor/motor_direction.h | 2 +- frtos/motor/motor_speed.h | 45 ++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/frtos/motor/motor_direction.h b/frtos/motor/motor_direction.h index dfd0c2e..931762a 100644 --- a/frtos/motor/motor_direction.h +++ b/frtos/motor/motor_direction.h @@ -30,7 +30,7 @@ set_wheel_direction(uint32_t direction) void update_target_yaw(volatile direction_t * g_direction) { - updateDirection(g_direction); +// updateDirection(g_direction); g_direction->target_yaw = g_direction->yaw; } diff --git a/frtos/motor/motor_speed.h b/frtos/motor/motor_speed.h index 997c205..6f1758c 100644 --- a/frtos/motor/motor_speed.h +++ b/frtos/motor/motor_speed.h @@ -105,27 +105,28 @@ set_wheel_speed_synced(uint32_t pwm_level, car_struct_t *pp_car_strut) set_wheel_speed(pwm_level, pp_car_strut->p_right_motor); } -///*! -// * @brief Set the distance to travel before stopping, must be called after -// * setting the speed and direction. -// * @param distance_cm distance to travel in cm -// */ -//void -//distance_to_stop(float distance_cm) -//{ -// float initial = g_motor_right.speed.distance_cm; -// -// for (;;) -// { -// if (g_motor_right.speed.distance_cm - initial >= distance_cm) -// { -// set_wheel_speed_synced(0u); -// break; -// } -// vTaskDelay(pdMS_TO_TICKS(10)); -// } -// vTaskDelay(pdMS_TO_TICKS(1000)); -// g_motor_right.speed.distance_cm = g_motor_left.speed.distance_cm; -//} +/*! + * @brief Set the distance to travel before stopping, must be called after + * setting the speed and direction. + * @param distance_cm distance to travel in cm + */ +void +distance_to_stop(car_struct_t * pp_car_struct, float distance_cm) +{ + float initial = pp_car_struct->p_left_motor->speed.distance_cm; + + for (;;) + { + if (pp_car_struct->p_left_motor->speed.distance_cm - initial >= distance_cm) + { + set_wheel_speed_synced(0u); + break; + } + vTaskDelay(pdMS_TO_TICKS(10)); + } + vTaskDelay(pdMS_TO_TICKS(1000)); + pp_car_struct->p_right_motor->speed.distance_cm = + pp_car_struct->p_left_motor->speed.distance_cm; +} #endif /* MOTOR_SPEED_H */