diff --git a/App/Src/app_line_seek.c b/App/Src/app_line_seek.c index 4d99641..5e1e5ae 100644 --- a/App/Src/app_line_seek.c +++ b/App/Src/app_line_seek.c @@ -44,7 +44,7 @@ void LINESEEK_HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) if (beep_time++ > 100) { - buzzer(0); + HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_SET); } } @@ -255,7 +255,7 @@ void Hanlde_Crossroad(void) } beep_time = 0; - buzzer(1); + HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_RESET); // state = MOVE_STRAIGHT; // buzzer(1); // HAL_Delay(50); diff --git a/App/Src/app_ultrasonic.c b/App/Src/app_ultrasonic.c index 724a251..2a2e5c2 100644 --- a/App/Src/app_ultrasonic.c +++ b/App/Src/app_ultrasonic.c @@ -3,6 +3,7 @@ #include "hcsr04.h" #include "main.h" #include "led.h" +#include "path_plan.h" #define BLOCK_DISTANCE 150 diff --git a/Core/Inc/main.h b/Core/Inc/main.h index afa8e32..d01cff8 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -106,10 +106,6 @@ void Error_Handler(void); /* USER CODE BEGIN Private defines */ #define LOW (0) #define HIGH (1) -#define LEFT (0) -#define STRAIGHT (1) -#define RIGHT (2) -#define STOP (3) /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/Core/Inc/stm32f1xx_it.h b/Core/Inc/stm32f1xx_it.h index 3f1ab9b..64ba1a0 100644 --- a/Core/Inc/stm32f1xx_it.h +++ b/Core/Inc/stm32f1xx_it.h @@ -57,9 +57,9 @@ void PendSV_Handler(void); void SysTick_Handler(void); void DMA1_Channel6_IRQHandler(void); void TIM2_IRQHandler(void); -void USART1_IRQHandler(void); void TIM3_IRQHandler(void); void TIM4_IRQHandler(void); +void USART1_IRQHandler(void); void USART2_IRQHandler(void); void EXTI15_10_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/Core/Src/main.c b/Core/Src/main.c index de33485..883b377 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -102,11 +102,12 @@ int main(void) MX_GPIO_Init(); MX_DMA_Init(); MX_I2C2_Init(); + MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); - // MX_USART2_UART_Init(); MX_USART1_UART_Init(); + // MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ HC_SR04_Init(); diff --git a/Core/Src/stm32f1xx_it.c b/Core/Src/stm32f1xx_it.c index 748479e..fb7ced6 100644 --- a/Core/Src/stm32f1xx_it.c +++ b/Core/Src/stm32f1xx_it.c @@ -1,20 +1,20 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32f1xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32f1xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2024 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 ------------------------------------------------------------------*/ @@ -77,9 +77,9 @@ void NMI_Handler(void) /* USER CODE END NonMaskableInt_IRQn 0 */ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - while (1) - { - } + while (1) + { + } /* USER CODE END NonMaskableInt_IRQn 1 */ } @@ -232,17 +232,6 @@ void TIM2_IRQHandler(void) } /** - * @brief This function handles USART1 global interrupt. - */ -void USART1_IRQHandler(void) -{ - /* USER CODE BEGIN USART1_IRQn 0 */ - - /* USER CODE END USART1_IRQn 0 */ - HAL_UART_IRQHandler(&huart1); - /* USER CODE BEGIN USART1_IRQn 1 */ - - /* USER CODE END USART1_IRQn 1 */ * @brief This function handles TIM3 global interrupt. */ void TIM3_IRQHandler(void) @@ -270,6 +259,20 @@ void TIM4_IRQHandler(void) /* USER CODE END TIM4_IRQn 1 */ } +/** + * @brief This function handles USART1 global interrupt. + */ +void USART1_IRQHandler(void) +{ + /* USER CODE BEGIN USART1_IRQn 0 */ + + /* USER CODE END USART1_IRQn 0 */ + HAL_UART_IRQHandler(&huart1); + /* USER CODE BEGIN USART1_IRQn 1 */ + + /* USER CODE END USART1_IRQn 1 */ +} + /** * @brief This function handles USART2 global interrupt. */ diff --git a/Core/Src/tim.c b/Core/Src/tim.c index a263420..72c4bcd 100644 --- a/Core/Src/tim.c +++ b/Core/Src/tim.c @@ -218,7 +218,7 @@ void MX_TIM4_Init(void) htim4.Instance = TIM4; htim4.Init.Prescaler = 720 - 1; htim4.Init.CounterMode = TIM_COUNTERMODE_UP; - htim4.Init.Period = 100; + htim4.Init.Period = 100; htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; if (HAL_TIM_Base_Init(&htim4) != HAL_OK) diff --git a/Makefile b/Makefile index fe629d7..3b62267 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [4.4.0-B60] date: [Tue Jul 16 20:05:56 CST 2024] +# File automatically-generated by tool: [projectgenerator] version: [4.4.0-B60] date: [Wed Jul 17 21:44:09 CST 2024] ########################################################################################################################## # ------------------------------------------------ @@ -62,14 +62,18 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \ Core/Src/system_stm32f1xx.c \ Core/Src/sysmem.c \ -User/Src/hcsr04.c \ -User/Src/motor.c \ -User/Src/led.c \ -User/Src/bluetooth.c \ -User/Src/control.c \ -User/Src/line_seek.c \ -User/Src/path_plan.c \ -App/Src/app_line_seek.c +Peripheral/Src/hcsr04.c \ +Peripheral/Src/motor.c \ +Peripheral/Src/led.c \ +Peripheral/Src/bluetooth.c \ +Peripheral/Src/control.c \ +Peripheral/Src/line_seek.c \ +Peripheral/Src/path_plan.c \ +Peripheral/Src/servo.c \ +Peripheral/Src/infrared.c \ +App/Src/app_line_seek.c \ +App/Src/app_ultrasonic.c + # ASM sources ASM_SOURCES = \ @@ -130,7 +134,7 @@ AS_INCLUDES = # C includes C_INCLUDES = \ -ICore/Inc \ --IUser/Inc \ +-IPeripheral/Inc \ -IApp/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \ diff --git a/Peripheral/Src/control.c b/Peripheral/Src/control.c index 9765e99..e5afd94 100644 --- a/Peripheral/Src/control.c +++ b/Peripheral/Src/control.c @@ -78,7 +78,7 @@ void CONTROL_Mode(uint8_t new_mode, uint8_t state) case MODE_REMOTE: speed = 20; MOTOR_SetDuty(speed, speed); - MOTOR_Start(); + MOTOR_Init(); break; case MODE_PATROL: break; @@ -98,7 +98,7 @@ void carMove(uint8_t state) MOTOR_Stop(); else { - MOTOR_Start(); + MOTOR_Init(); switch (state) { // 前进 diff --git a/User/Inc/path_plan.h b/User/Inc/path_plan.h deleted file mode 100644 index 3cb03cd..0000000 --- a/User/Inc/path_plan.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __PATH_PLAN_H -#define __PATH_PLAN_H - -// 定义方向枚举 -typedef enum -{ - STRAIGHT, - LEFT, - RIGHT, - STOP -} Direction; - -// 定义路径规划器结构 -typedef struct -{ - int currentStep; - Direction* path; - int pathLength; -} PathPlanner; - -// 全局路径规划器 -extern PathPlanner pathPlanner; - -void PathPlanner_Init(); -Direction GetCurrentDirection(); -Direction GetNextDirection(); -void AddPathStep(Direction step); - -#endif