"..\source\Appliciation\Telltales_user.c", line 215: error #20: identifier "CAN_MSGStatus" is undefined CAN_MSGStatus = CAN_MSG_Status(&CAN_CH4_CanMsgOp, CAN_CH4_ID_ABS4_0x261_Msg_Count);

时间: 2025-08-01 17:19:33 浏览: 10
<think>我们正在解决一个编译错误:`#20: identifier 'CAN_MSGStatus' is undefined`。这个错误表明编译器在当前位置无法识别`CAN_MSGStatus`这个标识符。根据引用[1][2][3],这类错误通常有以下几个原因和解决方法: ### 原因分析 1. **头文件未包含**:可能没有包含定义`CAN_MSGStatus`的头文件。 2. **头文件包含顺序问题**:可能存在头文件之间的依赖关系,导致某些定义未被正确包含。 3. **使用特定外设库时的特殊包含方式**:如引用[2][3]所述,使用STM32 HAL库时,直接包含外设头文件(如`stm32f1xx_hal_can.h`)可能不如包含顶层头文件(如`stm32f1xx_hal.h`)可靠。 ### 解决步骤 #### 步骤1: 确认标识符所在头文件 首先,需要确定`CAN_MSGStatus`是在哪个头文件中定义的。通常,对于STM32的CAN外设,它可能定义在`stm32fxxx_hal_can.h`(其中`xxx`代表芯片系列,如`f1xx`、`f4xx`等)。你可以通过以下方式查找: - 在工程中搜索`CAN_MSGStatus`,看它在哪个头文件中被定义。 - 或者查阅HAL库文档。 #### 步骤2: 包含正确的头文件 根据引用[2][3]的经验,使用STM32 HAL库时,推荐以下两种方式: - **方法A(推荐)**:包含顶层头文件`stm32fxxx_hal.h`(将`xxx`替换为你的芯片系列,如`f1xx`、`f4xx`等)。这个头文件会自动包含所有外设的头文件(通过`stm32fxxx_hal_conf.h`配置)。 ```c #include "stm32f1xx_hal.h" // 示例,根据你的芯片替换 ``` - **方法B**:如果不想包含整个HAL库,可以单独包含CAN外设的头文件,但必须确保先包含`stm32fxxx_hal_def.h`(因为其中定义了`HAL_StatusTypeDef`等基础类型)和`stm32fxxx_hal_can.h`(定义`CAN_MSGStatus`)。注意顺序: ```c #include "stm32f1xx_hal_def.h" // 基础类型定义 #include "stm32f1xx_hal_can.h" // CAN外设定 ``` #### 步骤3: 检查头文件包含顺序 如果已经包含了必要的头文件,但仍然报错,可能是包含顺序不对。确保: 1. 先包含芯片相关的头文件(如`stm32fxxx.h`)。 2. 再包含HAL库的头文件(如`stm32fxxx_hal.h`或外设头文件)。 #### 步骤4: 检查宏定义开关 在`stm32fxxx_hal_conf.h`中,确保已经使能了CAN外设。找到如下行并取消注释: ```c #define HAL_CAN_MODULE_ENABLED // 确保这行没有被注释 ``` #### 步骤5: 清理并重新编译 修改后,执行以下操作: 1. 清理工程(在IDE中选择Clean或删除编译输出文件)。 2. 重新编译。 ### 示例代码结构 ```c /* 正确包含头文件示例 */ #include "stm32f1xx.h" // 芯片级头文件 #include "stm32f1xx_hal.h" // HAL库顶层头文件(推荐方式) int main(void) { CAN_MSGStatus status; // 此时编译器应能识别CAN_MSGStatus // ... 其他代码 } ``` ### 常见问题排查 - **问题1**:`CAN_MSGStatus`拼写错误? 检查是否拼写一致(大小写敏感)。 - **问题2**:多个头文件冲突? 如果工程中有多个地方定义了`CAN_MSGStatus`,可能导致冲突。确保只包含标准HAL库的头文件。 - **问题3**:旧版HAL库? 更新HAL库到最新版本,确保`CAN_MSGStatus`在头文件中存在。 ### 相关问题 1. 如何确认一个标识符在哪个头文件中定义? 2. 使用STM32 HAL库时,为什么推荐包含`stm32fxxx_hal.h`而不是单独的外设头文件? 3. 如何配置`stm32fxxx_hal_conf.h`来启用特定外设? 4. 编译后仍然出现未定义错误,可能是什么原因? [^1]: [error: #20: identifier "adcx1" is undefined 的解决方法](https://blog.csdn.net/wuyuzun/article/details/...) [^2]: [HAL_StatusTypeDef未定义的解决方法](https://example.com) [^3]: [identifier "XXX_InitTypeDef" is undefined 的解决方案](https://example.com)</think>### C语言编译错误 `#20: identifier 'CAN_MSGStatus' is undefined` 解决方案 这个错误表示编译器找不到 `CAN_MSGStatus` 的定义,通常发生在使用STM32 HAL库开发时。以下是系统化的解决步骤: #### 1. **包含正确的头文件**(最常见原因) ```c // 错误方式:单独包含外设头文件 #include "stm32f1xx_hal_can.h" // 正确方式:包含顶层HAL库头文件 #include "stm32f1xx_hal.h" // 自动包含所有外设定义[^2][^3] ``` #### 2. **检查HAL库配置** 在 `stm32f1xx_hal_conf.h` 中启用CAN模块: ```c #define HAL_CAN_MODULE_ENABLED // 取消此行注释 ``` #### 3. **验证头文件包含顺序** 确保包含顺序正确: ```c #include "stm32f1xx.h" // 芯片定义 #include "stm32f1xx_hal.h" // HAL库主头文件 // 其他用户头文件... ``` #### 4. **检查标识符拼写** 确认大小写完全匹配: - 正确:`CAN_MSGStatus` - 错误:`CAN_MsgStatus` 或 `CAN_MSGSTATUS` #### 5. **清理并重建工程** 1. 删除 `build/` 或 `Debug/` 目录 2. 在IDE中执行 **Project → Clean** 3. 重新编译整个工程 #### 6. **验证HAL库版本** 在 `stm32f1xx_hal_can.h` 中检查是否存在定义: ```c typedef enum { CAN_MSGSTATUS_PENDING, CAN_MSGSTATUS_FAILED, CAN_MSGSTATUS_OK } CAN_MSGStatus; ``` > ⚠️ 如果仍找不到定义,可能是库版本问题,需更新HAL库 ### 问题排查流程图 ```mermaid graph TD A[出现 CAN_MSGStatus 未定义错误] --> B{是否包含 stm32f1xx_hal.h?} B -->|否| C[添加 #include stm32f1xx_hal.h] B -->|是| D{是否启用CAN模块?} D -->|否| E[在 hal_conf.h 中定义 HAL_CAN_MODULE_ENABLED] D -->|是| F{是否清理过工程?} F -->|否| G[执行完整清理后重建] F -->|是| H[检查HAL库版本] ``` ### 常见陷阱 1. **循环包含问题** 避免在头文件中相互包含,特别是外设头文件之间 2. **预编译头文件冲突** 如果使用预编译头(如 `pch.h`),确保它包含正确的主头文件 3. **多版本库混合** 检查工程是否意外混用了标准外设库(SPL)和HAL库 ### 相关问题 1. 如何正确配置STM32的HAL库头文件包含结构? 2. `HAL_StatusTypeDef` 未定义错误如何解决? 3. 使用STM32CubeMX生成工程后出现未定义标识符怎么办? 4. 如何验证STM32 HAL库的版本兼容性? [^1]: [标识符未定义错误分析及解决路径](https://blog.csdn.net/wuyuzun/article/details/...) [^2]: [HAL库头文件包含规范](https://example.com/hal_include) [^3]: [STM32外设模块启用配置指南](https://example.com/hal_module_config)
阅读全文

相关推荐

*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' compiling PWM.c... Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\PWM.c: 0 warnings, 7 errors compiling Buzzer.c... Hardware\Buzzer.c(28): error: #20: identifier "KEY_S2" is undefined if(key_val == KEY_S2) { Hardware\Buzzer.c(36): warning: #223-D: function "HAL_GetTick" declared implicitly if(buzzerState && (HAL_GetTick() - lastToggle > 500)) { Hardware\Buzzer.c(38): warning: #223-D: function "GPIO_ToggleBits" declared implicitly GPIO_ToggleBits(BUZZER_PORT, BUZZER_PIN); // 鍒囨崲鐘舵€? Hardware\Buzzer.c: 2 warnings, 1 error compiling LightSensor.c... Hardware\LightSensor.c(2): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\LightSensor.c: 0 warnings, 1 error compiling OLED.c... Hardware\OLED.c(3): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\OLED.c: 0 warnings, 1 error compiling main.c... .\Hardware\lightsensor.h(3): error: #3: #include file ".\Hardware\lightsensor.h" includes itself #include "lightsensor.h" // 去掉下划线[^1] User\main.c: 0 warnings, 1 error compiling Key.c... Hardware\Key.c(13): error: #20: identifier "KEY_S0_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S0_PIN; Hardware\Key.c(15): error: #20: identifier "KEY_S0_PORT" is undefined GPIO_Init(KEY_S0_PORT, &GPIO_InitStructure); Hardware\Key.c(18): error: #20: identifier "KEY_S1_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S1_PIN; Hardware\Key.c(19): error: #20: identifier "KEY_S1_PORT" is undefined GPIO_Init(KEY_S1_PORT, &GPIO_InitStructure); Hardware\Key.c(22): error: #20: identifier "KEY_S2_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S2_PIN; Hardware\Key.c(23): error: #20: identifier "KEY_S2_PORT" is undefined GPIO_Init(KEY_S2_PORT, &GPIO_InitStructure); Hardware\Key.c(26): error: #20: identifier "KEY_S3_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S3_PIN; Hardware\Key.c(27): error: #20: identifier "KEY_S3_PORT" is undefined GPIO_Init(KEY_S3_PORT, &GPIO_InitStructure); Hardware\Key.c(34): error: #20: identifier "KEY_S0_PORT" is undefined if(key_up && (GPIO_ReadInputDataBit(KEY_S0_PORT, KEY_S0_PIN) == Bit_SET || Hardware\Key.c(34): error: #20: identifier "KEY_S0_PIN" is undefined if(key_up && (GPIO_ReadInputDataBit(KEY_S0_PORT, KEY_S0_PIN) == Bit_SET || Hardware\Key.c(35): error: #20: identifier "KEY_S1_PORT" is undefined GPIO_ReadInputDataBit(KEY_S1_PORT, KEY_S1_PIN) == Bit_SET || Hardware\Key.c(35): error: #20: identifier "KEY_S1_PIN" is undefined GPIO_ReadInputDataBit(KEY_S1_PORT, KEY_S1_PIN) == Bit_SET || Hardware\Key.c(36): error: #20: identifier "KEY_S2_PORT" is undefined GPIO_ReadInputDataBit(KEY_S2_PORT, KEY_S2_PIN) == Bit_SET || Hardware\Key.c(36): error: #20: identifier "KEY_S2_PIN" is undefined GPIO_ReadInputDataBit(KEY_S2_PORT, KEY_S2_PIN) == Bit_SET || Hardware\Key.c(37): error: #20: identifier "KEY_S3_PORT" is undefined GPIO_ReadInputDataBit(KEY_S3_PORT, KEY_S3_PIN) == Bit_SET)) { Hardware\Key.c(37): error: #20: identifier "KEY_S3_PIN" is undefined GPIO_ReadInputDataBit(KEY_S3_PORT, KEY_S3_PIN) == Bit_SET)) { Hardware\Key.c(38): warning: #223-D: function "Delay_ms" declared implicitly Delay_ms(10); // 娑堟姈寤舵椂 Hardware\Key.c(48): error: #20: identifier "KEY_S3" is undefined return KEY_S3; Hardware\Key.c(57): error: #20: identifier "KEY_NONE" is undefined return KEY_NONE; Hardware\Key.c: 1 warning, 18 errors compiling LED.c... Hardware\LED.c(7): error: #20: identifier "LED_FlowMode" is undefined static LED_FlowMode flowMode = LED_FLOW_OFF; Hardware\LED.c(9): error: #20: identifier "BREATH_OFF" is undefined static BreathState breathState = BREATH_OFF; Hardware\LED.c(23): error: #20: identifier "LED_PINS" is undefined GPIO_InitStructure.GPIO_Pin = LED_PINS; Hardware\LED.c(37): error: #20: identifier "KEY_S0" is undefined if(key_val == KEY_S0) { Hardware\LED.c(40): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); // 鍏抽棴鎵€鏈塋ED Hardware\LED.c(47): error: #20: identifier "LED_FLOW_FORWARD" is undefined case LED_FLOW_FORWARD: OLED_ShowString(72, 0, "FWD"); break; Hardware\LED.c(48): error: #20: identifier "LED_FLOW_BACKWARD" is undefined case LED_FLOW_BACKWARD: OLED_ShowString(72, 0, "REV"); break; Hardware\LED.c(53): error: #20: identifier "KEY_S1" is undefined if(key_val == KEY_S1) { Hardware\LED.c(54): warning: #188-D: enumerated type mixed with another type breathState = (breathState + 1) % 3; Hardware\LED.c(61): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); // 鍏抽棴LED Hardware\LED.c(63): error: #20: identifier "BREATH_ON" is undefined case BREATH_ON: Hardware\LED.c(67): error: #20: identifier "BREATH_FULL" is undefined case BREATH_FULL: Hardware\LED.c(75): warning: #223-D: function "HAL_GetTick" declared implicitly if(flowMode != LED_FLOW_OFF && (HAL_GetTick() - lastUpdate > 200)) { Hardware\LED.c(79): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); Hardware\LED.c(82): error: #20: identifier "LED_FLOW_FORWARD" is undefined if(flowMode == LED_FLOW_FORWARD) { Hardware\LED.c(93): error: #20: identifier "BREATH_ON" is undefined if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(93): warning: #223-D: function "HAL_GetTick" declared implicitly if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(34): warning: #177-D: variable "flowDir" was declared but never referenced static uint8_t flowDir = 0; // 0:宸︹啋鍙? 1:鍙斥啋宸? Hardware\LED.c: 4 warnings, 14 errors ".\Objects\Project.axf" - 43 Error(s), 7 Warning(s). Target not created.所有要修改的模块

Rebuild started: Project: display *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\MCUSTM32\ARM\ARMCC\Bin' Rebuild target 'display' Note: source file '..\CORE\system_stm32f10x.c' - object file renamed from '.\Objects\system_stm32f10x.o' to '.\Objects\system_stm32f10x_1.o'. compiling system_stm32f10x.c... compiling stm32f10x_it.c... compiling main.c... ..\USER\main.h(16): warning: #1-D: last line of file ends without a newline // 空行(解决警告) ..\USER\main.c(2): error: #5: cannot open source input file "systick.h": No such file or directory #include "systick.h" ..\USER\main.c: 1 warning, 1 error assembling startup_stm32f10x_md.s... compiling misc.c... compiling core_cm3.c... compiling stm32f10x_rcc.c... compiling display.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\APP\display.c: 1 warning, 0 errors compiling stm32f10x_gpio.c... compiling key.c... ..\USER\main.h(16): warning: #1-D: last line of file ends without a newline // 空行(解决警告) ..\APP\timer.h(9): warning: #1-D: last line of file ends without a newline #endif /* __TIMER_H */ ..\APP\key.c(33): error: #20: identifier "KEY_MODE" is undefined return KEY_MODE; ..\APP\key.c(35): error: #20: identifier "KEY_UP" is undefined return KEY_UP; ..\APP\key.c(37): error: #20: identifier "KEY_DOWN" is undefined return KEY_DOWN; ..\APP\key.c(38): error: #20: identifier "KEY_NONE" is undefined return KEY_NONE; ..\APP\key.c(51): error: #20: identifier "KEY_MODE" is undefined case KEY_MODE: ..\APP\key.c(55): error: #20: identifier "KEY_UP" is undefined case KEY_UP: ..\APP\key.c(66): error: #20: identifier "KEY_DOWN" is undefined case KEY_DOWN: ..\APP\key.c(78): warning: #1-D: last line of file ends without a newline } ..\APP\key.c: 3 warnings, 7 errors compiling systick_delay.c... compiling timer.c... ..\USER\main.h(16): warning: #1-D: last line of file ends without a newline // 空行(解决警告) ..\APP\timer.h(9): warning: #1-D: last line of file ends without a newline #endif /* __TIMER_H */ ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\APP\timer.c: 3 warnings, 0 errors compiling stm32f10x_tim.c... ".\Objects\display.axf" - 8 Error(s), 8 Warning(s). Target not created. Build Time Elapsed: 00:00:02

Rebuild started: Project: display *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\MCUSTM32\ARM\ARMCC\Bin' Rebuild target 'display' Note: source file '..\CORE\system_stm32f10x.c' - object file renamed from '.\Objects\system_stm32f10x.o' to '.\Objects\system_stm32f10x_1.o'. compiling system_stm32f10x.c... assembling startup_stm32f10x_md.s... compiling main.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\USER\main.h(23): warning: #1-D: last line of file ends without a newline #endif /* __MAIN_H */ ..\USER\main.h(23): warning: #1-D: last line of file ends without a newline #endif /* __MAIN_H */ ..\APP\timer.h(9): warning: #1-D: last line of file ends without a newline #endif /* __TIMER_H */ ..\USER\main.c: 4 warnings, 0 errors compiling misc.c... compiling core_cm3.c... compiling stm32f10x_gpio.c... compiling systick.c... ..\APP\systick.h(5): error: #20: identifier "uint32_t" is undefined void delay_ms(uint32_t ms); ..\APP\systick.c(12): error: #20: identifier "GPIO_InitTypeDef" is undefined GPIO_InitTypeDef GPIO_InitStructure; ..\APP\systick.c(14): warning: #223-D: function "RCC_APB2PeriphClockCmd" declared implicitly RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE); ..\APP\systick.c(14): error: #20: identifier "RCC_APB2Periph_GPIOC" is undefined RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE); ..\APP\systick.c(14): error: #20: identifier "ENABLE" is undefined RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE); ..\APP\systick.c(15): error: #20: identifier "GPIO_Pin_13" is undefined GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; // 板载LED接PC13 ..\APP\systick.c(16): error: #20: identifier "GPIO_Speed_2MHz" is undefined GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; ..\APP\systick.c(17): error: #20: identifier "GPIO_Mode_Out_PP" is undefined GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; ..\APP\systick.c(18): warning: #223-D: function "GPIO_Init" declared implicitly GPIO_Init(GPIOC, &GPIO_InitStructure); ..\APP\systick.c(18): error: #20: identifier "GPIOC" is undefined GPIO_Init(GPIOC, &GPIO_InitStructure); ..\APP\systick.c: 2 warnings, 8 errors compiling delay.c... compiling key.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\USER\main.h(23): warning: #1-D: last line of file ends without a newline #endif /* __MAIN_H */ ..\APP\key.c(56): warning: #223-D: function "set_time" declared implicitly set_time(h, currentTime.minutes, currentTime.seconds); ..\APP\key.c(60): warning: #223-D: function "set_time" declared implicitly set_time(currentTime.hours, m, currentTime.seconds); ..\APP\key.c(67): warning: #223-D: function "set_time" declared implicitly set_time(h, currentTime.minutes, currentTime.seconds); ..\APP\key.c(71): warning: #223-D: function "set_time" declared implicitly set_time(currentTime.hours, m, currentTime.seconds); ..\APP\key.c(76): warning: #1-D: last line of file ends without a newline } ..\APP\key.c: 7 warnings, 0 errors compiling timer.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\USER\main.h(23): warning: #1-D: last line of file ends without a newline #endif /* __MAIN_H */ ..\USER\main.h(23): warning: #1-D: last line of file ends without a newline #endif /* __MAIN_H */ ..\APP\timer.h(9): warning: #1-D: last line of file ends without a newline #endif /* __TIMER_H */ ..\APP\timer.c: 4 warnings, 0 errors compiling stm32f10x_rcc.c... compiling stm32f10x_it.c... compiling display.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\APP\display.c: 1 warning, 0 errors compiling stm32f10x_tim.c... ".\Objects\display.axf" - 8 Error(s), 18 Warning(s). Target not created. Build Time Elapsed: 00:00:02

*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' compiling LightSensor.c... Hardware\LightSensor.c(2): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\LightSensor.c: 0 warnings, 1 error compiling LED.c... Hardware\LED.c(37): error: #20: identifier "KEY_S0" is undefined if(key_val == KEY_S0) { Hardware\LED.c(38): warning: #188-D: enumerated type mixed with another type flowMode = (flowMode + 1) % 3; Hardware\LED.c(53): error: #20: identifier "KEY_S1" is undefined if(key_val == KEY_S1) { Hardware\LED.c(54): warning: #188-D: enumerated type mixed with another type breathState = (breathState + 1) % 3; Hardware\LED.c(75): warning: #223-D: function "HAL_GetTick" declared implicitly if(flowMode != LED_FLOW_OFF && (HAL_GetTick() - lastUpdate > 200)) { Hardware\LED.c(93): warning: #223-D: function "HAL_GetTick" declared implicitly if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(34): warning: #177-D: variable "flowDir" was declared but never referenced static uint8_t flowDir = 0; // 0:宸︹啋鍙? 1:鍙斥啋宸? Hardware\LED.c: 5 warnings, 2 errors compiling OLED.c... Hardware\OLED.c(3): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\OLED.c: 0 warnings, 1 error compiling PWM.c... Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\PWM.c(25): error: #20: identifier "LED1_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED2_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED3_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED4_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED5_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED6_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED7_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED1_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED2_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED3_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED4_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED5_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED6_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED7_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c: 0 warnings, 21 errors compiling Buzzer.c... Hardware\Buzzer.c(28): error: #20: identifier "KEY_S2" is undefined if(key_val == KEY_S2) { Hardware\Buzzer.c(36): warning: #223-D: function "HAL_GetTick" declared implicitly if(buzzerState && (HAL_GetTick() - lastToggle > 500)) { Hardware\Buzzer.c(38): warning: #223-D: function "GPIO_ToggleBits" declared implicitly GPIO_ToggleBits(BUZZER_PORT, BUZZER_PIN); // 鍒囨崲鐘舵€? Hardware\Buzzer.c: 2 warnings, 1 error compiling main.c... .\Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; .\Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; .\Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; User\main.c(22): warning: #223-D: function "delay_init" declared implicitly delay_init(); // 寤舵椂鍒濆鍖? User\main.c(27): error: #165: too few arguments in function call LightSensor_Init(); User\main.c(31): error: #140: too many arguments in function call u8 key = KEY_Scan(0); // 涓嶆敮鎸佽繛鎸? User\main.c(34): error: #20: identifier "KEY0_PRES" is undefined if (key == KEY0_PRES) User\main.c(37): warning: #223-D: function "LED_Flow_SetMode" declared implicitly LED_Flow_SetMode(sysState.ledFlowMode); User\main.c(41): error: #20: identifier "KEY1_PRES" is undefined if (key == KEY1_PRES) User\main.c(46): warning: #223-D: function "LED_Breath_SetState" declared implicitly LED_Breath_SetState(LED_BREATH_ON); User\main.c(46): error: #20: identifier "LED_BREATH_ON" is undefined LED_Breath_SetState(LED_BREATH_ON); User\main.c(47): warning: #223-D: function "LED_Breath_SetPeriod" declared implicitly LED_Breath_SetPeriod(500); // 500ms鍛ㄦ湡 User\main.c(52): warning: #223-D: function "LED_Breath_SetState" declared implicitly LED_Breath_SetState(LED_BREATH_OFF); User\main.c(52): error: #20: identifier "LED_BREATH_OFF" is undefined LED_Breath_SetState(LED_BREATH_OFF); User\main.c(57): error: #20: identifier "KEY2_PRES" is undefined if (key == KEY2_PRES) User\main.c(60): warning: #223-D: function "Buzzer_SetState" declared implicitly Buzzer_SetState(sysState.beepState); User\main.c(64): error: #20: identifier "KEY3_PRES" is undefined if (key == KEY3_PRES) User\main.c(69): warning: #223-D: function "OLED_DisplayOn" declared implicitly OLED_DisplayOn(); User\main.c(71): warning: #223-D: function "OLED_ShowPersonalInfo" declared implicitly OLED_ShowPersonalInfo(); User\main.c(75): warning: #223-D: function "OLED_DisplayOff" declared implicitly OLED_DisplayOff(); User\main.c(80): warning: #223-D: function "LED_Flow_Task" declared implicitly LED_Flow_Task(); User\main.c(83): warning: #223-D: function "LED_Breath_Task" declared implicitly LED_Breath_Task(); User\main.c(86): warning: #223-D: function "Buzzer_Task" declared implicitly Buzzer_Task(); User\main.c(91): warning: #223-D: function "OLED_UpdateLightState" declared implicitly OLED_UpdateLightState(); // 鏇存柊鍏夌収鐘舵€佹樉绀? User\main.c(94): warning: #223-D: function "delay_ms" declared implicitly delay_ms(10); User\main.c: 14 warnings, 15 errors ".\Objects\Project.axf" - 41 Error(s), 21 Warning(s). Target not created.

根据错误提示修改代码Rebuild started: Project: display *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\MCUSTM32\ARM\ARMCC\Bin' Rebuild target 'display' Note: source file '..\CORE\system_stm32f10x.c' - object file renamed from '.\Objects\system_stm32f10x.o' to '.\Objects\system_stm32f10x_1.o'. compiling display.c... ..\APP\display.h(36): warning: #1-D: last line of file ends without a newline #endif ..\APP\display.c: 1 warning, 0 errors compiling main.c... ..\USER\main.c(4): error: #20: identifier "TimeStruct" is undefined extern TimeStruct currentTime; ..\USER\main.c(15): warning: #223-D: function "systick_init" declared implicitly systick_init(); // 系统滴答定时器初始化 ..\USER\main.c(19): warning: #223-D: function "led_init" declared implicitly led_init(); // LED初始化(用于系统状态指示) ..\USER\main.c(20): warning: #223-D: function "display_init" declared implicitly display_init(); // 数码管显示初始化 ..\USER\main.c(21): warning: #223-D: function "keys_init" declared implicitly keys_init(); // 按键初始化(用于时间调整) ..\USER\main.c(26): warning: #223-D: function "tim4_init" declared implicitly tim4_init(200-1, 360-1); ..\USER\main.c(29): warning: #223-D: function "set_time" declared implicitly set_time(12, 0, 0); // 设置初始时间为12:00:00 ..\USER\main.c(38): warning: #223-D: function "PCout" declared implicitly PCout(13) = !PCin(13); ..\USER\main.c(38): warning: #223-D: function "PCin" declared implicitly PCout(13) = !PCin(13); ..\USER\main.c(38): error: #137: expression must be a modifiable lvalue PCout(13) = !PCin(13); ..\USER\main.c(39): warning: #223-D: function "delay_ms" declared implicitly delay_ms(500); ..\USER\main.c(42): warning: #223-D: function "handle_keypress" declared implicitly handle_keypress(&adjust_mode); ..\USER\main.c: 10 warnings, 2 errors assembling startup_stm32f10x_md.s... compiling system_stm32f10x.c... compiling stm32f10x_rcc.c... compiling core_cm3.c... compiling misc.c... compiling stm32f10x_gpio.c... compiling delay.c... compiling stm32f10x_it.c... compiling led.c... compiling timer.c... ..\APP\display.h(36): warning: #1-D: last line of file ends without a newline #endif ..\APP\timer.c(58): error: #136: struct "<unnamed>" has no field "blinkPhase" dsp.blinkPhase = !dsp.blinkPhase; // 翻转闪烁相位 ..\APP\timer.c(58): error: #136: struct "<unnamed>" has no field "blinkPhase" dsp.blinkPhase = !dsp.blinkPhase; // 翻转闪烁相位 ..\APP\timer.c(64): error: #20: identifier "COLON_SYMBOL" is undefined dsp.digit[2] = COLON_SYMBOL; // 冒号 ..\APP\timer.c(70): error: #136: struct "<unnamed>" has no field "colonMask" dsp.colonMask = (1 << 2); // 第3位显示冒号 (索引2) ..\APP\timer.c(71): error: #136: struct "<unnamed>" has no field "blinkMask" dsp.blinkMask = (1 << 2); // 第3位闪烁 ..\APP\timer.c: 1 warning, 5 errors compiling key.c... ..\APP\display.h(36): warning: #1-D: last line of file ends without a newline #endif ..\APP\key.c(7): warning: #223-D: function "key_scan" declared implicitly uint8_t current_key_state = key_scan(); ..\APP\key.c(21): error: #20: identifier "currentTime" is undefined uint8_t h = currentTime.hours; ..\APP\key.c(23): warning: #223-D: function "set_time" declared implicitly set_time(h, currentTime.minutes, currentTime.seconds); ..\APP\key.c(27): error: #20: identifier "currentTime" is undefined uint8_t m = currentTime.minutes; ..\APP\key.c(29): warning: #223-D: function "set_time" declared implicitly set_time(currentTime.hours, m, currentTime.seconds); ..\APP\key.c(36): error: #20: identifier "currentTime" is undefined uint8_t h = currentTime.hours; ..\APP\key.c(38): warning: #223-D: function "set_time" declared implicitly set_time(h, currentTime.minutes, currentTime.seconds); ..\APP\key.c(42): error: #20: identifier "currentTime" is undefined uint8_t m = currentTime.minutes; ..\APP\key.c(44): warning: #223-D: function "set_time" declared implicitly set_time(currentTime.hours, m, currentTime.seconds); ..\APP\key.c(48): warning: #1-D: last line of file ends without a newline } ..\APP\key.c: 7 warnings, 4 errors compiling stm32f10x_tim.c... ".\Objects\display.axf" - 11 Error(s), 19 Warning(s). Target not created. Build Time Elapsed: 00:00:02

根据提示修改代码Rebuild started: Project: display *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\MCUSTM32\ARM\ARMCC\Bin' Rebuild target 'display' Note: source file '..\CORE\system_stm32f10x.c' - object file renamed from '.\Objects\system_stm32f10x.o' to '.\Objects\system_stm32f10x_1.o'. assembling startup_stm32f10x_md.s... compiling system_stm32f10x.c... compiling main.c... ..\APP\display.h(36): warning: #1-D: last line of file ends without a newline #endif ..\USER\main.c(26): warning: #223-D: function "systick_init" declared implicitly systick_init(); ..\USER\main.c(34): warning: #223-D: function "delay_ms" declared implicitly delay_ms(500); ..\USER\main.c: 3 warnings, 0 errors compiling stm32f10x_it.c... compiling misc.c... compiling core_cm3.c... compiling stm32f10x_tim.c... compiling stm32f10x_gpio.c... compiling stm32f10x_rcc.c... compiling display.c... ..\APP\display.h(36): warning: #1-D: last line of file ends without a newline #endif ..\APP\display.c(7): error: #147: declaration is incompatible with "const u16 segCode[14]" (declared at line 25 of "..\APP\display.h") const u16 segCode[11] = { ..\APP\display.c(50): error: #29: expected an expression for(int i = 0; i < 6; i++) { ..\APP\display.c(50): error: #20: identifier "i" is undefined for(int i = 0; i < 6; i++) { ..\APP\display.c(63): error: #29: expected an expression for(int i = 0; i < 6; i++) { ..\APP\display.c(63): error: #20: identifier "i" is undefined for(int i = 0; i < 6; i++) { ..\APP\display.c: 1 warning, 5 errors compiling delay.c... compiling led.c... compiling timer.c... ..\APP\display.h(36): warning: #1-D: last line of file ends without a newline #endif ..\APP\timer.c: 1 warning, 0 errors ".\Objects\display.axf" - 5 Error(s), 5 Warning(s). Target not created. Build Time Elapsed: 00:00:01

Rebuild started: Project: display *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\MCUSTM32\ARM\ARMCC\Bin' Rebuild target 'display' Note: source file '..\CORE\system_stm32f10x.c' - object file renamed from '.\Objects\system_stm32f10x.o' to '.\Objects\system_stm32f10x_1.o'. compiling stm32f10x_it.c... compiling timer.c... ..\APP\timer.h(10): warning: #1-D: last line of file ends without a newline #endif /* __TIMER_H */ ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\APP\timer.c(6): error: #20: identifier "TimeStruct" is undefined TimeStruct currentTime = {12, 0, 0}; // 初始化为12:00:00 ..\APP\timer.c: 2 warnings, 1 error assembling startup_stm32f10x_md.s... compiling system_stm32f10x.c... compiling misc.c... compiling main.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\USER\main.h(22): warning: #1-D: last line of file ends without a newline #endif ..\USER\main.h(22): warning: #1-D: last line of file ends without a newline #endif ..\USER\main.c(2): error: #5: cannot open source input file "systick.h": No such file or directory #include "systick.h" ..\USER\main.c: 3 warnings, 1 error compiling core_cm3.c... compiling stm32f10x_rcc.c... compiling display.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\APP\display.c(69): error: #136: struct "<unnamed>" has no field "dot" dsp.dot = 0; // 默认无小数点 ..\APP\display.c(94): error: #136: struct "<unnamed>" has no field "dot" dsp->dot = dotBit; ..\APP\display.c(150): error: #136: struct "<unnamed>" has no field "dot" if(dsp.currDigit == dsp.dot && dsp.dot != 0) { ..\APP\display.c(150): error: #136: struct "<unnamed>" has no field "dot" if(dsp.currDigit == dsp.dot && dsp.dot != 0) { ..\APP\display.c: 1 warning, 4 errors compiling stm32f10x_gpio.c... compiling delay.c... compiling led.c... compiling key.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\USER\main.h(22): warning: #1-D: last line of file ends without a newline #endif ..\APP\key.c(56): warning: #223-D: function "set_time" declared implicitly set_time(h, currentTime.minutes, currentTime.seconds); ..\APP\key.c(60): warning: #223-D: function "set_time" declared implicitly set_time(currentTime.hours, m, currentTime.seconds); ..\APP\key.c(67): warning: #223-D: function "set_time" declared implicitly set_time(h, currentTime.minutes, currentTime.seconds); ..\APP\key.c(71): warning: #223-D: function "set_time" declared implicitly set_time(currentTime.hours, m, currentTime.seconds); ..\APP\key.c(76): warning: #1-D: last line of file ends without a newline } ..\APP\key.c: 7 warnings, 0 errors compiling stm32f10x_tim.c... ".\Objects\display.axf" - 6 Error(s), 13 Warning(s). Target not created. Build Time Elapsed: 00:00:02根据提示修改代码

*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' compiling main.c... User\main.c(21): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" User\main.c: 0 warnings, 1 error compiling LightSensor.c... Hardware\lightsensor.h(6): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\LightSensor.c: 0 warnings, 1 error compiling Delay.c... compiling OLED.c... Hardware\myi2c.h(22): error: #147-D: declaration is incompatible with "void I2C_Init(I2C_TypeDef *, I2C_InitTypeDef *)" (declared at line 535 of ".\Library\stm32f10x_i2c.h") void I2C_Init(void); Hardware\OLED.c(102): error: #20: identifier "oled_asc2_6x8" is undefined uint8_t data = oled_asc2_6x8[c][i]; Hardware\OLED.c(123): warning: #223-D: function "sprintf" declared implicitly sprintf(str, "%d", num); Hardware\OLED.c: 1 warning, 2 errors compiling PWM.c... compiling Key.c... Hardware\Key.c(34): warning: #223-D: function "delay_ms" declared implicitly delay_ms(20); // 娑堟姈 Hardware\Key.c(41): warning: #223-D: function "delay_ms" declared implicitly delay_ms(20); Hardware\Key.c(48): warning: #223-D: function "delay_ms" declared implicitly delay_ms(20); Hardware\Key.c(55): warning: #223-D: function "delay_ms" declared implicitly delay_ms(20); Hardware\Key.c: 4 warnings, 0 errors compiling LED.c... compiling myi2c.c... Hardware\myi2c.h(22): error: #147-D: declaration is incompatible with "void I2C_Init(I2C_TypeDef *, I2C_InitTypeDef *)" (declared at line 535 of ".\Library\stm32f10x_i2c.h") void I2C_Init(void); Hardware\myi2c.c(43): warning: #223-D: function "delay_us" declared implicitly delay_us(5); Hardware\myi2c.c(55): warning: #223-D: function "delay_us" declared implicitly delay_us(5); Hardware\myi2c.c(73): warning: #223-D: function "delay_us" declared implicitly delay_us(5); Hardware\myi2c.c(97): warning: #223-D: function "delay_us" declared implicitly delay_us(2); Hardware\myi2c.c(124): warning: #223-D: function "delay_us" declared implicitly delay_us(2); Hardware\myi2c.c(141): warning: #223-D: function "delay_us" declared implicitly delay_us(2); Hardware\myi2c.c: 6 warnings, 1 error compiling Buzzer.c... Hardware\Buzzer.c(62): warning: #223-D: function "delay_ms" declared implicitly delay_ms(duration_ms); Hardware\Buzzer.c: 1 warning, 0 errors ".\Objects\Project.axf" - 5 Error(s), 12 Warning(s). Target not created. Build Time Elapsed: 00:00:43这是什么错误

*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' compiling i2c.c... i2c.h(6): error: #147-D: declaration is incompatible with "void I2C_Init(I2C_TypeDef *, I2C_InitTypeDef *)" (declared at line 535 of ".\Library\stm32f10x_i2c.h") void I2C_Init(void); i2c.h(15): warning: #1-D: last line of file ends without a newline #endif i2c.c(20): warning: #223-D: function "SDA_OUT" declared implicitly SDA_OUT(); i2c.c(21): warning: #223-D: function "I2C_SDA_H" declared implicitly I2C_SDA_H(); i2c.c(22): warning: #223-D: function "I2C_SCL_H" declared implicitly I2C_SCL_H(); i2c.c(24): warning: #223-D: function "I2C_SDA_L" declared implicitly I2C_SDA_L(); i2c.c(26): warning: #223-D: function "I2C_SCL_L" declared implicitly I2C_SCL_L(); i2c.c(31): warning: #223-D: function "SDA_OUT" declared implicitly SDA_OUT(); i2c.c(32): warning: #223-D: function "I2C_SCL_L" declared implicitly I2C_SCL_L(); i2c.c(33): warning: #223-D: function "I2C_SDA_L" declared implicitly I2C_SDA_L(); i2c.c(35): warning: #223-D: function "I2C_SCL_H" declared implicitly I2C_SCL_H(); i2c.c(36): warning: #223-D: function "I2C_SDA_H" declared implicitly I2C_SDA_H(); i2c.c(43): warning: #223-D: function "SDA_OUT" declared implicitly SDA_OUT(); i2c.c(44): warning: #223-D: function "I2C_SCL_L" declared implicitly I2C_SCL_L(); i2c.c(46): warning: #223-D: function "I2C_SDA_H" declared implicitly if((txd & 0x80) >> 7) I2C_SDA_H(); i2c.c(47): warning: #223-D: function "I2C_SDA_L" declared implicitly else I2C_SDA_L(); i2c.c(50): warning: #223-D: function "I2C_SCL_H" declared implicitly I2C_SCL_H(); i2c.c(60): warning: #223-D: function "SDA_IN" declared implicitly SDA_IN(); i2c.c(62): warning: #223-D: function "I2C_SCL_L" declared implicitly I2C_SCL_L(); i2c.c(64): warning: #223-D: function "I2C_SCL_H" declared implicitly I2C_SCL_H(); i2c.c(66): error: #20: identifier "READ_SDA" is undefined if(READ_SDA) receive++; i2c.c(77): warning: #223-D: function "SDA_IN" declared implicitly SDA_IN(); i2c.c(78): warning: #223-D: function "I2C_SDA_H" declared implicitly I2C_SDA_H(); Delay_us(1); i2c.c(79): warning: #223-D: function "I2C_SCL_H" declared implicitly I2C_SCL_H(); Delay_us(5); i2c.c(80): error: #20: identifier "READ_SDA" is undefined while(READ_SDA) { i2c.c(87): warning: #223-D: function "I2C_SCL_L" declared implicitly I2C_SCL_L(); i2c.c(93): warning: #223-D: function "I2C_SCL_L" declared implicitly I2C_SCL_L(); i2c.c(94): warning: #223-D: function "SDA_OUT" declared implicitly SDA_OUT(); i2c.c(95): warning: #223-D: function "I2C_SDA_L" declared implicitly I2C_SDA_L(); i2c.c(97): warning: #223-D: function "I2C_SCL_H" declared implicitly I2C_SCL_H(); i2c.c(104): warning: #223-D: function "I2C_SCL_L" declared implicitly I2C_SCL_L(); i2c.c(105): warning: #223-D: function "SDA_OUT" declared implicitly SDA_OUT(); i2c.c(106): warning: #223-D: function "I2C_SDA_H" declared implicitly I2C_SDA_H(); i2c.c(108): warning: #223-D: function "I2C_SCL_H" declared implicitly I2C_SCL_H(); i2c.c(120): warning: #1-D: last line of file ends without a newline #define READ_SDA (GPIOB->IDR & GPIO_Pin_7) i2c.c: 32 warnings, 3 errors compiling main.c... User\main.c(6): error: #5: cannot open source input file "mpu6050.h": No such file or directory #include "mpu6050.h" // 鏇挎崲jy61p.h涓篗PU6050椹卞姩 User\main.c: 0 warnings, 1 error compiling mpu6050.c... mpu6050.h(21): warning: #1-D: last line of file ends without a newline #endif i2c.h(6): error: #147-D: declaration is incompatible with "void I2C_Init(I2C_TypeDef *, I2C_InitTypeDef *)" (declared at line 535 of ".\Library\stm32f10x_i2c.h") void I2C_Init(void); i2c.h(15): warning: #1-D: last line of file ends without a newline #endif mpu6050.c(69): warning: #1-D: last line of file ends without a newline } mpu6050.c: 3 warnings, 1 error ".\Objects\Project.axf" - 5 Error(s), 35 Warning(s). Target not created. Build Time Elapsed: 00:00:01

compiling main.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/main.c(48): error: #256: invalid redeclaration of type name "Cylinder" (declared at line 10 of "../Core/Inc/path_planner.h") } Cylinder; ../Core/Src/main.c(73): error: #101: "TASK_SIMPLE_EXIT" has already been declared in the current scope TASK_SIMPLE_EXIT, ../Core/Src/main.c(74): error: #101: "TASK_SNAKE_PATH" has already been declared in the current scope TASK_SNAKE_PATH, ../Core/Src/main.c(75): error: #101: "TASK_CIRCLE_TWO_COLORS" has already been declared in the current scope TASK_CIRCLE_TWO_COLORS, ../Core/Src/main.c(76): error: #101: "TASK_COLUMN_SWAP" has already been declared in the current scope TASK_COLUMN_SWAP, ../Core/Src/main.c(77): error: #101: "TASK_RANDOM_DETECT" has already been declared in the current scope TASK_RANDOM_DETECT, ../Core/Src/main.c(78): error: #101: "TASK_DETECT_AND_PATH" has already been declared in the current scope TASK_DETECT_AND_PATH, ../Core/Src/main.c(79): error: #101: "TASK_NONE" has already been declared in the current scope TASK_NONE ../Core/Src/main.c(80): error: #256: invalid redeclaration of type name "TaskMode" (declared at line 20 of "../Core/Inc/path_planner.h") } TaskMode; ../Core/Src/main.c(398): error: #20: identifier "M_PI" is undefined current_x += encoder_dist * cosf(fused_yaw * M_PI / 180.0f); ../Core/Src/main.c: 2 warnings, 10 errors compiling pid.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\pid.c: 2 warnings, 0 errors compiling usart.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/usart.c: 2 warnings, 0 errors compiling ultrasonic.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\ultrasonic.c: 2 warnings, 0 errors compiling encoder.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ..\Core\Src\encoder.c: 3 warnings, 0 errors compiling kalman_filter.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\kalman_filter.c: 2 warnings, 0 errors compiling motor.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\motor.c: 2 warnings, 0 errors compiling jy61p.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\jy61p.c(18): warning: #1-D: last line of file ends without a newline } ..\Core\Src\jy61p.c: 3 warnings, 0 errors compiling i2c.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/i2c.c: 2 warnings, 0 errors compiling tim.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/tim.c: 2 warnings, 0 errors compiling gpio.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/gpio.c: 2 warnings, 0 errors compiling motion.c... ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\motion.c(13): error: #20: identifier "Cylinder" is undefined extern Cylinder cylinders[MAX_CYLINDERS]; ..\Core\Src\motion.c(13): error: #20: identifier "MAX_CYLINDERS" is undefined extern Cylinder cylinders[MAX_CYLINDERS]; ..\Core\Src\motion.c: 3 warnings, 2 errors compiling stm32f1xx_it.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/stm32f1xx_it.c: 2 warnings, 0 errors compiling stm32f1xx_hal_msp.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/stm32f1xx_hal_msp.c: 2 warnings, 0 errors compiling path_planner.c... ../Core/Inc/encoder.h(11): warning: #1-D: last line of file ends without a newline #endif /* __ENCODER_H */ ../Core/Inc/motion.h(24): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\path_planner.c(51): warning: #1-D: last line of file ends without a newline } ..\Core\Src\path_planner.c: 3 warnings, 0 errors "carL\carL.axf" - 12 Error(s), 34 Warning(s). Target not created. 以下是现有的代码 main.c /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "i2c.h" #include "tim.h" #include "usart.h" #include "gpio.h" #include "jy61p.h" #include "pid.h" #include "kalman_filter.h" #include "motor.h" #include "encoder.h" #include "ultrasonic.h" #include "motion.h" #include "path_planner.h" #include <stdio.h> #include <string.h> #include <math.h> /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ // ??????? #define MAX_CYLINDERS 10 typedef struct { int x, y, r; char color; uint8_t visited; } Cylinder; Cylinder cylinders[MAX_CYLINDERS]; int cylinder_count = 0; uint8_t mission_running = 0; uint32_t start_time = 0; #define TASK_TIMEOUT_MS 10000 #define DETECT_TIMEOUT_MS 30000 uint32_t timeout = TASK_TIMEOUT_MS; char openmv_buffer[128]; uint8_t openmv_index = 0; uint8_t rx_byte; uint8_t openmv_data_ready = 0; uint8_t task_selected = 0; PID_Controller speed_pid; PID_Controller angle_pid; KalmanFilter kf; // ???? typedef enum { TASK_SIMPLE_EXIT, TASK_SNAKE_PATH, TASK_CIRCLE_TWO_COLORS, TASK_COLUMN_SWAP, TASK_RANDOM_DETECT, TASK_DETECT_AND_PATH, TASK_NONE } TaskMode; TaskMode current_task = TASK_SIMPLE_EXIT; // ????? typedef enum { TASK_IDLE, TASK_DETECTING, TASK_PATH_PLANNING, TASK_EXECUTING, TASK_CIRCLE_COLUMN, TASK_COMPLETED, TASK_FAILED } TaskState; TaskState current_state = TASK_IDLE; // ????? typedef enum { MOVE_IDLE, MOVE_FORWARD, MOVE_TURNING, MOVE_CIRCLE } MoveState; MoveState move_state = MOVE_IDLE; // ?????? float current_x = 0.0f; float current_y = 0.0f; float current_angle = 0.0f; // ????? PathPlanner planner; // ???? void Detect_Cylinders(void); void Plan_Path(TaskMode task); void ExecuteStep(void); void Reset_Cylinders(void); float Calculate_Distance(int x1, int y1, int x2, int y2); void Parse_OpenMV_Data(void); /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ void StartMission(void); void ExecuteMission(TaskMode task); void SimpleExitPath(void); void SnakePath(void); void CircleTwoColors(void); void ColumnSwapPath(void); void RandomDetectPath(void); void AddCylinder(int x, int y, int r, char color); void BuildPath(char color); void AvoidObstacle(void); void Send_Debug_Info(void); void SensorFusion_Init(void); float SensorFusion_Update(float imu_yaw, float encoder_angle); void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart); /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart == &huart1) { if (rx_byte == '\n' || openmv_index >= sizeof(openmv_buffer) - 1) { openmv_buffer[openmv_index] = '\0'; openmv_index = 0; openmv_data_ready = 1; } else { openmv_buffer[openmv_index++] = rx_byte; } HAL_UART_Receive_IT(&huart1, &rx_byte, 1); } } void StartMission() { mission_running = 1; start_time = HAL_GetTick(); current_state = TASK_DETECTING; Reset_Cylinders(); } uint8_t IsMissionTimeout() { return (HAL_GetTick() - start_time) > timeout; } void AddCylinder(int x, int y, int r, char color) { if (cylinder_count < MAX_CYLINDERS) { cylinders[cylinder_count].x = x; cylinders[cylinder_count].y = y; cylinders[cylinder_count].r = r; cylinders[cylinder_count].color = color; cylinders[cylinder_count].visited = 0; cylinder_count++; } } void Reset_Cylinders() { for (int i = 0; i < cylinder_count; i++) { cylinders[i].visited = 0; } } float Calculate_Distance(int x1, int y1, int x2, int y2) { return sqrtf(powf(x2 - x1, 2) + powf(y2 - y1, 2)); } void Parse_OpenMV_Data(void) { char *token = strtok(openmv_buffer, ";"); cylinder_count = 0; while (token != NULL && cylinder_count < MAX_CYLINDERS) { int x, y, r; char color; if (sscanf(token, "%d,%d,%d,%c", &x, &y, &r, &color) == 4) { AddCylinder(x, y, r, color); } token = strtok(NULL, ";"); } } void Detect_Cylinders(void) { // ???? HAL_Delay(2000); AddCylinder(100, 200, 30, 'W'); AddCylinder(300, 150, 35, 'B'); printf("Detected %d cylinders.\r\n", cylinder_count); } void Plan_Path(TaskMode task) { // ?????? Path_Init(&planner); switch (task) { case TASK_SIMPLE_EXIT: Path_AddPoint(&planner, 0, 200, 0); Path_AddPoint(&planner, 300, 200, 1); break; case TASK_SNAKE_PATH: for (int i = 0; i < cylinder_count; i++) { Path_AddPoint(&planner, cylinders[i].x, cylinders[i].y, 1); } break; case TASK_CIRCLE_TWO_COLORS: Path_AddPoint(&planner, 100, 200, 2); Path_AddPoint(&planner, 300, 150, 2); break; } } void ExecuteStep(void) { static uint8_t step_index = 0; if (step_index < planner.count) { PathPoint *point = &planner.points[step_index]; if (point->type == 0) { Move_Forward(100); // ???? } else if (point->type == 1) { Turn_Right(90); // ?? } else { CircleColumn(step_index); // ?? } step_index++; } else { current_state = TASK_COMPLETED; } } void TaskMachine_Run() { switch (current_state) { case TASK_IDLE: if (mission_running) { current_state = TASK_DETECTING; } break; case TASK_DETECTING: if (openmv_data_ready) { Parse_OpenMV_Data(); openmv_data_ready = 0; current_state = TASK_PATH_PLANNING; } else if (IsMissionTimeout()) { current_state = TASK_FAILED; } break; case TASK_PATH_PLANNING: Plan_Path(current_task); current_state = TASK_EXECUTING; break; case TASK_EXECUTING: ExecuteStep(); AvoidObstacle(); // ???? break; case TASK_CIRCLE_COLUMN: CircleTwoColors(); current_state = TASK_COMPLETED; break; case TASK_COMPLETED: Motor_Stop(); mission_running = 0; current_state = TASK_IDLE; break; case TASK_FAILED: Motor_Stop(); printf("Mission Failed!\r\n"); mission_running = 0; current_state = TASK_IDLE; break; } if (IsMissionTimeout() && current_state != TASK_DETECTING) { current_state = TASK_FAILED; } } /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_UART_Receive_IT(&huart1, &rx_byte, 1); HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); HAL_TIM_Encoder_Start(&htim4, TIM_CHANNEL_ALL); JY61P_Init(&hi2c1); PID_Init(&speed_pid, 1.0f, 0.1f, 0.05f); PID_Init(&angle_pid, 2.0f, 0.0f, 0.1f); KalmanFilter_Init(&kf, 0.001f, 0.003f, 0.03f); HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); AddCylinder(100, 200, 30, 'W'); AddCylinder(300, 150, 35, 'B'); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_11) == GPIO_PIN_RESET) { HAL_Delay(20); if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_11) == GPIO_PIN_RESET) { StartMission(); while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_11) == GPIO_PIN_RESET); } } if (mission_running) { TaskMachine_Run(); } // ??????? float encoder_dist = Get_Total_Distance(); JY61P_Data imu_data; JY61P_Read_Attitude(&imu_data); float fused_yaw = KalmanFilter_Update(&kf, imu_data.yaw, imu_data.gz, 0.01f); // ?????? current_x += encoder_dist * cosf(fused_yaw * M_PI / 180.0f); current_y += encoder_dist * sinf(fused_yaw * M_PI / 180.0f); current_angle = fused_yaw; HAL_Delay(10); } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ gpio.c /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file gpio.c * @brief This file provides code for the configuration * of all used GPIO pins. ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "gpio.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /*----------------------------------------------------------------------------*/ /* Configure GPIO */ /*----------------------------------------------------------------------------*/ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /** Configure pins as * Analog * Input * Output * EVENT_OUT * EXTI */ void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /* Configure TB6612 Control Pins */ GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure PWM Pins (PB0, PB1) */ GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure Ultrasonic TRIG (PB2, PB4) */ GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_4; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure Ultrasonic ECHO (PB3, PB5) */ GPIO_InitStruct.Pin = GPIO_PIN_3 | GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure Start Button (PB11) */ GPIO_InitStruct.Pin = GPIO_PIN_11; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ i2c.c /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file i2c.c * @brief This file provides code for the configuration * of the I2C instances. ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "i2c.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ I2C_HandleTypeDef hi2c1; /* I2C1 init function */ void MX_I2C1_Init(void) { /* USER CODE BEGIN I2C1_Init 0 */ /* USER CODE END I2C1_Init 0 */ /* USER CODE BEGIN I2C1_Init 1 */ /* USER CODE END I2C1_Init 1 */ hi2c1.Instance = I2C1; hi2c1.Init.ClockSpeed = 400000; hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c1.Init.OwnAddress1 = 0; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c1.Init.OwnAddress2 = 0; hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; if (HAL_I2C_Init(&hi2c1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN I2C1_Init 2 */ /* USER CODE END I2C1_Init 2 */ } void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(i2cHandle->Instance==I2C1) { /* USER CODE BEGIN I2C1_MspInit 0 */ /* USER CODE END I2C1_MspInit 0 */ __HAL_RCC_GPIOB_CLK_ENABLE(); /**I2C1 GPIO Configuration PB8 ------> I2C1_SCL PB9 ------> I2C1_SDA */ GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); __HAL_AFIO_REMAP_I2C1_ENABLE(); /* I2C1 clock enable */ __HAL_RCC_I2C1_CLK_ENABLE(); /* USER CODE BEGIN I2C1_MspInit 1 */ /* USER CODE END I2C1_MspInit 1 */ } } void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle) { if(i2cHandle->Instance==I2C1) { /* USER CODE BEGIN I2C1_MspDeInit 0 */ /* USER CODE END I2C1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_I2C1_CLK_DISABLE(); /**I2C1 GPIO Configuration PB8 ------> I2C1_SCL PB9 ------> I2C1_SDA */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8); HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9); /* USER CODE BEGIN I2C1_MspDeInit 1 */ /* USER CODE END I2C1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ tim.c /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file tim.c * @brief This file provides code for the configuration * of the TIM instances. ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "tim.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim4; /* TIM2 init function */ void MX_TIM2_Init(void) { /* USER CODE BEGIN TIM2_Init 0 */ /* USER CODE END TIM2_Init 0 */ TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; /* USER CODE BEGIN TIM2_Init 1 */ /* USER CODE END TIM2_Init 1 */ htim2.Instance = TIM2; htim2.Init.Prescaler = 71; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 999; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) { Error_Handler(); } sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM2_Init 2 */ /* USER CODE END TIM2_Init 2 */ HAL_TIM_MspPostInit(&htim2); } /* TIM3 init function */ void MX_TIM3_Init(void) { /* USER CODE BEGIN TIM3_Init 0 */ /* USER CODE END TIM3_Init 0 */ TIM_Encoder_InitTypeDef sConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; /* USER CODE BEGIN TIM3_Init 1 */ /* USER CODE END TIM3_Init 1 */ htim3.Instance = TIM3; htim3.Init.Prescaler = 0; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 65535; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; sConfig.EncoderMode = TIM_ENCODERMODE_TI1; sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; sConfig.IC1Prescaler = TIM_ICPSC_DIV1; sConfig.IC1Filter = 0; sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; sConfig.IC2Prescaler = TIM_ICPSC_DIV1; sConfig.IC2Filter = 0; if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM3_Init 2 */ /* USER CODE END TIM3_Init 2 */ } /* TIM4 init function */ void MX_TIM4_Init(void) { /* USER CODE BEGIN TIM4_Init 0 */ /* USER CODE END TIM4_Init 0 */ TIM_Encoder_InitTypeDef sConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; /* USER CODE BEGIN TIM4_Init 1 */ /* USER CODE END TIM4_Init 1 */ htim4.Instance = TIM4; htim4.Init.Prescaler = 0; htim4.Init.CounterMode = TIM_COUNTERMODE_UP; htim4.Init.Period = 65535; htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; sConfig.EncoderMode = TIM_ENCODERMODE_TI1; sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; sConfig.IC1Prescaler = TIM_ICPSC_DIV1; sConfig.IC1Filter = 0; sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; sConfig.IC2Prescaler = TIM_ICPSC_DIV1; sConfig.IC2Filter = 0; if (HAL_TIM_Encoder_Init(&htim4, &sConfig) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM4_Init 2 */ /* USER CODE END TIM4_Init 2 */ } void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle) { if(tim_pwmHandle->Instance==TIM2) { /* USER CODE BEGIN TIM2_MspInit 0 */ /* USER CODE END TIM2_MspInit 0 */ /* TIM2 clock enable */ __HAL_RCC_TIM2_CLK_ENABLE(); /* USER CODE BEGIN TIM2_MspInit 1 */ /* USER CODE END TIM2_MspInit 1 */ } } void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* tim_encoderHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(tim_encoderHandle->Instance==TIM3) { /* USER CODE BEGIN TIM3_MspInit 0 */ /* USER CODE END TIM3_MspInit 0 */ /* TIM3 clock enable */ __HAL_RCC_TIM3_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**TIM3 GPIO Configuration PA6 ------> TIM3_CH1 PA7 ------> TIM3_CH2 */ GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* TIM3 interrupt Init */ HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TIM3_IRQn); /* USER CODE BEGIN TIM3_MspInit 1 */ /* USER CODE END TIM3_MspInit 1 */ } else if(tim_encoderHandle->Instance==TIM4) { /* USER CODE BEGIN TIM4_MspInit 0 */ /* USER CODE END TIM4_MspInit 0 */ /* TIM4 clock enable */ __HAL_RCC_TIM4_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /**TIM4 GPIO Configuration PB6 ------> TIM4_CH1 PB7 ------> TIM4_CH2 */ GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* TIM4 interrupt Init */ HAL_NVIC_SetPriority(TIM4_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TIM4_IRQn); /* USER CODE BEGIN TIM4_MspInit 1 */ /* USER CODE END TIM4_MspInit 1 */ } } void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(timHandle->Instance==TIM2) { /* USER CODE BEGIN TIM2_MspPostInit 0 */ /* USER CODE END TIM2_MspPostInit 0 */ __HAL_RCC_GPIOA_CLK_ENABLE(); /**TIM2 GPIO Configuration PA0-WKUP ------> TIM2_CH1 PA1 ------> TIM2_CH2 */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN TIM2_MspPostInit 1 */ /* USER CODE END TIM2_MspPostInit 1 */ } } void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* tim_pwmHandle) { if(tim_pwmHandle->Instance==TIM2) { /* USER CODE BEGIN TIM2_MspDeInit 0 */ /* USER CODE END TIM2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_TIM2_CLK_DISABLE(); /* USER CODE BEGIN TIM2_MspDeInit 1 */ /* USER CODE END TIM2_MspDeInit 1 */ } } void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* tim_encoderHandle) { if(tim_encoderHandle->Instance==TIM3) { /* USER CODE BEGIN TIM3_MspDeInit 0 */ /* USER CODE END TIM3_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_TIM3_CLK_DISABLE(); /**TIM3 GPIO Configuration PA6 ------> TIM3_CH1 PA7 ------> TIM3_CH2 */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6|GPIO_PIN_7); /* TIM3 interrupt Deinit */ HAL_NVIC_DisableIRQ(TIM3_IRQn); /* USER CODE BEGIN TIM3_MspDeInit 1 */ /* USER CODE END TIM3_MspDeInit 1 */ } else if(tim_encoderHandle->Instance==TIM4) { /* USER CODE BEGIN TIM4_MspDeInit 0 */ /* USER CODE END TIM4_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_TIM4_CLK_DISABLE(); /**TIM4 GPIO Configuration PB6 ------> TIM4_CH1 PB7 ------> TIM4_CH2 */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7); /* TIM4 interrupt Deinit */ HAL_NVIC_DisableIRQ(TIM4_IRQn); /* USER CODE BEGIN TIM4_MspDeInit 1 */ /* USER CODE END TIM4_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ usart.c /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file usart.c * @brief This file provides code for the configuration * of the USART instances. ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "usart.h" #include "stdio.h" #include "string.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ UART_HandleTypeDef huart1; /* USART1 init function */ void MX_USART1_UART_Init(void) { /* USER CODE BEGIN USART1_Init 0 */ /* USER CODE END USART1_Init 0 */ /* USER CODE BEGIN USART1_Init 1 */ /* USER CODE END USART1_Init 1 */ huart1.Instance = USART1; huart1.Init.BaudRate = 115200; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART1_Init 2 */ /* USER CODE END USART1_Init 2 */ } void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspInit 0 */ /* USER CODE END USART1_MspInit 0 */ /* USART1 clock enable */ __HAL_RCC_USART1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USART1 interrupt Init */ HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspInit 1 */ /* USER CODE END USART1_MspInit 1 */ } } void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspDeInit 0 */ /* USER CODE END USART1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART1_CLK_DISABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); /* USART1 interrupt Deinit */ HAL_NVIC_DisableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE END USART1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ void Send_Debug_Info(void) { char buffer[100]; sprintf(buffer, "Left: %.2f cm, Right: %.2f cm\r\n", Get_Left_Distance(), Get_Right_Distance()); HAL_UART_Transmit(&huart1, (uint8_t*)buffer, strlen(buffer), HAL_MAX_DELAY); } /* USER CODE END 1 */ motion.c #include "motion.h" #include "motor.h" #include "encoder.h" #include "jy61p.h" #include "pid.h" #include "stdio.h" #include <math.h> #ifndef M_PI #define M_PI 3.14159265358979323846 #endif extern Cylinder cylinders[MAX_CYLINDERS]; extern int cylinder_count; extern PID_Controller angle_pid; float current_x = 0.0f; float current_y = 0.0f; float current_angle = 0.0f; void Move_Forward(float distance) { float start_ticks = Get_Total_Distance(); float target_ticks = start_ticks + distance * 10.0f; Motor_Forward(80); while (Get_Total_Distance() < target_ticks) { HAL_Delay(10); } Motor_Stop(); } void Move_Backward(float distance) { float start_ticks = Get_Total_Distance(); float target_ticks = start_ticks + distance * 10.0f; Motor_Backward(80); while (Get_Total_Distance() < target_ticks) { HAL_Delay(10); } Motor_Stop(); } void Turn_Left(float angle) { JY61P_Data imu; JY61P_Read_Attitude(&imu); float target_yaw = imu.yaw - angle; if (target_yaw < -180.0f) target_yaw += 360.0f; Motor_Turn_Left(40); do { JY61P_Read_Attitude(&imu); HAL_Delay(10); } while (fabsf(imu.yaw - target_yaw) > 5.0f); Motor_Stop(); current_angle = target_yaw; } void Turn_Right(float angle) { JY61P_Data imu; JY61P_Read_Attitude(&imu); float target_yaw = imu.yaw + angle; if (target_yaw > 180.0f) target_yaw -= 360.0f; Motor_Turn_Right(40); do { JY61P_Read_Attitude(&imu); HAL_Delay(10); } while (fabsf(imu.yaw - target_yaw) > 5.0f); Motor_Stop(); current_angle = target_yaw; } void CircleColumn(int index) { float center_x = cylinders[index].x; float center_y = cylinders[index].y; float radius = cylinders[index].r + 15.0f; for (int i = 0; i < 36; i++) { float angle = current_angle + i * 10 * M_PI / 180.0f; float target_x = center_x + radius * cosf(angle); float target_y = center_y + radius * sinf(angle); float dist = sqrtf(powf(target_x - current_x, 2) + powf(target_y - current_y, 2)); float target_angle = atan2f(target_y - current_y, target_x - current_x) * 180.0f / M_PI; Turn_Right(target_angle - current_angle); Move_Forward(dist); } cylinders[index].visited = 1; } void Follow_Wall(float distance) { float wall_dist = Get_Left_Distance(); float start_x = current_x; float start_y = current_y; Motor_Forward(70); while (sqrtf(powf(current_x - start_x, 2) + powf(current_y - start_y, 2)) < distance) { float error = Get_Left_Distance() - wall_dist; float steer = PID_Update(&angle_pid, error, 0.01f); int left_speed = 70 + steer; int right_speed = 70 - steer; Motor_SetSpeed(left_speed, right_speed); HAL_Delay(10); } Motor_Stop(); } void AvoidObstacle() { float left = Get_Left_Distance(); float right = Get_Right_Distance(); if (left < 15 || right < 15) { Motor_Backward(10); if (left < right) { Turn_Right(60); } else { Turn_Left(60); } } } path_planner.c #include "path_planner.h" void Path_Init(PathPlanner *planner) { planner->count = 0; } void Path_AddPoint(PathPlanner *planner, int x, int y, uint8_t type) { if (planner->count < MAX_PATH_POINTS) { planner->points[planner->count].x = x; planner->points[planner->count].y = y; planner->points[planner->count].type = type; planner->count++; } } void Path_Generate(PathPlanner *planner, Cylinder *cylinders, uint8_t count, TaskMode task) { switch (task) { case TASK_SIMPLE_EXIT: Path_AddPoint(planner, 0, 200, 0); Path_AddPoint(planner, 300, 200, 1); break; case TASK_SNAKE_PATH: for (int i = 0; i < count; i++) { Path_AddPoint(planner, cylinders[i].x, cylinders[i].y, 1); } break; case TASK_CIRCLE_TWO_COLORS: Path_AddPoint(planner, 100, 200, 2); Path_AddPoint(planner, 300, 150, 2); break; } } uint8_t Path_Execute(PathPlanner *planner) { static uint8_t step_index = 0; if (step_index < planner->count) { PathPoint *point = &planner->points[step_index]; if (point->type == 0) { Move_Forward(100); } else if (point->type == 1) { Turn_Right(90); } else { CircleColumn(step_index); } step_index++; return 0; } else { step_index = 0; return 1; } } pid.c #include "pid.h" void PID_Init(PID_Controller *pid, float Kp, float Ki, float Kd) { pid->Kp = Kp; pid->Ki = Ki; pid->Kd = Kd; pid->integral = 0.0f; pid->last_error = 0.0f; } float PID_Update(PID_Controller *pid, float error, float dt) { pid->integral += error * dt; float derivative = (error - pid->last_error) / dt; float output = pid->Kp * error + pid->Ki * pid->integral + pid->Kd * derivative; pid->last_error = error; return output; } ultrasonic.c #include "ultrasonic.h" float Get_Left_Distance(void) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_SET); HAL_Delay(10); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET); uint32_t start = 0, end = 0; while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_3) == GPIO_PIN_RESET); start = htim3.Instance->CNT; while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_3) == GPIO_PIN_SET); end = htim3.Instance->CNT; return (end - start) * 0.034 / 2; } float Get_Right_Distance(void) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET); HAL_Delay(10); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET); uint32_t start = 0, end = 0; while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5) == GPIO_PIN_RESET); start = htim3.Instance->CNT; while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5) == GPIO_PIN_SET); end = htim3.Instance->CNT; return (end - start) * 0.034 / 2; } kalman_filter.c #include "kalman_filter.h" void KalmanFilter_Init(KalmanFilter *kf, float Q_angle, float Q_bias, float R_measure) { kf->Q_angle = Q_angle; kf->Q_bias = Q_bias; kf->R_measure = R_measure; kf->angle = 0.0f; kf->bias = 0.0f; kf->P[0][0] = 0.0f; kf->P[0][1] = 0.0f; kf->P[1][0] = 0.0f; kf->P[1][1] = 0.0f; } float KalmanFilter_Update(KalmanFilter *kf, float new_angle, float new_rate, float dt) { kf->rate = new_rate - kf->bias; kf->angle += dt * kf->rate; kf->P[0][0] += dt * (dt * kf->P[1][1] - kf->P[0][1] - kf->P[1][0] + kf->Q_angle); kf->P[0][1] -= dt * kf->P[1][1]; kf->P[1][0] -= dt * kf->P[1][1]; kf->P[1][1] += kf->Q_bias * dt; float y = new_angle - kf->angle; float S = kf->P[0][0] + kf->R_measure; float K0 = kf->P[0][0] / S; float K1 = kf->P[1][0] / S; kf->angle += K0 * y; kf->bias += K1 * y; float P00_temp = kf->P[0][0]; float P01_temp = kf->P[0][1]; kf->P[0][0] -= K0 * P00_temp; kf->P[0][1] -= K0 * P01_temp; kf->P[1][0] -= K1 * P00_temp; kf->P[1][1] -= K1 * P01_temp; return kf->angle; } motor.c #include "motor.h" void Motor_SetSpeed(int left, int right) { __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, left); __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, right); } void Motor_Forward(int speed) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); Motor_SetSpeed(speed, speed); } void Motor_Backward(int speed) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_SET); Motor_SetSpeed(speed, speed); } void Motor_Stop() { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); Motor_SetSpeed(0, 0); } void Motor_Turn_Left(int speed) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); Motor_SetSpeed(speed, speed); } void Motor_Turn_Right(int speed) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_SET); Motor_SetSpeed(speed, speed); } encoder.c #include "encoder.h" void Reset_Encoders(void) { htim3.Instance->CNT = 0; htim4.Instance->CNT = 0; } float Get_Total_Distance(void) { float left = htim3.Instance->CNT * 0.1f; float right = htim4.Instance->CNT * 0.1f; return (left + right) / 2.0f; } float Get_Left_Encoder(void) { return htim3.Instance->CNT * 0.1f; } float Get_Right_Encoder(void) { return htim4.Instance->CNT * 0.1f; } jy61p.c #include "jy61p.h" #include "main.h" extern I2C_HandleTypeDef hi2c1; #define JY61P_ADDR 0x50 << 1 void JY61P_Init(I2C_HandleTypeDef *hi2c) { // ³õʼ»¯ } void JY61P_Read_Attitude(JY61P_Data *data) { uint8_t buf[6]; HAL_I2C_Mem_Read(&hi2c1, JY61P_ADDR, 0x56, 1, buf, 6, HAL_MAX_DELAY); data->pitch = (int16_t)(buf[0] << 8 | buf[1]) / 32768.0f * 180; data->roll = (int16_t)(buf[2] << 8 | buf[3]) / 32768.0f * 180; data->yaw = (int16_t)(buf[4] << 8 | buf[5]) / 32768.0f * 180; }

大家在看

recommend-type

金蝶EAS通过套打模板实现后台生成PDF文件.docx

在EAS开发中,如果需要合同调用套打模板自动生成PDF进行档案归档备份,可通过后台服务器代码进行开发实现;
recommend-type

复盛压缩机选型软件.rar )

此款为官方专用,简单的压缩机可以选择。SRL型的没有,暂时不能使用请谨慎选择
recommend-type

基于边折叠的网格快速简化

Fast mesh simplification via edge collapsing This project contains an implementation of a "multiple choice" mesh simplfication algorithm. Over a number of iterations a random fraction of the total edges in the supplied mesh are processed with a subset of these processed edges collapsed (the lowest scoring collapses win when a collision occurs). The only non-standard dependency is the qef_simd.h single file header which you can find in my "qef" project, a version is also included here.
recommend-type

20201107-为rvv-llvm添加一个intrinsic-廖春玉1

3. multiclass signed_binary_v_vv_vx { 4. multiclass Binary<string name,/ string
recommend-type

一种低噪声便携式的心电监测仪设计

便携式监护仪小型方便,结构简单,性能稳定,可以随身携带,可由电池供电,一般用于非监护室及外出抢救病人的监护。心血管疾病是人类生命的最主要威胁之一,而心电(Electrocardiogram,ECG信号是诊断心血管疾病的主要依据,因此实时监测病人心电活动,设计自动采集病人心电信号的便携式系统具有重要意义。本文为人体日常生活方便,设计了导联电极脱落检测电路,防止运动输入电极脱落。

最新推荐

recommend-type

有限公司成立合作协议书.doc

有限公司成立合作协议书.doc
recommend-type

mpu9650STM32f103c8t6例程

mpu9650STM32f103c8t6例程
recommend-type

1754823429242.jpeg

1754823429242.jpeg
recommend-type

工业自动化领域欧姆龙Sysmac Studio NJ101-1000与R88D-KN01H伺服控制系统实现

欧姆龙Sysmac Studio环境下NJ101-1000控制器与R88D-KN01H伺服电机的编程实现方法。首先概述了硬件特点及其应用场景,接着深入探讨了输入信号(如使能输入、点动控制、回原点模式)、输出信号(如使能状态、故障信息、速度和位置反馈)的具体配置方式。文中还重点讲解了如何利用Sysmac Studio提供的打包块功能简化编程流程,确保各模式间的互斥性和安全性,并给出了简单示例代码展示点动正转功能的实现。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是那些希望深入了解欧姆龙伺服系统编程的人士。 使用场景及目标:适用于需要对NJ101-1000和R88D-KN01H系列伺服进行精准控制的应用场合,如生产线自动化、机器人运动控制等。目的是帮助读者掌握伺服系统的配置技巧,提高工作效率和产品质量。 其他说明:文中强调了编程过程中需要注意的关键点,比如不同模式之间的切换逻辑、速度设定的选择依据等,有助于读者更好地理解和应用相关技术。同时提醒读者,在实际项目中应根据具体需求灵活调整参数设置。
recommend-type

已解密-技术服务协议.docx

已解密-技术服务协议.docx
recommend-type

Python程序TXLWizard生成TXL文件及转换工具介绍

### 知识点详细说明: #### 1. 图形旋转与TXL向导 图形旋转是图形学领域的一个基本操作,用于改变图形的方向。在本上下文中,TXL向导(TXLWizard)是由Esteban Marin编写的Python程序,它实现了特定的图形旋转功能,主要用于电子束光刻掩模的生成。光刻掩模是半导体制造过程中非常关键的一个环节,它确定了在硅片上沉积材料的精确位置。TXL向导通过生成特定格式的TXL文件来辅助这一过程。 #### 2. TXL文件格式与用途 TXL文件格式是一种基于文本的文件格式,它设计得易于使用,并且可以通过各种脚本语言如Python和Matlab生成。这种格式通常用于电子束光刻中,因为它的文本形式使得它可以通过编程快速创建复杂的掩模设计。TXL文件格式支持引用对象和复制对象数组(如SREF和AREF),这些特性可以用于优化电子束光刻设备的性能。 #### 3. TXLWizard的特性与优势 - **结构化的Python脚本:** TXLWizard 使用结构良好的脚本来创建遮罩,这有助于开发者创建清晰、易于维护的代码。 - **灵活的Python脚本:** 作为Python程序,TXLWizard 可以利用Python语言的灵活性和强大的库集合来编写复杂的掩模生成逻辑。 - **可读性和可重用性:** 生成的掩码代码易于阅读,开发者可以轻松地重用和修改以适应不同的需求。 - **自动标签生成:** TXLWizard 还包括自动为图形对象生成标签的功能,这在管理复杂图形时非常有用。 #### 4. TXL转换器的功能 - **查看.TXL文件:** TXL转换器(TXLConverter)允许用户将TXL文件转换成HTML或SVG格式,这样用户就可以使用任何现代浏览器或矢量图形应用程序来查看文件。 - **缩放和平移:** 转换后的文件支持缩放和平移功能,这使得用户在图形界面中更容易查看细节和整体结构。 - **快速转换:** TXL转换器还提供快速的文件转换功能,以实现有效的蒙版开发工作流程。 #### 5. 应用场景与技术参考 TXLWizard的应用场景主要集中在电子束光刻技术中,特别是用于设计和制作半导体器件时所需的掩模。TXLWizard作为一个向导,不仅提供了生成TXL文件的基础框架,还提供了一种方式来优化掩模设计,提高光刻过程的效率和精度。对于需要进行光刻掩模设计的工程师和研究人员来说,TXLWizard提供了一种有效的方法来实现他们的设计目标。 #### 6. 系统开源特性 标签“系统开源”表明TXLWizard遵循开放源代码的原则,这意味着源代码对所有人开放,允许用户自由地查看、修改和分发软件。开源项目通常拥有活跃的社区,社区成员可以合作改进软件,添加新功能,或帮助解决遇到的问题。这种开放性促进了技术创新,并允许用户根据自己的需求定制软件。 #### 7. 压缩包子文件的文件名称列表 文件名称列表中的“txlwizard-master”可能指的是TXLWizard项目的主版本库或主分支。这个名称表明了这是项目源代码的中心点,其他开发者会从这个主分支拉取代码进行合作开发或部署。以“-master”结尾通常是版本控制系统中表示主要开发线路的常见约定,例如Git中的master(现在更常被称为main)分支。 通过这些知识点的详细解释,我们可以看到TXLWizard不仅是一个用于生成TXL文件的工具,它还整合了一系列的功能,使得电子束光刻掩模的设计工作更为高效和直观。同时,作为一个开源项目,它能够借助社区的力量不断进步,为用户带来更多的便利和创新。
recommend-type

【创新图生成:扣子平台的技术前沿与创新思维】:引领图像生成技术的新潮流

# 1. 扣子平台的图像生成技术概述 在当今数字化时代,图像生成技术正成为推动技术创新和社会变革的关键力量。扣子平台正是这一技术革新的代表。本章将对扣子平台的图像生成技术进行一个全面概述,探究它如何将理论技术转化为实际应用,并带来显著的社会影响。 扣子平台运用了先进的图像生成技术,将现实世界和数字空间无缝融合,打造了沉浸式的视觉体验。其技术的核心是通过高度复杂的算法模型,快速生成高质
recommend-type

海康威视机器视觉工程师考核

<think>好的,我现在需要帮助用户了解海康威视机器视觉工程师的考核内容和要求。根据用户提供的引用资料,特别是引用[1]和[2],里面提到了考核素材包分为初级和中级,涵盖理论、算法、应用案例等。首先,我要整理这些信息,确保结构清晰,符合用户要求的格式。 接下来,我需要确认素材包的具体内容,比如初级和中级的不同点。引用[2]提到初级包含基础理论、算法实现和实际案例,中级则增加复杂算法和项目分析。这部分需要分点说明,方便用户理解层次。 另外,用户可能想知道如何准备考核,比如下载素材、学习顺序、模拟考核等,引用[2]中有使用说明和注意事项,这部分也要涵盖进去。同时要注意提醒用户考核窗口已关闭,
recommend-type

Linux环境下Docker Hub公共容器映像检测工具集

在给出的知识点中,我们需要详细解释有关Docker Hub、公共容器映像、容器编排器以及如何与这些工具交互的详细信息。同时,我们会涵盖Linux系统下的相关操作和工具使用,以及如何在ECS和Kubernetes等容器编排工具中运用这些检测工具。 ### Docker Hub 和公共容器映像 Docker Hub是Docker公司提供的一项服务,它允许用户存储、管理以及分享Docker镜像。Docker镜像可以视为应用程序或服务的“快照”,包含了运行特定软件所需的所有必要文件和配置。公共容器映像指的是那些被标记为公开可见的Docker镜像,任何用户都可以拉取并使用这些镜像。 ### 静态和动态标识工具 静态和动态标识工具在Docker Hub上用于识别和分析公共容器映像。静态标识通常指的是在不运行镜像的情况下分析镜像的元数据和内容,例如检查Dockerfile中的指令、环境变量、端口映射等。动态标识则需要在容器运行时对容器的行为和性能进行监控和分析,如资源使用率、网络通信等。 ### 容器编排器与Docker映像 容器编排器是用于自动化容器部署、管理和扩展的工具。在Docker环境中,容器编排器能够自动化地启动、停止以及管理容器的生命周期。常见的容器编排器包括ECS和Kubernetes。 - **ECS (Elastic Container Service)**:是由亚马逊提供的容器编排服务,支持Docker容器,并提供了一种简单的方式来运行、停止以及管理容器化应用程序。 - **Kubernetes**:是一个开源平台,用于自动化容器化应用程序的部署、扩展和操作。它已经成为容器编排领域的事实标准。 ### 如何使用静态和动态标识工具 要使用这些静态和动态标识工具,首先需要获取并安装它们。从给定信息中了解到,可以通过克隆仓库或下载压缩包并解压到本地系统中。之后,根据需要针对不同的容器编排环境(如Dockerfile、ECS、Kubernetes)编写配置,以集成和使用这些检测工具。 ### Dockerfile中的工具使用 在Dockerfile中使用工具意味着将检测工具的指令嵌入到构建过程中。这可能包括安装检测工具的命令、运行容器扫描的步骤,以及将扫描结果集成到镜像构建流程中,确保只有通过安全和合规检查的容器镜像才能被构建和部署。 ### ECS与Kubernetes中的工具集成 在ECS或Kubernetes环境中,工具的集成可能涉及到创建特定的配置文件、定义服务和部署策略,以及编写脚本或控制器来自动执行检测任务。这样可以在容器编排的过程中实现实时监控,确保容器编排器只使用符合预期的、安全的容器镜像。 ### Linux系统下的操作 在Linux系统下操作这些工具,用户可能需要具备一定的系统管理和配置能力。这包括使用Linux命令行工具、管理文件系统权限、配置网络以及安装和配置软件包等。 ### 总结 综上所述,Docker Hub上的静态和动态标识工具提供了一种方法来检测和分析公共容器映像,确保这些镜像的安全性和可靠性。这些工具在Linux开发环境中尤为重要,因为它们帮助开发人员和运维人员确保他们的容器映像满足安全要求。通过在Dockerfile、ECS和Kubernetes中正确使用这些工具,可以提高应用程序的安全性,减少由于使用不安全的容器镜像带来的风险。此外,掌握Linux系统下的操作技能,可以更好地管理和维护这些工具,确保它们能够有效地发挥作用。
recommend-type

【扣子平台图像艺术探究:理论与实践的完美结合】:深入学习图像生成的艺术

# 1. 图像艺术的理论基础 艺术领域的每一个流派和技巧都有其理论基础。在图像艺术中,理论基础不仅是对艺术表现形式的认知,也是掌握艺术创作内在逻辑的关键。深入理解图像艺术的理论基础,能够帮助艺术家们在创作过程中更加明确地表达自己的艺术意图,以及更好地与观众沟通。 图像艺术的理论