Files
QDAC-firmware/app/gl_barrier.c

64 lines
1.9 KiB
C
Raw Normal View History

2024-03-23 09:43:06 +08:00
#include "zf_common_headfile.h"
#include "gl_headfile.h"
enum barrier_type_e barrier_type = BARRIER_NONE;
2024-03-24 18:26:36 +08:00
uint16 time_barrier;
void CheckBarrier()
{
2024-03-23 09:43:06 +08:00
if (barrier_type == BARRIER_NONE && Lpt0_found_barrier_in && !Lpt1_found_barrier_in && is_straight1) {
barrier_type = BARRIER_LEFT_BEGIN;
}
if (barrier_type == BARRIER_NONE && !Lpt0_found_barrier_in && Lpt1_found_barrier_in && is_straight0) {
barrier_type = BARRIER_RIGHT_BEGIN;
}
}
2024-03-24 18:26:36 +08:00
void RunBarrier()
{
if (barrier_type == BARRIER_LEFT_BEGIN) {
track_type = TRACK_RIGHT;
if (Lpt0_found) {
Lpt0_found_count++;
}
if (Lpt0_found_count >= 1 && time_barrier >= 5000) {
Lpt0_found_count = 0;
barrier_type = BARRIER_LEFT_RUNNING;
track_type = TRACK_RIGHT;
timer_clear(TIM_3);
timer_start(TIM_3);
}
} else if (barrier_type == BARRIER_LEFT_RUNNING) {
track_type = TRACK_RIGHT;
time_barrier = timer_get(TIM_3);
if (time_barrier >= 5000) {
barrier_type = BARRIER_NONE;
track_type = TRACK_RIGHT;
timer_start(TIM_3);
timer_clear(TIM_3);
}
2024-03-24 16:07:39 +08:00
}
2024-03-23 17:37:31 +08:00
2024-03-24 18:26:36 +08:00
if (barrier_type == BARRIER_RIGHT_BEGIN) {
track_type = TRACK_LEFT;
if (Lpt1_found) {
Lpt1_found_count++;
}
if (Lpt1_found_count >= 1) {
Lpt1_found_count = 0;
barrier_type = BARRIER_RIGHT_RUNNING;
track_type = TRACK_LEFT;
timer_clear(TIM_3);
timer_start(TIM_3);
}
} else if (barrier_type == BARRIER_RIGHT_RUNNING) {
track_type = TRACK_LEFT;
time_barrier = timer_get(TIM_3);
if (time_barrier >= 5000) {
timer_start(TIM_3);
timer_clear(TIM_3);
barrier_type = BARRIER_NONE;
track_type = TRACK_LEFT;
}
2024-03-24 16:07:39 +08:00
}
2024-03-23 17:37:31 +08:00
}