Files
QDAC-firmware/app/gl_barrier.c

115 lines
2.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-06-16 21:52:42 +08:00
enum s_type_e s_type = S_NONE;
2024-03-24 18:26:36 +08:00
uint16 time_barrier;
2024-06-16 21:52:42 +08:00
float (*mid_track_s)[2];
int32_t mid_track_count_s;
int temp_min_s;
int temp_max_s;
2024-03-24 18:26:36 +08:00
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++;
}
2024-03-30 11:43:43 +08:00
if (Lpt0_found_count >= 1) {
2024-03-24 18:26:36 +08:00
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);
2024-06-26 17:27:38 +08:00
if (time_barrier >= 220) {
2024-03-24 18:26:36 +08:00
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);
2024-06-26 17:27:38 +08:00
if (time_barrier >= 220) {
2024-03-24 18:26:36 +08:00
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
}
2024-06-16 21:52:42 +08:00
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;
}
}