From eca0d277522ad557c7d48fbe9e8ad3440b8a0c24 Mon Sep 17 00:00:00 2001 From: Glz <354338225@qq.com> Date: Sun, 24 Dec 2023 22:24:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=9B=BE=E5=83=8F=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 10 +++---- app/gl_common.h | 4 +-- app/main.c | 73 +++++++++++++++++++++++++++++++-------------- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d4d5714..a467a37 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,13 +5,13 @@ "cwd": "${workspaceRoot}", "type": "cortex-debug", "request": "launch", - "name": "jlink", - "servertype": "jlink", - "interface": "swd", + "name": "openocd", + "servertype": "openocd", "executable": "build\\Debug\\violet_firmware_zf.elf", "runToEntryPoint": "main", - "device": "null", - "toolchainPrefix": "riscv-none-embed" + "configFiles": [ + "${workspaceFolder}/tools/wch-riscv.cfg" + ] } ] } \ No newline at end of file diff --git a/app/gl_common.h b/app/gl_common.h index 1bd003a..b0e2789 100644 --- a/app/gl_common.h +++ b/app/gl_common.h @@ -5,8 +5,8 @@ #define IMAGE_H (MT9V03X_H) #define IMAGE_W (MT9V03X_W) -#define BEGINH_L (61) -#define BEGINH_R (61) +#define BEGINH_L (80) +#define BEGINH_R (80) #define BEGINW_L (-18) #define BEGINW_R (-12) #define PT_MAXLEN (75) diff --git a/app/main.c b/app/main.c index 3b0d909..2d99b74 100644 --- a/app/main.c +++ b/app/main.c @@ -89,23 +89,29 @@ int frame_count = 0; void img_processing(); void get_corners(); +void adaptiveThreshold(uint8_t* img_data, uint8_t* output_data, int width, int height, int block, uint8_t clip_value); + + int main(void) { clock_init(SYSTEM_CLOCK_120M); // 初始化芯片时钟 工作频率为 120MHz debug_init(); // 务必保留,本函数用于初始化 MPU 时钟 调试串口 - // mt9v03x_init(); + //mt9v03x_init(); + // system_delay_ms(2000); ips200_init(IPS200_TYPE_SPI); - by_gpio_init(); - by_exit_init(); - by_pwm_init(); - cw_servo_init(); - while (imu660ra_init()) - ; + mt9v03x_init(); + // by_gpio_init(); + // by_exit_init(); + // by_pwm_init(); + // cw_servo_init(); + //printf("hello world\n"); + // while (imu660ra_init()) + // ; - system_delay_ms(2000); - gyroOffset_init(); - pit_ms_init(TIM6_PIT, 2); + // system_delay_ms(2000); + // gyroOffset_init(); + // pit_ms_init(TIM6_PIT, 2); while (1) { // while (frame_count < 20) { @@ -113,36 +119,57 @@ int main(void) // memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t))); // adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 8); // //threshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, MT9V03X_W, MT9V03X_H, 110); - // ips114_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); + // ips200_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); // mt9v03x_finish_flag = 0; // frame_count++; // } //} if (mt9v03x_finish_flag) { - // ips114_show_gray_image(0, 0, mt9v03x_image[0], 188, 120, 188, 120,0); memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t))); - // Img_Gray = mt9v03x_image; - // mt9v03x_image_copy[0] = Img_Gray[0]; + adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 17); + ips200_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); mt9v03x_finish_flag = 0; state_type = COMMON_STATE; img_processing(); - get_corners(); + //get_corners(); - aim_distance = COMMON_AIM; + //aim_distance = COMMON_AIM; - tracking(); + //tracking(); + //printf("1\r\n"); + //system_delay_ms(100); - ElementJudge(); + //ElementJudge(); - ElementRun(); + //ElementRun(); - MidLineTrack(); + //MidLineTrack(); } - // by_imu_data_get(); - by_ips_show(); - system_delay_ms(200); + // // by_imu_data_get(); + // // by_ips_show(); + // // system_delay_ms(200); } +} + + + +void adaptiveThreshold(uint8_t* img_data, uint8_t* output_data, int width, int height, int block, uint8_t clip_value){ + int half_block = block / 2; + for(int y=half_block; ythres ? 255 : 0; + } + } } \ No newline at end of file