Files
QDAC-firmware/app/gl_barrier.c

170 lines
5.1 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-07-03 16:30:37 +08:00
enum s_type_e s_type = S_NONE;
2024-07-05 14:16:20 +08:00
enum shield_type_e shield_type = SHIELD_NONE;
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-07-02 16:56:43 +08:00
int barrier_begin_flag = 0;
2024-07-05 14:12:01 +08:00
int barrier_count = 0;
2024-06-16 21:52:42 +08:00
2024-03-24 18:26:36 +08:00
void CheckBarrier()
{
2024-07-05 14:12:01 +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-23 09:43:06 +08:00
}
2024-03-24 18:26:36 +08:00
void RunBarrier()
{
if (barrier_type == BARRIER_LEFT_BEGIN) {
track_type = TRACK_RIGHT;
2024-07-05 14:12:01 +08:00
// if (barrier_begin_flag == 0) {
// timer_clear(TIM_3);
// timer_start(TIM_3);
// barrier_begin_flag = 1;
// }
// }
// if (barrier_type == BARRIER_LEFT_BEGIN || barrier_type == BARRIER_LEFT_RUNNING) {
// if (barrier_begin_flag == 1) {
// barrier_type = BARRIER_LEFT_BEGIN;
// time_barrier = timer_get(TIM_3);
// if (time_barrier >= 300 && time_barrier < 600) {
// barrier_type = BARRIER_LEFT_RUNNING;
// } else if (time_barrier >= 600) {
// barrier_type = BARRIER_NONE;
// barrier_count = 1;
// barrier_begin_flag = 0;
// timer_stop(TIM_3);
// timer_clear(TIM_3);
// }
// }
// }
if (Lpt0_found) {
Lpt0_found_count++;
2024-03-24 18:26:36 +08:00
}
2024-07-05 14:12:01 +08:00
if (Lpt0_found_count >= 1 && barrier_type == BARRIER_LEFT_BEGIN) {
Lpt0_found_count = 0;
barrier_type = BARRIER_LEFT_RUNNING;
track_type = TRACK_RIGHT;
timer_clear(TIM_1);
timer_start(TIM_1);
} else if (barrier_type == BARRIER_LEFT_RUNNING) {
track_type = TRACK_RIGHT;
if (timer_get(TIM_1) >= 220) {
barrier_type = BARRIER_NONE;
track_type = TRACK_RIGHT;
timer_stop(TIM_1);
timer_clear(TIM_1);
2024-07-02 16:56:43 +08:00
}
2024-03-24 18:26:36 +08:00
}
2024-07-03 16:30:37 +08:00
}
2024-03-24 18:26:36 +08:00
if (barrier_type == BARRIER_RIGHT_BEGIN) {
track_type = TRACK_LEFT;
2024-07-05 14:12:01 +08:00
// if (barrier_begin_flag == 0) {
// timer_clear(TIM_3);
// timer_start(TIM_3);
// barrier_begin_flag = 1;
// }
// }
// if (barrier_type == BARRIER_RIGHT_BEGIN || barrier_type == BARRIER_RIGHT_RUNNING) {
// if (barrier_begin_flag == 1) {
// barrier_type = BARRIER_RIGHT_BEGIN;
// time_barrier = timer_get(TIM_3);
// if (time_barrier >= 300 && time_barrier < 600) {
// barrier_type = BARRIER_RIGHT_RUNNING;
// } else if (time_barrier >= 600) {
// barrier_type = BARRIER_NONE;
// barrier_count = 1;
// barrier_begin_flag = 0;
// timer_stop(TIM_3);
// timer_clear(TIM_3);
// }
// }
// }
if (Lpt1_found) {
Lpt1_found_count++;
2024-03-24 18:26:36 +08:00
}
2024-07-05 14:12:01 +08:00
if (Lpt1_found_count >= 1 && barrier_type == BARRIER_RIGHT_BEGIN) {
Lpt1_found_count = 0;
barrier_type = BARRIER_RIGHT_RUNNING;
track_type = TRACK_LEFT;
timer_clear(TIM_1);
timer_start(TIM_1);
} else if (barrier_type == BARRIER_RIGHT_RUNNING) {
track_type = TRACK_LEFT;
if (timer_get(TIM_1) >= 220) {
timer_stop(TIM_1);
timer_clear(TIM_1);
barrier_type = BARRIER_NONE;
track_type = TRACK_LEFT;
2024-07-02 16:56:43 +08:00
}
2024-03-24 18:26:36 +08:00
}
2024-07-03 16:30:37 +08:00
}
2024-03-23 17:37:31 +08:00
}
2024-06-16 21:52:42 +08:00
2024-07-03 16:30:37 +08:00
void Check_s()
{
2024-06-16 21:52:42 +08:00
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;
2024-07-03 16:30:37 +08:00
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];
2024-06-16 21:52:42 +08:00
temp_min_s = min_s;
}
2024-07-03 16:30:37 +08:00
if (mid_track_s[i][1] > max_s) {
max_s = mid_track_s[i][1];
2024-06-16 21:52:42 +08:00
temp_max_s = max_s;
}
}
2024-07-03 16:30:37 +08:00
if (is_straight0 == false && is_straight1 == false && (max_s - min_s) <= 30 && (max_s - min_s) >= 5) {
2024-06-16 21:52:42 +08:00
s_type = S_BEGIN;
}
}
2024-07-03 16:30:37 +08:00
void RunS()
{
2024-06-16 21:52:42 +08:00
2024-07-03 16:30:37 +08:00
if (temp_max_s - temp_min_s > 30 || (is_straight0 && is_straight1)) {
2024-06-16 21:52:42 +08:00
s_type = S_NONE;
}
2024-07-05 14:12:01 +08:00
}
2024-07-05 14:16:20 +08:00
void Check_shield(){
2024-07-05 14:12:01 +08:00
if (begin_flag == 1)
{
2024-07-05 14:16:20 +08:00
shield_type = SHIELD_BEGIN;
2024-07-05 14:12:01 +08:00
timer_clear(TIM_3);
timer_start(TIM_3);
begin_flag = 0;
}
2024-07-05 14:16:20 +08:00
if (timer_get(TIM_3) > 1000 && shield_type == SHIELD_BEGIN)
2024-07-05 14:12:01 +08:00
{
2024-07-05 14:16:20 +08:00
shield_type = SHIELD_NONE;
2024-07-05 14:12:01 +08:00
timer_stop(TIM_3);
timer_clear(TIM_3);
}
2024-06-16 21:52:42 +08:00
}