pending dodge test
This commit is contained in:
parent
6ac564ee04
commit
034ccb47e5
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue