2023-12-11 21:45:06 +08:00
|
|
|
|
/*********************************************************************************************************************
|
2024-01-04 22:07:13 +08:00
|
|
|
|
* CH32V307VCT6 Opensourec Library 即(CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
|
|
|
|
|
|
* Copyright (c) 2022 SEEKFREE 逐飞科技
|
|
|
|
|
|
*
|
|
|
|
|
|
* 本文件是 CH32V307VCT6 开源库的一部分
|
|
|
|
|
|
*
|
|
|
|
|
|
* CH32V307VCT6 开源库 是免费软件
|
|
|
|
|
|
* 您可以根据自由软件基金会发布的 GPL(GNU General Public License,即 GNU 通用公共许可证)的条款
|
|
|
|
|
|
* 即 GPL 的第 3 版(即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它
|
|
|
|
|
|
*
|
|
|
|
|
|
* 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证
|
|
|
|
|
|
* 甚至没有隐含的适销性或适合特定用途的保证
|
|
|
|
|
|
* 更多细节请参见 GPL
|
|
|
|
|
|
*
|
|
|
|
|
|
* 您应该在收到本开源库的同时收到一份 GPL 的副本
|
|
|
|
|
|
* 如果没有,请参阅<https://www.gnu.org/licenses/>
|
|
|
|
|
|
*
|
|
|
|
|
|
* 额外注明:
|
|
|
|
|
|
* 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本
|
|
|
|
|
|
* 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中
|
|
|
|
|
|
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
|
|
|
|
|
|
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
|
|
|
|
|
|
********************************************************************************************************************/
|
2023-12-11 21:45:06 +08:00
|
|
|
|
#include "zf_common_headfile.h"
|
2023-12-17 16:11:35 +08:00
|
|
|
|
#include "gl_headfile.h"
|
2024-01-04 22:07:13 +08:00
|
|
|
|
#include "by_rt_button.h"
|
2023-12-15 21:42:43 +08:00
|
|
|
|
#include "by_fan_control.h"
|
2023-12-21 22:33:36 +08:00
|
|
|
|
#include "cw_servo.h"
|
|
|
|
|
|
#include "./page/cw_page.h"
|
|
|
|
|
|
|
2023-12-24 22:21:15 +08:00
|
|
|
|
uint8_t (*Img_Gray)[MT9V03X_W];
|
|
|
|
|
|
// uint8_t *mt9v03x_image_copy[0];
|
|
|
|
|
|
int32_t pts_left[PT_MAXLEN][2];
|
|
|
|
|
|
int32_t pts_right[PT_MAXLEN][2];
|
2023-12-21 22:33:36 +08:00
|
|
|
|
int32_t pts_left_count, pts_right_count;
|
|
|
|
|
|
float pts_inv_l[PT_MAXLEN][2], pts_inv_r[PT_MAXLEN][2];
|
|
|
|
|
|
int32_t pts_inv_l_count, pts_inv_r_count;
|
|
|
|
|
|
float pts_filter_l[PT_MAXLEN][2], pts_filter_r[PT_MAXLEN][2];
|
|
|
|
|
|
int32_t pts_filter_l_count, pts_filter_r_count;
|
|
|
|
|
|
float pts_resample_left[PT_MAXLEN][2], pts_resample_right[PT_MAXLEN][2];
|
|
|
|
|
|
int32_t pts_resample_left_count, pts_resample_right_count;
|
|
|
|
|
|
float mid_left[PT_MAXLEN][2], mid_right[PT_MAXLEN][2];
|
|
|
|
|
|
int32_t mid_left_count, mid_right_count;
|
|
|
|
|
|
|
2023-12-17 16:11:35 +08:00
|
|
|
|
float angle_new_left[PT_MAXLEN];
|
|
|
|
|
|
float angle_new_right[PT_MAXLEN];
|
|
|
|
|
|
int angle_new_left_num, angle_new_right_num;
|
|
|
|
|
|
uint8_t mt9v03x_image_copy[MT9V03X_H][MT9V03X_W];
|
|
|
|
|
|
|
|
|
|
|
|
float angle_left[PT_MAXLEN];
|
|
|
|
|
|
float angle_right[PT_MAXLEN];
|
|
|
|
|
|
int angle_left_num, angle_right_num;
|
|
|
|
|
|
|
|
|
|
|
|
int Lpt0_rpts0s_id, Lpt1_rpts1s_id;
|
|
|
|
|
|
bool Lpt0_found, Lpt1_found;
|
2023-12-21 22:33:36 +08:00
|
|
|
|
int Lpt1[2], Lpt0[2];
|
2023-12-17 16:11:35 +08:00
|
|
|
|
|
|
|
|
|
|
int Lpt_in0_rpts0s_id, Lpt_in1_rpts1s_id;
|
|
|
|
|
|
bool Lpt_in0_found, Lpt_in1_found;
|
|
|
|
|
|
int Lpt_in1[2], Lpt_in0[2];
|
|
|
|
|
|
|
|
|
|
|
|
bool is_straight0, is_straight1;
|
|
|
|
|
|
|
|
|
|
|
|
bool is_turn0, is_turn1;
|
|
|
|
|
|
|
|
|
|
|
|
float rptsn[PT_MAXLEN][2];
|
|
|
|
|
|
int rptsn_num;
|
|
|
|
|
|
float aim_distance;
|
|
|
|
|
|
|
|
|
|
|
|
enum track_type_e track_type = TRACK_RIGHT;
|
|
|
|
|
|
|
|
|
|
|
|
int frame_count = 0;
|
|
|
|
|
|
|
2024-01-04 22:07:13 +08:00
|
|
|
|
uint16_t pwm_cnt = 500;
|
|
|
|
|
|
|
2023-12-17 16:11:35 +08:00
|
|
|
|
void img_processing();
|
|
|
|
|
|
void get_corners();
|
2023-12-17 16:23:13 +08:00
|
|
|
|
|
2023-12-16 11:31:25 +08:00
|
|
|
|
int main(void)
|
2023-12-11 21:45:06 +08:00
|
|
|
|
{
|
2023-12-24 22:21:15 +08:00
|
|
|
|
clock_init(SYSTEM_CLOCK_120M);
|
|
|
|
|
|
debug_init();
|
2023-12-11 21:45:06 +08:00
|
|
|
|
mt9v03x_init();
|
2024-01-04 22:07:13 +08:00
|
|
|
|
pwm_init(TIM2_PWM_MAP0_CH1_A0, 50, 1000);
|
|
|
|
|
|
pwm_init(TIM2_PWM_MAP0_CH2_A1, 50, 1000);
|
2023-12-21 22:33:36 +08:00
|
|
|
|
ips200_init(IPS200_TYPE_SPI);
|
2023-12-13 21:54:20 +08:00
|
|
|
|
by_gpio_init();
|
|
|
|
|
|
by_exit_init();
|
2023-12-15 21:42:43 +08:00
|
|
|
|
by_pwm_init();
|
2024-01-04 22:07:13 +08:00
|
|
|
|
// cw_servo_init();
|
2023-12-24 22:21:15 +08:00
|
|
|
|
// while (imu660ra_init())
|
|
|
|
|
|
// ;
|
2023-12-16 11:31:25 +08:00
|
|
|
|
|
2023-12-21 22:33:36 +08:00
|
|
|
|
Page_Init();
|
2023-12-17 16:11:35 +08:00
|
|
|
|
|
2023-12-21 22:33:36 +08:00
|
|
|
|
while (1) {
|
2024-01-04 22:07:13 +08:00
|
|
|
|
// ips200_show_uint(0, 0, pwm_cnt, 6);
|
|
|
|
|
|
// uint8_t temp_status = by_get_rb_status();
|
|
|
|
|
|
// if (2 == temp_status) {
|
|
|
|
|
|
// pwm_cnt += 50;
|
|
|
|
|
|
// } else if (3 == temp_status) {
|
|
|
|
|
|
// pwm_cnt -= 50;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// pwm_cnt = (uint16_t)clip(pwm_cnt, 500, 1000);
|
|
|
|
|
|
// by_pwm_update_duty(4000);
|
|
|
|
|
|
// pwm_set_duty(TIM2_PWM_MAP0_CH1_A0, pwm_cnt);
|
|
|
|
|
|
// pwm_set_duty(TIM2_PWM_MAP0_CH2_A1, pwm_cnt);
|
|
|
|
|
|
|
|
|
|
|
|
// by_pwm_update_duty(pwm_cnt);
|
|
|
|
|
|
|
2023-12-21 22:33:36 +08:00
|
|
|
|
Page_Run();
|
2024-01-04 22:07:13 +08:00
|
|
|
|
|
2023-12-17 16:11:35 +08:00
|
|
|
|
if (mt9v03x_finish_flag) {
|
2023-12-21 22:33:36 +08:00
|
|
|
|
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
2023-12-17 16:11:35 +08:00
|
|
|
|
mt9v03x_finish_flag = 0;
|
|
|
|
|
|
|
|
|
|
|
|
state_type = COMMON_STATE;
|
|
|
|
|
|
img_processing();
|
|
|
|
|
|
get_corners();
|
|
|
|
|
|
aim_distance = COMMON_AIM;
|
|
|
|
|
|
tracking();
|
|
|
|
|
|
ElementJudge();
|
|
|
|
|
|
ElementRun();
|
|
|
|
|
|
MidLineTrack();
|
2023-12-11 21:45:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-12-17 16:23:13 +08:00
|
|
|
|
}
|