Files
QDAC-firmware/app/gl_get_corners.c

161 lines
6.7 KiB
C
Raw Permalink Normal View History

#include "zf_common_headfile.h"
#include "math.h"
#include "gl_headfile.h"
2024-03-26 22:40:44 +08:00
void get_corners()
{
Lpt0_found = Lpt1_found = false;
Lpt_in0_found = Lpt_in1_found = false;
2024-05-24 20:42:56 +08:00
is_straight0 = pts_resample_left_count > 0.8 / RESAMPLEDIST;
is_straight1 = pts_resample_right_count > 0.8 / RESAMPLEDIST;
2024-03-29 10:50:37 +08:00
// is_turn0_l = is_turn1_l = is_turn0_r = is_turn1_r = 0;
for (int i = 0; i < pts_resample_left_count; i++) {
if (angle_new_left[i] == 0) continue;
2024-03-26 22:40:44 +08:00
int im1 = clip(i - (int)round(ANGLEDIST / RESAMPLEDIST), 0, pts_resample_left_count - 1);
int ip1 = clip(i + (int)round(ANGLEDIST / RESAMPLEDIST), 0, pts_resample_left_count - 1);
float conf = fabs(angle_left[i]) - (fabs(angle_left[im1]) + fabs(angle_left[ip1])) / 2;
2024-03-28 19:57:17 +08:00
// 114_show_float(120, 80, conf, 3, 4);
// L 角点阈值
if (Lpt0_found == false && (66. / 180. * PI32) < conf && conf < (140. / 180. * PI32) && i < 0.5 / RESAMPLEDIST)
{
Lpt0_rpts0s_id = i;
2024-03-26 22:40:44 +08:00
Lpt0_found = true;
2024-03-22 20:28:49 +08:00
// transform(pts_resample_left[Lpt0_rpts0s_id][1],pts_resample_left[Lpt0_rpts0s_id][0],&Lpt0[1],&Lpt0[0]); //待优化,是否用到,无用则删
}
2024-03-26 22:40:44 +08:00
// 长直道阈值
2024-03-29 10:50:37 +08:00
if (conf > (6. / 180. * PI32) && i < 0.8 / RESAMPLEDIST) {
2024-03-26 22:40:44 +08:00
is_straight0 = false;
}
if (Lpt0_found == true && is_straight0 == false) break;
}
2024-03-22 20:28:49 +08:00
2024-03-29 10:50:37 +08:00
// if (Lpt0_found == false)
// {
// // is_turn0 = is_curve(angle_left ,clip(angle_left_num - 10, 0,angle_left_num),0.05);
// int gap = 0;
// gap = pts_resample_left[clip(pts_resample_left_count - 30, 0, pts_resample_left_count - 1)][1] - pts_resample_left[0][1];
// ips200_show_uint(200, 205, gap, 3);
// if (gap <= -10)
// {
// is_turn0_l = true;
// }
// if (gap >= 10)
// {
// is_turn1_l = true;
// }
// }
2024-03-27 16:20:49 +08:00
//if (is_turn0)
//{
2024-03-28 19:57:17 +08:00
// state_type = TURN_LEFT_STATE;
2024-03-27 16:20:49 +08:00
//}
2024-03-22 20:28:49 +08:00
Lpt0_found_barrier = Lpt1_found_barrier = false;
2024-03-23 09:43:06 +08:00
Lpt0_found_barrier_in = Lpt1_found_barrier_in = false;
2024-03-22 20:28:49 +08:00
for (int i = 0; i < pts_resample_left_count; i++) {
if (angle_new_left_barrier[i] == 0) continue;
2024-03-26 22:40:44 +08:00
int im1 = clip(i - (int)round(ANGLEDIST_barrier / RESAMPLEDIST), 0, pts_resample_left_count - 1);
int ip1 = clip(i + (int)round(ANGLEDIST_barrier / RESAMPLEDIST), 0, pts_resample_left_count - 1);
float conf = fabs(angle_left_barrier[i]) - (fabs(angle_left_barrier[im1]) + fabs(angle_left_barrier[ip1])) / 2;
2024-03-22 20:28:49 +08:00
2024-03-26 22:40:44 +08:00
// L 角点阈值
2024-07-03 16:30:37 +08:00
if (Lpt0_found_barrier == false && (40. / 180. * PI32) < conf && conf < (160. / 180. * PI32) && i < 0.6 / RESAMPLEDIST) {
2024-03-22 20:28:49 +08:00
Lpt0_rpts0s_id_barrier = i;
2024-07-03 16:37:53 +08:00
if (pts_resample_left[i][1] <= pts_resample_left[clip(i + 2, 0, pts_resample_left_count - 1)][1])
{
Lpt0_found_barrier = true;
}
else{
Lpt0_found_barrier = false;
}
//Lpt0_found_barrier = true;
2024-03-22 20:28:49 +08:00
}
}
2024-03-26 22:40:44 +08:00
if (Lpt0_found_barrier) {
float angle1 = calculate_vector_angle(pts_resample_left[Lpt0_rpts0s_id_barrier][1], pts_resample_left[Lpt0_rpts0s_id_barrier][0], pts_resample_left[Lpt0_rpts0s_id_barrier + 5][1], pts_resample_left[Lpt0_rpts0s_id_barrier + 5][0]);
if (angle1 < 85.) {
Lpt0_found_barrier_in = true;
Lpt0_found_barrier = false;
Lpt0_found_barrier_in_id = Lpt0_rpts0s_id_barrier;
}
}
2024-03-22 20:28:49 +08:00
2024-07-03 16:37:53 +08:00
for (int i = 0; i < pts_resample_right_count; i++) {
if (angle_new_right[i] == 0) continue;
2024-03-26 22:40:44 +08:00
int im1 = clip(i - (int)round(ANGLEDIST / RESAMPLEDIST), 0, pts_resample_right_count - 1);
int ip1 = clip(i + (int)round(ANGLEDIST / RESAMPLEDIST), 0, pts_resample_right_count - 1);
float conf = fabs(angle_right[i]) - (fabs(angle_right[im1]) + fabs(angle_right[ip1])) / 2;
2024-03-29 10:50:37 +08:00
// ips114_show_float(100, 100, conf, 3, 4);
2024-03-10 19:47:21 +08:00
if (Lpt1_found == false && (66. / 180. * PI32) < conf && conf < 140. / 180. * PI32 && i < 0.5 / RESAMPLEDIST) {
Lpt1_rpts1s_id = i;
2024-03-26 22:40:44 +08:00
Lpt1_found = true;
2024-03-22 20:28:49 +08:00
// transform(pts_resample_right[Lpt1_rpts1s_id][1],pts_resample_right[Lpt1_rpts1s_id][0],&Lpt1[1],&Lpt1[0]);
}
2024-03-29 10:50:37 +08:00
if (conf > (6. / 180. * PI32) && i < 0.8 / RESAMPLEDIST) is_straight1 = false;
if (Lpt1_found == true && is_straight1 == false) break;
}
2024-03-22 20:28:49 +08:00
2024-03-29 10:50:37 +08:00
// if(is_straight1 && is_straight0){
// state_type = STRAIGHT_STATE;
// }
2024-03-26 22:43:52 +08:00
2024-03-29 10:50:37 +08:00
// if (Lpt1_found == false)
// {
// // is_turn1 = is_curve(angle_right ,clip(angle_right_num - 10, 0,angle_right_num),0.05);
// int gap = 0;
// gap = pts_resample_right[clip(pts_resample_right_count - 30, 0, pts_resample_right_count - 1)][1] - pts_resample_right[0][1];
// ips200_show_uint(200, 224, gap, 3);
// if (gap <= -10)
// {
// is_turn1_l = true;
// }
// if (gap >= 10)
// {
// is_turn1_r = true;
// }
// }
2024-03-22 20:28:49 +08:00
for (int i = 0; i < pts_resample_right_count; i++) {
if (angle_new_right_barrier[i] == 0) continue;
2024-03-26 22:40:44 +08:00
int im1 = clip(i - (int)round(ANGLEDIST_barrier / RESAMPLEDIST), 0, pts_resample_right_count - 1);
int ip1 = clip(i + (int)round(ANGLEDIST_barrier / RESAMPLEDIST), 0, pts_resample_right_count - 1);
float conf = fabs(angle_right_barrier[i]) - (fabs(angle_right_barrier[im1]) + fabs(angle_right_barrier[ip1])) / 2;
2024-03-22 20:28:49 +08:00
2024-07-03 16:30:37 +08:00
if (Lpt1_found_barrier == false && (40. / 180. * PI32) < conf && conf < 160. / 180. * PI32 && i < 0.6 / RESAMPLEDIST) {
2024-03-22 20:28:49 +08:00
Lpt1_rpts1s_id_barrier = i;
2024-07-03 16:37:53 +08:00
if (pts_resample_right[i][1] >= pts_resample_right[clip(i + 2, 0, pts_resample_left_count - 1)][1])
{
Lpt1_found_barrier = true;
}
else{
Lpt1_found_barrier = false;
}
//Lpt1_found_barrier = true;
2024-03-22 20:28:49 +08:00
}
}
2024-03-26 22:40:44 +08:00
if (Lpt1_found_barrier) {
float angle2 = calculate_vector_angle(pts_resample_right[Lpt1_rpts1s_id_barrier][1], pts_resample_right[Lpt1_rpts1s_id_barrier][0], pts_resample_right[Lpt1_rpts1s_id_barrier + 5][1], pts_resample_right[Lpt1_rpts1s_id_barrier + 5][0]);
if (angle2 > 100.) {
Lpt1_found_barrier_in = true;
Lpt1_found_barrier = false;
Lpt1_found_barrier_in_id = Lpt1_rpts1s_id_barrier;
}
}
2024-03-26 21:39:39 +08:00
2024-03-29 10:50:37 +08:00
// if (is_turn0_l && is_turn1_l)
// {
// state_type = TURN_LEFT_STATE;
// }
// if (is_turn0_r && is_turn1_r)
// {
// state_type = TURN_RIGHT_STATE;
// }
}