2023-12-17 16:11:35 +08:00
|
|
|
#include "zf_common_headfile.h"
|
|
|
|
|
#include "gl_headfile.h"
|
2024-03-30 11:43:43 +08:00
|
|
|
#include "jj_blueteeth.h"
|
2024-06-18 16:21:19 +08:00
|
|
|
#include <float.h>
|
2023-12-17 16:11:35 +08:00
|
|
|
float (*mid_track)[2];
|
|
|
|
|
int32_t mid_track_count;
|
2024-03-10 08:35:37 +08:00
|
|
|
float pure_angle;
|
2024-05-27 21:17:40 +08:00
|
|
|
float pure_angle_half;
|
2024-06-18 16:21:19 +08:00
|
|
|
float curvature;
|
2024-03-08 19:58:36 +08:00
|
|
|
float dx_near;
|
2024-06-16 21:52:42 +08:00
|
|
|
float curvature;
|
2024-06-18 16:21:19 +08:00
|
|
|
float last_curvature;
|
2023-12-17 16:11:35 +08:00
|
|
|
float (*rpts)[2];
|
|
|
|
|
int rpts_num;
|
2024-05-24 20:42:56 +08:00
|
|
|
float last_pure_angle = 0.0f;
|
2024-06-16 21:52:42 +08:00
|
|
|
int8_t turn_flag = 0;
|
2024-07-03 16:30:37 +08:00
|
|
|
int circle_flag = 1;
|
2024-05-24 20:42:56 +08:00
|
|
|
// 计算最小二乘法斜率的函数
|
|
|
|
|
float leastSquaresSlope(float points[][2], int n)
|
|
|
|
|
{
|
|
|
|
|
float sum_x = 0;
|
|
|
|
|
float sum_y = 0;
|
|
|
|
|
float sum_xy = 0;
|
|
|
|
|
float sum_x_squared = 0;
|
|
|
|
|
|
|
|
|
|
// 计算各项和
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
sum_x += points[i][1];
|
|
|
|
|
sum_y += points[i][0];
|
|
|
|
|
sum_xy += points[i][1] * points[i][0];
|
|
|
|
|
sum_x_squared += points[i][1] * points[i][1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算斜率
|
|
|
|
|
float numerator = (float)n * sum_xy - sum_x * sum_y;
|
|
|
|
|
float denominator = (float)n * sum_x_squared - sum_x * sum_x;
|
|
|
|
|
|
|
|
|
|
if (denominator == 0) {
|
|
|
|
|
// 避免除以零错误
|
|
|
|
|
printf("Error: denominator is zero.\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float temp = denominator / numerator;
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 16:21:19 +08:00
|
|
|
// 计算曲率的函数
|
|
|
|
|
// 计算曲率的函数
|
|
|
|
|
float calculate_curvature(float x[], float y[], int n)
|
|
|
|
|
{
|
|
|
|
|
float total_curvature = 0.0;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < n - 1; i++) {
|
|
|
|
|
float x1 = x[i - 1], y1 = y[i - 1];
|
|
|
|
|
float x2 = x[i], y2 = y[i];
|
|
|
|
|
float x3 = x[i + 1], y3 = y[i + 1];
|
|
|
|
|
|
|
|
|
|
float dx1 = x2 - x1;
|
|
|
|
|
float dy1 = y2 - y1;
|
|
|
|
|
float dx2 = x3 - x2;
|
|
|
|
|
float dy2 = y3 - y2;
|
|
|
|
|
|
|
|
|
|
float dx = (dx1 + dx2) / 2;
|
|
|
|
|
float dy = (dy1 + dy2) / 2;
|
|
|
|
|
|
|
|
|
|
float ddx = x3 - 2 * x2 + x1;
|
|
|
|
|
float ddy = y3 - 2 * y2 + y1;
|
|
|
|
|
|
|
|
|
|
float numerator = dx * ddy - dy * ddx;
|
|
|
|
|
float denominator = powf(dx * dx + dy * dy, 1.5f);
|
|
|
|
|
|
|
|
|
|
if (fabs(denominator) > FLT_EPSILON) {
|
|
|
|
|
total_curvature += numerator / denominator;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return total_curvature / (float)(n - 2);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 21:52:42 +08:00
|
|
|
float calculateX(float a_x, float a_y, float slope, float b_y)
|
|
|
|
|
{
|
2024-05-24 20:42:56 +08:00
|
|
|
float b_x = a_x - (b_y - a_y) * slope;
|
|
|
|
|
return b_x;
|
|
|
|
|
}
|
2023-12-17 16:11:35 +08:00
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
void tracking()
|
|
|
|
|
{
|
2023-12-17 16:11:35 +08:00
|
|
|
|
|
|
|
|
if (pts_resample_left_count < pts_resample_right_count / 2 && pts_resample_left_count < 50) {
|
2024-03-08 20:58:16 +08:00
|
|
|
track_type = TRACK_RIGHT;
|
|
|
|
|
} else if (pts_resample_right_count < pts_resample_left_count / 2 && pts_resample_right_count < 58) {
|
|
|
|
|
track_type = TRACK_LEFT;
|
|
|
|
|
} else if (pts_resample_left_count < 20 && pts_resample_right_count > pts_resample_left_count) {
|
|
|
|
|
track_type = TRACK_RIGHT;
|
|
|
|
|
} else if (pts_resample_right_count < 20 && pts_resample_left_count > pts_resample_right_count) {
|
|
|
|
|
track_type = TRACK_LEFT;
|
|
|
|
|
}
|
2023-12-17 16:11:35 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-22 20:28:49 +08:00
|
|
|
void aim_distance_select(void)
|
|
|
|
|
{
|
|
|
|
|
if (cross_type != CROSS_NONE) {
|
2024-03-23 16:53:58 +08:00
|
|
|
aim_distance = cross_aim;
|
2024-06-16 21:52:42 +08:00
|
|
|
} else if (circle_type != CIRCLE_NONE) {
|
|
|
|
|
aim_distance = cricle_aim;
|
2024-03-23 17:37:31 +08:00
|
|
|
} else if (barrier_type != BARRIER_NONE) {
|
2024-03-23 18:26:03 +08:00
|
|
|
aim_distance = barrier_aim;
|
2024-03-22 20:28:49 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
void ElementJudge()
|
|
|
|
|
{
|
2024-07-05 14:50:53 +08:00
|
|
|
|
|
|
|
|
if(begin_flag == 1){
|
|
|
|
|
shield_type = SHIELD_BEGIN;
|
|
|
|
|
begin_flag = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 14:16:20 +08:00
|
|
|
if (shield_type == SHIELD_NONE) {
|
2024-07-05 14:12:01 +08:00
|
|
|
CheckGarage();
|
|
|
|
|
if (garage_type == GARAGE_NONE) {
|
|
|
|
|
CheckCross();
|
|
|
|
|
if (cross_type == CROSS_NONE) {
|
|
|
|
|
CheckBarrier();
|
|
|
|
|
if (barrier_type == BARRIER_NONE) {
|
|
|
|
|
CheckCircle();
|
|
|
|
|
if (circle_type == CIRCLE_NONE) {
|
|
|
|
|
Check_s();
|
|
|
|
|
}
|
2024-06-16 21:52:42 +08:00
|
|
|
}
|
2024-03-23 09:43:06 +08:00
|
|
|
}
|
2024-03-08 20:58:16 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-12-17 16:11:35 +08:00
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
if (garage_type != GARAGE_NONE) {
|
2024-07-05 14:12:01 +08:00
|
|
|
cross_type = CROSS_NONE;
|
|
|
|
|
circle_type = CIRCLE_NONE;
|
|
|
|
|
barrier_type = BARRIER_NONE;
|
2023-12-17 16:11:35 +08:00
|
|
|
}
|
2024-03-23 17:37:31 +08:00
|
|
|
if (cross_type != CROSS_NONE) {
|
|
|
|
|
circle_type = CIRCLE_NONE;
|
2024-03-23 09:43:06 +08:00
|
|
|
barrier_type = BARRIER_NONE;
|
2024-03-23 09:15:53 +08:00
|
|
|
}
|
2024-03-23 17:37:31 +08:00
|
|
|
if (barrier_type != BARRIER_NONE) {
|
2024-03-23 09:43:06 +08:00
|
|
|
circle_type = CIRCLE_NONE;
|
|
|
|
|
}
|
2023-12-17 16:11:35 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
void ElementRun()
|
|
|
|
|
{
|
|
|
|
|
if (garage_type != GARAGE_NONE) {
|
|
|
|
|
RunGarage();
|
|
|
|
|
}
|
2023-12-17 16:11:35 +08:00
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
else if (cross_type != CROSS_NONE) {
|
|
|
|
|
RunCross();
|
2024-03-23 17:37:31 +08:00
|
|
|
} else if (barrier_type != BARRIER_NONE) {
|
|
|
|
|
RunBarrier();
|
2024-07-05 14:12:01 +08:00
|
|
|
} else if (circle_type != CIRCLE_NONE) {
|
|
|
|
|
RunCircle();
|
2024-06-16 21:52:42 +08:00
|
|
|
} else if (s_type != S_NONE) {
|
2024-06-18 16:21:19 +08:00
|
|
|
// RunS();
|
2024-03-08 20:58:16 +08:00
|
|
|
}
|
2023-12-17 16:11:35 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
void MidLineTrack()
|
|
|
|
|
{
|
2024-07-05 14:50:53 +08:00
|
|
|
if (shield_type == SHIELD_BEGIN) {
|
|
|
|
|
shield_type = SHIELD_NONE;
|
|
|
|
|
system_delay_ms(1000); // 斑马线发车延时
|
|
|
|
|
}
|
|
|
|
|
else if (cross_type == CROSS_IN) {
|
2024-03-08 20:58:16 +08:00
|
|
|
if (track_type == TRACK_LEFT) {
|
|
|
|
|
mid_track = mid_left; // 这是为了预先分配内存
|
|
|
|
|
GetMidLine_Left(pts_far_resample_left + far_Lpt0_rpts0s_id, pts_far_resample_left_count - far_Lpt0_rpts0s_id, mid_left, (int)round(ANGLEDIST / RESAMPLEDIST), PIXPERMETER * ROADWIDTH / 2);
|
|
|
|
|
mid_track_count = pts_far_resample_left_count - far_Lpt0_rpts0s_id;
|
|
|
|
|
} else {
|
|
|
|
|
mid_track = mid_right; // 这是为了预先分配内存
|
|
|
|
|
GetMidLine_Right(pts_far_resample_right + far_Lpt1_rpts1s_id, pts_far_resample_right_count - far_Lpt1_rpts1s_id, mid_right, (int)round(ANGLEDIST / RESAMPLEDIST), PIXPERMETER * ROADWIDTH / 2);
|
|
|
|
|
mid_track_count = pts_far_resample_right_count - far_Lpt1_rpts1s_id;
|
|
|
|
|
}
|
2024-01-13 18:20:39 +08:00
|
|
|
} else {
|
2024-03-08 20:58:16 +08:00
|
|
|
if (track_type == TRACK_LEFT) {
|
|
|
|
|
mid_track = mid_left;
|
|
|
|
|
mid_track_count = mid_left_count;
|
|
|
|
|
} else {
|
|
|
|
|
mid_track = mid_right;
|
|
|
|
|
mid_track_count = mid_right_count;
|
|
|
|
|
}
|
2024-06-26 17:27:38 +08:00
|
|
|
float x[mid_track_count];
|
|
|
|
|
float y[mid_track_count];
|
2024-06-18 16:21:19 +08:00
|
|
|
|
2024-06-26 17:27:38 +08:00
|
|
|
for (int i = 0; i < mid_track_count; i++) {
|
2024-06-18 16:21:19 +08:00
|
|
|
x[i] = mid_track[i][1];
|
|
|
|
|
y[i] = mid_track[i][0];
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-26 17:27:38 +08:00
|
|
|
if (mid_track_count <= 5) {
|
2024-06-18 16:21:19 +08:00
|
|
|
curvature = last_curvature;
|
|
|
|
|
/* code */
|
|
|
|
|
} else {
|
2024-06-26 17:27:38 +08:00
|
|
|
curvature = calculate_curvature(x, y, mid_track_count);
|
2024-06-18 16:21:19 +08:00
|
|
|
}
|
|
|
|
|
last_curvature = curvature;
|
2023-12-17 16:11:35 +08:00
|
|
|
}
|
2024-03-08 20:58:16 +08:00
|
|
|
|
|
|
|
|
// 车轮对应点 (纯跟踪起始点)
|
2024-05-24 20:42:56 +08:00
|
|
|
float cx = InverseMapW[(int)(IMAGE_H * 0.8f)][70];
|
|
|
|
|
float cy = InverseMapH[(int)(IMAGE_H * 0.8f)][70];
|
|
|
|
|
|
2024-06-18 16:21:19 +08:00
|
|
|
int neary = (int)mid_track[0][0];
|
|
|
|
|
int nearx = (int)mid_track[0][1];
|
2024-03-08 20:58:16 +08:00
|
|
|
|
|
|
|
|
// 找最近点 (起始点中线归一化)
|
|
|
|
|
float min_dist = 1e10;
|
|
|
|
|
|
|
|
|
|
int begin_id = -1;
|
|
|
|
|
for (int i = 0; i < mid_track_count; i++) {
|
|
|
|
|
float dx = mid_track[i][1] - cx;
|
|
|
|
|
float dy = mid_track[i][0] - cy;
|
2024-03-10 20:02:40 +08:00
|
|
|
float dist = Q_sqrt(dx * dx + dy * dy);
|
2024-03-08 20:58:16 +08:00
|
|
|
if (dist < min_dist) {
|
|
|
|
|
min_dist = dist;
|
|
|
|
|
begin_id = i;
|
|
|
|
|
}
|
2023-12-17 16:11:35 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
if (begin_id >= 0 && mid_track_count - begin_id >= 3) {
|
|
|
|
|
// 归一化中线
|
|
|
|
|
mid_track[begin_id][0] = cy;
|
|
|
|
|
mid_track[begin_id][1] = cx;
|
|
|
|
|
rptsn_num = sizeof(rptsn) / sizeof(rptsn[0]);
|
|
|
|
|
GetLinesResample(mid_track + begin_id, mid_track_count - begin_id, rptsn, &rptsn_num, RESAMPLEDIST * PIXPERMETER);
|
|
|
|
|
|
2024-06-18 16:21:19 +08:00
|
|
|
if (cross_type == CROSS_IN) {
|
2024-06-26 17:27:38 +08:00
|
|
|
float x[rptsn_num];
|
|
|
|
|
float y[rptsn_num];
|
2024-06-18 16:21:19 +08:00
|
|
|
|
2024-06-26 17:27:38 +08:00
|
|
|
for (int i = 0; i < rptsn_num; i++) {
|
2024-06-18 16:21:19 +08:00
|
|
|
x[i] = rptsn[i][1];
|
|
|
|
|
y[i] = rptsn[i][0];
|
|
|
|
|
}
|
2024-06-26 17:27:38 +08:00
|
|
|
if (rptsn_num <= 5) {
|
2024-06-18 16:21:19 +08:00
|
|
|
curvature = last_curvature;
|
|
|
|
|
/* code */
|
|
|
|
|
} else {
|
2024-06-26 17:27:38 +08:00
|
|
|
curvature = calculate_curvature(x, y, rptsn_num);
|
2024-06-18 16:21:19 +08:00
|
|
|
}
|
|
|
|
|
last_curvature = curvature;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
// 远预锚点位置-
|
2024-05-24 20:42:56 +08:00
|
|
|
int aim_idx = clip(round(aim_distance / RESAMPLEDIST), 0, rptsn_num - 1);
|
|
|
|
|
int aim_idx_judge = clip(round(aim_judge_far / RESAMPLEDIST), 0, mid_track_count - 1);
|
2024-03-08 20:58:16 +08:00
|
|
|
|
|
|
|
|
// 近锚点位置
|
2024-05-27 21:17:40 +08:00
|
|
|
int aim_idx_near = clip(round(aim_distance / 2 / RESAMPLEDIST), 0, rptsn_num - 1);
|
2024-03-08 20:58:16 +08:00
|
|
|
|
2024-05-24 20:42:56 +08:00
|
|
|
float dx1 = mid_track[3 * (mid_track_count / 4)][1] - mid_track[aim_idx_judge][1];
|
|
|
|
|
float dy1 = mid_track[3 * (mid_track_count / 4)][0] - mid_track[aim_idx_judge][0];
|
2024-06-16 21:52:42 +08:00
|
|
|
float dn1 = Q_sqrt(dx1 * dx1 + dy1 * dy1);
|
2024-05-24 20:42:56 +08:00
|
|
|
float dx2 = mid_track[aim_idx_judge][1] - nearx;
|
|
|
|
|
float dy2 = mid_track[aim_idx_judge][0] - neary;
|
2024-03-30 11:43:43 +08:00
|
|
|
float dn2 = Q_sqrt(dx2 * dx2 + dy2 * dy2);
|
|
|
|
|
float c1 = dx1 / dn1;
|
|
|
|
|
float s1 = dy1 / dn1;
|
|
|
|
|
float c2 = dx2 / dn2;
|
|
|
|
|
float s2 = dy2 / dn2;
|
|
|
|
|
float angle_1 = atan2f(c1 * s2 - c2 * s1, c2 * c1 + s2 * s1);
|
2024-06-16 21:52:42 +08:00
|
|
|
|
2024-05-24 20:42:56 +08:00
|
|
|
if (angle_1 >= 0.2f || angle_1 <= -0.2f) {
|
2024-03-29 10:50:37 +08:00
|
|
|
state_type = TURN_STATE;
|
2024-03-30 11:43:43 +08:00
|
|
|
} else {
|
2024-03-29 10:50:37 +08:00
|
|
|
state_type = STRAIGHT_STATE;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 20:58:16 +08:00
|
|
|
// 计算远锚点偏差值
|
2024-06-16 21:52:42 +08:00
|
|
|
float dx = rptsn[aim_idx][1] - cx;
|
|
|
|
|
float dy = cy - rptsn[aim_idx][0]; // + 0.2f * PIXPERMETER;
|
|
|
|
|
float dn = (dx * dx + dy * dy);
|
2024-05-24 20:42:56 +08:00
|
|
|
float temp_near = 0;
|
2024-07-03 16:30:37 +08:00
|
|
|
|
|
|
|
|
switch (barrier_type) {
|
|
|
|
|
case BARRIER_LEFT_BEGIN:
|
|
|
|
|
// dx_near = mid_track[aim_idx_near][1] - cx + barrier_offset;
|
2024-07-05 14:12:01 +08:00
|
|
|
pure_angle = -atanf(PIXPERMETER * 2.0f * 0.2f * 0.5f * dx / dn) / PI32 * 180.0f - 20;
|
2024-07-03 16:30:37 +08:00
|
|
|
break;
|
|
|
|
|
case BARRIER_LEFT_RUNNING:
|
2024-07-05 14:12:01 +08:00
|
|
|
pure_angle = 15.f;
|
2024-07-03 16:30:37 +08:00
|
|
|
break;
|
|
|
|
|
case BARRIER_RIGHT_BEGIN:
|
2024-07-05 14:12:01 +08:00
|
|
|
pure_angle = -atanf(PIXPERMETER * 2.0f * 0.2f * 0.5f * dx / dn) / PI32 * 180.0f + 20;
|
2024-07-03 16:30:37 +08:00
|
|
|
break;
|
|
|
|
|
case BARRIER_RIGHT_RUNNING:
|
|
|
|
|
// dx_near = mid_track[aim_idx_near][1] - cx - barrier_offset;
|
2024-07-05 14:12:01 +08:00
|
|
|
pure_angle = -15.f;
|
2024-07-03 16:30:37 +08:00
|
|
|
default:
|
|
|
|
|
// pure_angle = -atanf(PIXPERMETER * 2.0f * 0.2f * 0.5f * dx / dn) / PI32 * 180.0f;
|
|
|
|
|
if (dy > 0) {
|
|
|
|
|
pure_angle = -atanf(dx / dy) / PI32 * 180.0f;
|
|
|
|
|
last_pure_angle = pure_angle;
|
|
|
|
|
// last_pure_angle_half = pure_angle_half;
|
|
|
|
|
} else {
|
|
|
|
|
pure_angle = last_pure_angle;
|
|
|
|
|
// pure_angle_half = last_pure_angle_half;
|
|
|
|
|
}
|
2024-03-23 17:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-03 16:30:37 +08:00
|
|
|
// if (barrier_type == BARRIER_LEFT_BEGIN) {
|
|
|
|
|
// // dx_near = mid_track[aim_idx_near][1] - cx + barrier_offset;
|
|
|
|
|
// pure_angle = -25.f;
|
|
|
|
|
// } else if (barrier_type == BARRIER_LEFT_RUNNING) {
|
|
|
|
|
// pure_angle = 25.f;
|
|
|
|
|
// } else if (barrier_type == BARRIER_RIGHT_BEGIN) {
|
|
|
|
|
// pure_angle = 25.f;
|
|
|
|
|
// } else if (barrier_type == BARRIER_RIGHT_RUNNING) {
|
|
|
|
|
// // dx_near = mid_track[aim_idx_near][1] - cx - barrier_offset;
|
|
|
|
|
// pure_angle = -25.f;
|
|
|
|
|
// } else {
|
|
|
|
|
// // pure_angle = -atanf(PIXPERMETER * 2.0f * 0.2f * 0.5f * dx / dn) / PI32 * 180.0f;
|
|
|
|
|
// if (dy > 0) {
|
|
|
|
|
// pure_angle = -atanf(dx / dy) / PI32 * 180.0f;
|
|
|
|
|
// last_pure_angle = pure_angle;
|
|
|
|
|
// // last_pure_angle_half = pure_angle_half;
|
|
|
|
|
// } else {
|
|
|
|
|
// pure_angle = last_pure_angle;
|
|
|
|
|
// // pure_angle_half = last_pure_angle_half;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2024-03-23 17:37:31 +08:00
|
|
|
// // 计算近锚点偏差值
|
|
|
|
|
// dx_near = rptsn[aim_idx_near][1] - cx;
|
|
|
|
|
// // float dy_near = cy - rptsn[aim_idx_near][0] + 0.2 * PIXPERMETER;
|
|
|
|
|
// // float dn_near = Q_sqrt(dx_near * dx_near + dy_near * dy_near);
|
|
|
|
|
// // float error_near = -atan2f(dx_near, dy_near) * 180 / PI32;
|
2024-03-08 20:58:16 +08:00
|
|
|
}
|
2024-06-30 15:55:49 +08:00
|
|
|
|
2024-07-05 14:12:01 +08:00
|
|
|
if (circle_type == CIRCLE_LEFT_IN || circle_type == CIRCLE_RIGHT_IN || circle_type == CIRCLE_LEFT_BEGIN || circle_type == CIRCLE_RIGHT_BEGIN) {
|
2024-05-24 20:42:56 +08:00
|
|
|
state_type = CIRCLE_STATE;
|
2024-06-30 15:55:49 +08:00
|
|
|
timer_clear(TIM_3);
|
|
|
|
|
timer_start(TIM_3);
|
2024-03-30 11:43:43 +08:00
|
|
|
}
|
2024-06-30 15:55:49 +08:00
|
|
|
if (circle_type == CIRCLE_LEFT_RUNNING || circle_type == CIRCLE_RIGHT_RUNNING || circle_type == CIRCLE_RIGHT_OUT || circle_type == CIRCLE_LEFT_OUT || circle_type == CIRCLE_LEFT_END || circle_type == CIRCLE_RIGHT_END) {
|
2024-07-03 16:30:37 +08:00
|
|
|
if (circle_flag == 1) {
|
2024-06-30 15:55:49 +08:00
|
|
|
state_type = CIRCLE_STATE;
|
|
|
|
|
}
|
2024-07-03 16:30:37 +08:00
|
|
|
|
2024-06-30 15:55:49 +08:00
|
|
|
uint16 ti = timer_get(TIM_3);
|
|
|
|
|
if (ti >= 1000) {
|
|
|
|
|
timer_stop(TIM_3);
|
|
|
|
|
timer_clear(TIM_3);
|
2024-07-03 16:30:37 +08:00
|
|
|
|
2024-06-30 15:55:49 +08:00
|
|
|
circle_flag = 0;
|
|
|
|
|
}
|
2024-07-03 16:30:37 +08:00
|
|
|
if (circle_flag == 0) {
|
2024-06-30 15:55:49 +08:00
|
|
|
state_type = CIRCLE_RUNNING_STATE;
|
|
|
|
|
}
|
2024-06-26 17:27:38 +08:00
|
|
|
}
|
2024-06-30 15:55:49 +08:00
|
|
|
|
2024-07-03 16:30:37 +08:00
|
|
|
if (circle_type == CIRCLE_NONE) {
|
2024-06-30 15:55:49 +08:00
|
|
|
circle_flag = 1;
|
2024-06-26 17:27:38 +08:00
|
|
|
}
|
2024-06-30 15:55:49 +08:00
|
|
|
|
|
|
|
|
if (barrier_type == BARRIER_LEFT_BEGIN || barrier_type == BARRIER_LEFT_RUNNING || barrier_type == BARRIER_RIGHT_BEGIN || barrier_type == BARRIER_RIGHT_RUNNING) {
|
|
|
|
|
state_type = BARRIER_STATE;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 20:42:56 +08:00
|
|
|
if (cross_type == CROSS_BEGIN || cross_type == CROSS_IN) {
|
2024-04-03 16:20:56 +08:00
|
|
|
state_type = STRAIGHT_STATE;
|
|
|
|
|
}
|
2024-06-30 15:55:49 +08:00
|
|
|
// last_state = state_type;
|
2024-06-16 21:52:42 +08:00
|
|
|
if (state_type == STRAIGHT_STATE) {
|
|
|
|
|
aim_distance = straight_aim;
|
|
|
|
|
} else if (state_type == TURN_STATE) {
|
|
|
|
|
aim_distance = turn_aim;
|
|
|
|
|
}
|
2024-06-30 15:55:49 +08:00
|
|
|
|
|
|
|
|
// if (last_state == STRAIGHT_STATE && (state_type == TURN_STATE || state_type == CIRCLE_STATE)) {
|
|
|
|
|
// turn_flag = 1;
|
|
|
|
|
// timer_clear(TIM_3);
|
|
|
|
|
// timer_start(TIM_3);
|
|
|
|
|
// }
|
|
|
|
|
// if (turn_flag == 1) {
|
|
|
|
|
// aim_distance = turn_aim;
|
|
|
|
|
|
|
|
|
|
// uint16 ti = timer_get(TIM_3);
|
|
|
|
|
// if (ti >= 2000) {
|
|
|
|
|
// turn_flag = 0;
|
|
|
|
|
// timer_stop(TIM_3);
|
|
|
|
|
// timer_clear(TIM_3);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-03-08 20:58:16 +08:00
|
|
|
}
|