Files
QDAC-firmware/app/gl_barrier.c
2024-06-26 17:27:38 +08:00

115 lines
2.9 KiB
C

#include "zf_common_headfile.h"
#include "gl_headfile.h"
enum barrier_type_e barrier_type = BARRIER_NONE;
enum s_type_e s_type = S_NONE;
uint16 time_barrier;
float (*mid_track_s)[2];
int32_t mid_track_count_s;
int temp_min_s;
int temp_max_s;
void CheckBarrier()
{
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;
}
}
void RunBarrier()
{
if (barrier_type == BARRIER_LEFT_BEGIN) {
track_type = TRACK_RIGHT;
if (Lpt0_found) {
Lpt0_found_count++;
}
if (Lpt0_found_count >= 1) {
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 >= 220) {
barrier_type = BARRIER_NONE;
track_type = TRACK_RIGHT;
timer_start(TIM_3);
timer_clear(TIM_3);
}
}
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 >= 220) {
timer_start(TIM_3);
timer_clear(TIM_3);
barrier_type = BARRIER_NONE;
track_type = TRACK_LEFT;
}
}
}
void Check_s(){
if (track_type == TRACK_LEFT) {
mid_track_s = mid_left;
mid_track_count_s = mid_left_count;
} else {
mid_track_s = mid_right;
mid_track_count_s = mid_right_count;
}
int min_s = 1000;
int max_s = 1;
for (int i = 0; i < mid_track_count_s; i++)
{
if (mid_track_s[i][1] < min_s)
{
min_s = mid_track_s[i][1];
temp_min_s = min_s;
}
if (mid_track_s[i][1] > max_s)
{
max_s = mid_track_s[i][1];
temp_max_s = max_s;
}
}
if (is_straight0 == false && is_straight1 == false && (max_s - min_s) <= 30 && (max_s - min_s) >= 5)
{
s_type = S_BEGIN;
}
}
void RunS(){
if (temp_max_s - temp_min_s >30 || (is_straight0 && is_straight1))
{
s_type = S_NONE;
}
}