pending dodge test

This commit is contained in:
Richie 2023-11-09 15:16:50 +08:00
parent 6ac564ee04
commit 034ccb47e5
2 changed files with 36 additions and 9 deletions

View File

@ -77,12 +77,12 @@ check_direction(float current_direction, float target_direction, float range)
void
spin_to_yaw(uint32_t direction, float target_yaw, car_struct_t *pp_car_struct)
{
pp_car_struct->p_pid->use_pid = false;
set_wheel_direction(direction);
set_wheel_speed_synced(80u, pp_car_struct);
pp_car_struct->p_pid->use_pid = false;
for (;;)
{
updateDirection();
@ -101,18 +101,26 @@ spin_to_yaw(uint32_t direction, float target_yaw, car_struct_t *pp_car_struct)
void
spin_right(float degree, car_struct_t *pp_car_struct)
{
set_wheel_direction(DIRECTION_MASK);
vTaskDelay(pdMS_TO_TICKS(50));
updateDirection();
float initial_yaw = g_direction.yaw;
float target_yaw = adjust_yaw(initial_yaw + degree);
spin_to_yaw(DIRECTION_RIGHT, target_yaw, pp_car_struct);
}
void
spin_left(float degree, car_struct_t *pp_car_struct)
{
set_wheel_direction(DIRECTION_MASK);
vTaskDelay(pdMS_TO_TICKS(50));
updateDirection();
float initial_yaw = g_direction.yaw;
float target_yaw = adjust_yaw(initial_yaw - degree);
spin_to_yaw(DIRECTION_LEFT, target_yaw, pp_car_struct);
}

View File

@ -4,21 +4,40 @@
#include "car_config.h"
#include "motor_init.h"
bool
check_collision(void *params)
{
car_struct_t *car_struct = (car_struct_t *)params;
return !(car_struct->obs->line_detected) ||
car_struct->obs->ultrasonic_detected;
}
void
motor_control_task(void *params)
{
car_struct_t *car_struct = (car_struct_t *)params;
for (;;)
{
if (check_collision(car_struct))
{
spin_left(90, car_struct);
if (check_collision(car_struct))
{
spin_right(180, car_struct);
if (check_collision(car_struct))
{
spin_right(90, car_struct);
}
}
}
else
{
set_wheel_direction(DIRECTION_FORWARD);
set_wheel_speed_synced(90u, car_struct);
vTaskDelay(pdMS_TO_TICKS(10000));
revert_wheel_direction();
set_wheel_speed_synced(90u, car_struct);
vTaskDelay(pdMS_TO_TICKS(10000));
}
vTaskDelay(pdMS_TO_TICKS(5));
}
}