合并:完善小车巡线运动
This commit is contained in:
parent
2efc1e8375
commit
bb23d452ca
|
@ -44,7 +44,7 @@ void LINESEEK_HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
|
||||||
|
|
||||||
if (beep_time++ > 100)
|
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;
|
beep_time = 0;
|
||||||
buzzer(1);
|
HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_RESET);
|
||||||
// state = MOVE_STRAIGHT;
|
// state = MOVE_STRAIGHT;
|
||||||
// buzzer(1);
|
// buzzer(1);
|
||||||
// HAL_Delay(50);
|
// HAL_Delay(50);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "hcsr04.h"
|
#include "hcsr04.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
#include "path_plan.h"
|
||||||
|
|
||||||
#define BLOCK_DISTANCE 150
|
#define BLOCK_DISTANCE 150
|
||||||
|
|
||||||
|
|
|
@ -106,10 +106,6 @@ void Error_Handler(void);
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
#define LOW (0)
|
#define LOW (0)
|
||||||
#define HIGH (1)
|
#define HIGH (1)
|
||||||
#define LEFT (0)
|
|
||||||
#define STRAIGHT (1)
|
|
||||||
#define RIGHT (2)
|
|
||||||
#define STOP (3)
|
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -57,9 +57,9 @@ void PendSV_Handler(void);
|
||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
void DMA1_Channel6_IRQHandler(void);
|
void DMA1_Channel6_IRQHandler(void);
|
||||||
void TIM2_IRQHandler(void);
|
void TIM2_IRQHandler(void);
|
||||||
void USART1_IRQHandler(void);
|
|
||||||
void TIM3_IRQHandler(void);
|
void TIM3_IRQHandler(void);
|
||||||
void TIM4_IRQHandler(void);
|
void TIM4_IRQHandler(void);
|
||||||
|
void USART1_IRQHandler(void);
|
||||||
void USART2_IRQHandler(void);
|
void USART2_IRQHandler(void);
|
||||||
void EXTI15_10_IRQHandler(void);
|
void EXTI15_10_IRQHandler(void);
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|
|
@ -102,11 +102,12 @@ int main(void)
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_DMA_Init();
|
MX_DMA_Init();
|
||||||
MX_I2C2_Init();
|
MX_I2C2_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
MX_TIM2_Init();
|
MX_TIM2_Init();
|
||||||
MX_TIM3_Init();
|
MX_TIM3_Init();
|
||||||
MX_TIM4_Init();
|
MX_TIM4_Init();
|
||||||
// MX_USART2_UART_Init();
|
|
||||||
MX_USART1_UART_Init();
|
MX_USART1_UART_Init();
|
||||||
|
// MX_USART2_UART_Init();
|
||||||
|
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
HC_SR04_Init();
|
HC_SR04_Init();
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
/* USER CODE BEGIN Header */
|
/* USER CODE BEGIN Header */
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file stm32f1xx_it.c
|
* @file stm32f1xx_it.c
|
||||||
* @brief Interrupt Service Routines.
|
* @brief Interrupt Service Routines.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 STMicroelectronics.
|
* Copyright (c) 2024 STMicroelectronics.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
* in the root directory of this software component.
|
* in the root directory of this software component.
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
@ -77,9 +77,9 @@ void NMI_Handler(void)
|
||||||
|
|
||||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
/* USER CODE END NonMaskableInt_IRQn 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.
|
* @brief This function handles TIM3 global interrupt.
|
||||||
*/
|
*/
|
||||||
void TIM3_IRQHandler(void)
|
void TIM3_IRQHandler(void)
|
||||||
|
@ -270,6 +259,20 @@ void TIM4_IRQHandler(void)
|
||||||
/* USER CODE END TIM4_IRQn 1 */
|
/* 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.
|
* @brief This function handles USART2 global interrupt.
|
||||||
*/
|
*/
|
||||||
|
|
24
Makefile
24
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 \
|
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
||||||
Core/Src/system_stm32f1xx.c \
|
Core/Src/system_stm32f1xx.c \
|
||||||
Core/Src/sysmem.c \
|
Core/Src/sysmem.c \
|
||||||
User/Src/hcsr04.c \
|
Peripheral/Src/hcsr04.c \
|
||||||
User/Src/motor.c \
|
Peripheral/Src/motor.c \
|
||||||
User/Src/led.c \
|
Peripheral/Src/led.c \
|
||||||
User/Src/bluetooth.c \
|
Peripheral/Src/bluetooth.c \
|
||||||
User/Src/control.c \
|
Peripheral/Src/control.c \
|
||||||
User/Src/line_seek.c \
|
Peripheral/Src/line_seek.c \
|
||||||
User/Src/path_plan.c \
|
Peripheral/Src/path_plan.c \
|
||||||
App/Src/app_line_seek.c
|
Peripheral/Src/servo.c \
|
||||||
|
Peripheral/Src/infrared.c \
|
||||||
|
App/Src/app_line_seek.c \
|
||||||
|
App/Src/app_ultrasonic.c
|
||||||
|
|
||||||
|
|
||||||
# ASM sources
|
# ASM sources
|
||||||
ASM_SOURCES = \
|
ASM_SOURCES = \
|
||||||
|
@ -130,7 +134,7 @@ AS_INCLUDES =
|
||||||
# C includes
|
# C includes
|
||||||
C_INCLUDES = \
|
C_INCLUDES = \
|
||||||
-ICore/Inc \
|
-ICore/Inc \
|
||||||
-IUser/Inc \
|
-IPeripheral/Inc \
|
||||||
-IApp/Inc \
|
-IApp/Inc \
|
||||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||||
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
||||||
|
|
|
@ -78,7 +78,7 @@ void CONTROL_Mode(uint8_t new_mode, uint8_t state)
|
||||||
case MODE_REMOTE:
|
case MODE_REMOTE:
|
||||||
speed = 20;
|
speed = 20;
|
||||||
MOTOR_SetDuty(speed, speed);
|
MOTOR_SetDuty(speed, speed);
|
||||||
MOTOR_Start();
|
MOTOR_Init();
|
||||||
break;
|
break;
|
||||||
case MODE_PATROL:
|
case MODE_PATROL:
|
||||||
break;
|
break;
|
||||||
|
@ -98,7 +98,7 @@ void carMove(uint8_t state)
|
||||||
MOTOR_Stop();
|
MOTOR_Stop();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MOTOR_Start();
|
MOTOR_Init();
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
// 前进
|
// 前进
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user