✨ feat: 公交车
This commit is contained in:
parent
4c9cae72e0
commit
e70663edb3
|
@ -7,7 +7,7 @@ HeaderPath=..\Drivers\STM32F1xx_HAL_Driver\Inc;..\Drivers\STM32F1xx_HAL_Driver\I
|
|||
CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER;
|
||||
|
||||
[PreviousUsedMakefileFiles]
|
||||
SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\dma.c;Core\Src\i2c.c;Core\Src\tim.c;Core\Src\usart.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_i2c.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_i2c.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;;;
|
||||
SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\dma.c;Core\Src\tim.c;Core\Src\usart.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;;;
|
||||
HeaderPath=Drivers\STM32F1xx_HAL_Driver\Inc;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;Drivers\CMSIS\Device\ST\STM32F1xx\Include;Drivers\CMSIS\Include;Core\Inc;
|
||||
CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER;
|
||||
|
||||
|
|
8
App/Inc/app_bus.h
Normal file
8
App/Inc/app_bus.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __APP_BUS_H
|
||||
#define __APP_BUS_H
|
||||
|
||||
void BlockDetect_Init();
|
||||
void App_Bus(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -3,8 +3,13 @@
|
|||
|
||||
#include "tim.h"
|
||||
|
||||
extern int beep_time;
|
||||
|
||||
void LineSeek_Init(void);
|
||||
void LineSeek_Start(void);
|
||||
void LineSeek_Stop(void);
|
||||
void App_LineSeek(void);
|
||||
void Hanlde_Crossroad(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
98
App/Src/app_bus.c
Normal file
98
App/Src/app_bus.c
Normal file
|
@ -0,0 +1,98 @@
|
|||
#include "app_bus.h"
|
||||
|
||||
#include "app_line_seek.h"
|
||||
#include "block_detect.h"
|
||||
#include "buzzer.h"
|
||||
#include "led.h"
|
||||
#include "line_seek.h"
|
||||
#include "motor.h"
|
||||
#include "path_plan.h"
|
||||
#include "syn6288.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RUNNING, // 按路线运营
|
||||
READY_TO_PARK, // 准备进站停车(或者准备左转)
|
||||
PARKING, // 进站停车
|
||||
WAIT_PASSENGER, // 等候乘客
|
||||
STOP // 停车
|
||||
} BusState;
|
||||
|
||||
static BusState state;
|
||||
|
||||
static int current_station;
|
||||
char* stations[] = {"太平园站", "西南交大站", "新业北街站", "终点站"};
|
||||
|
||||
void App_Bus(void)
|
||||
{
|
||||
// printf("bus_state:%d\n", state);
|
||||
|
||||
LineSeek_GetStatusStr();
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case RUNNING: // 按路线运营
|
||||
{
|
||||
LineSeek_Start();
|
||||
if (Has_Block(FRONT)) // 前方有障碍物,停车
|
||||
{
|
||||
state = STOP;
|
||||
}
|
||||
else if (Has_Block(RIGHT_FRONT)) // 右前方有障碍物,准备停车或者左转避障
|
||||
{
|
||||
state = READY_TO_PARK;
|
||||
// state = WAIT_PASSENGER;
|
||||
}
|
||||
else if (Has_Block(LEFT_FRONT)) // 左前方有障碍物,右转避障
|
||||
{
|
||||
Direction nextDirs[] = {RIGHT, RIGHT};
|
||||
ReplacePathStep(nextDirs, 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case READY_TO_PARK: // 准备进站停车,或者准备左转避障
|
||||
{
|
||||
if (LineSeek_Equals("0xxx")) // 左方有路线,左转
|
||||
{
|
||||
Direction nextDirs[] = {LEFT, LEFT};
|
||||
ReplacePathStep(nextDirs, 2);
|
||||
state = RUNNING;
|
||||
}
|
||||
else if (LineSeek_Equals("xxx0")) // 右方有路线,右转进站
|
||||
{
|
||||
Direction nextDirs[] = {RIGHT, RIGHT};
|
||||
ReplacePathStep(nextDirs, 2);
|
||||
state = PARKING;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PARKING: // 进站停车
|
||||
{
|
||||
if (Has_Block(RIGHT_FRONT)) // 右前方有障碍物,停车
|
||||
{
|
||||
state = WAIT_PASSENGER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WAIT_PASSENGER: // 等候乘客
|
||||
{
|
||||
// TODO: 添加乘客等待逻辑
|
||||
LineSeek_Stop();
|
||||
SYN_FrameInfo(0, stations[current_station]);
|
||||
BUZZER_StartNTimes(3, 500, 500);
|
||||
MOTOR_Stop();
|
||||
HAL_Delay(5000);
|
||||
current_station++;
|
||||
state = RUNNING;
|
||||
break;
|
||||
}
|
||||
case STOP: // 停车
|
||||
{
|
||||
LineSeek_Stop();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
App_LineSeek();
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
#include "app_line_seek.h"
|
||||
|
||||
#include "bluetooth.h"
|
||||
#include "buzzer.h"
|
||||
#include "led.h"
|
||||
#include "line_seek.h"
|
||||
#include "main.h"
|
||||
#include "motor.h"
|
||||
|
@ -8,16 +11,15 @@
|
|||
#include "stm32f1xx_hal_tim.h"
|
||||
#include "syscalls.h"
|
||||
#include "tim.h"
|
||||
#include "timer.h"
|
||||
|
||||
#define LOW_TUNE_SPEED -5
|
||||
#define LOW_SPEED 35
|
||||
#define MID_SPEED 40
|
||||
#define HIGH_SPEED 45
|
||||
#define MIN_TURN_TIME 300 // 最小转直角时间
|
||||
#define MIN_CROSSING_TIME 200 // 最小走十字路口时间
|
||||
#define MIN_CROSSING_STRAIGHT_TIME 50 // 最小走十字路口时间
|
||||
#define MIN_TUNE_TIME 40 // 最小微调时间
|
||||
#define MAX_TURN_TIME 4000 // 最大转弯时间
|
||||
#define MIN_TURN_TIME 200 // 最小转直角时间
|
||||
#define MIN_CROSSING_TIME 300 // 最小走十字路口时间
|
||||
#define MIN_TUNE_TIME 30 // 最小微调时间
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -27,41 +29,53 @@ typedef enum
|
|||
TUNE_LEFT, // 左微调
|
||||
TUNE_RIGHT, // 右微调
|
||||
TURN_LEFT_BIG,
|
||||
TURN_RIGHT_BIG
|
||||
TURN_RIGHT_BIG,
|
||||
MOVE_STOP
|
||||
} MoveState;
|
||||
|
||||
MoveState state, preState; // 运动状态
|
||||
static MoveState state, preState; // 运动状态
|
||||
int turn_time; // 转弯时间
|
||||
int beep_time; // 蜂鸣器鸣叫时间
|
||||
int is_crossing; // 是否正在走十字路口
|
||||
static timer_event_id = -1;
|
||||
|
||||
void LINESEEK_HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
|
||||
// 每1ms一次回调
|
||||
void LINESEEK_TURN_TIME()
|
||||
{
|
||||
if (turn_time < INT16_MAX)
|
||||
{
|
||||
turn_time++; // 每1ms自增一
|
||||
}
|
||||
|
||||
if (beep_time++ > 100)
|
||||
{
|
||||
HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_SET);
|
||||
turn_time++;
|
||||
}
|
||||
}
|
||||
|
||||
// 巡线功能初始化
|
||||
void LineSeek_Init(void)
|
||||
{
|
||||
// 注册定时器中断溢出回调
|
||||
HAL_TIM_RegisterCallback(&htim4, HAL_TIM_PERIOD_ELAPSED_CB_ID, LINESEEK_HAL_TIM_PeriodElapsedCallback);
|
||||
HAL_TIM_Base_Start_IT(&htim4);
|
||||
// 注册定时器事件
|
||||
timer_event_id = TIMER_AddInfiniteLoopEvent(timer_event_id, LINESEEK_TURN_TIME, 1);
|
||||
}
|
||||
|
||||
void LineSeek_Start(void)
|
||||
{
|
||||
if (state == MOVE_STOP)
|
||||
{
|
||||
state = MOVE_STRAIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
void LineSeek_Stop(void)
|
||||
{
|
||||
state = MOVE_STOP;
|
||||
}
|
||||
|
||||
void App_LineSeek(void)
|
||||
{
|
||||
int LineL1 = 1, LineL2 = 1, LineR1 = 1, LineR2 = 1;
|
||||
// LineSeek_GetStatusStr();
|
||||
|
||||
// LineSeek_GetStatus(&LineL1, &LineL2, &LineR1, &LineR2); // 获取黑线检测状态
|
||||
|
||||
LineSeek_GetStatusStr();
|
||||
// if (state != MOVE_STOP)
|
||||
// {
|
||||
// BLUETOOTH_Send("line_seek state:%d, line_seek: %s\n", state, LineSeek_Status);
|
||||
// // BLUETOOTH_Send("line_seek: %s \n", LineSeek_Status);
|
||||
// }
|
||||
// printf("%s %d \n", LineSeek_Status, turn_time);
|
||||
|
||||
// return;
|
||||
|
@ -77,15 +91,19 @@ void App_LineSeek(void)
|
|||
LineSeek_Status[3] = '1';
|
||||
}
|
||||
|
||||
if (LineSeek_Equals("0000") && !is_crossing && state != MOVE_STOP) // 十字路口
|
||||
{
|
||||
Hanlde_Crossroad();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case MOVE_STRAIGHT: // 直行
|
||||
LED_Stop(LED_ALL);
|
||||
LED_Start(LED_R);
|
||||
MOTOR_SetDuty(HIGH_SPEED, HIGH_SPEED);
|
||||
if (LineSeek_Equals("0000")) // 十字路口
|
||||
{
|
||||
Hanlde_Crossroad();
|
||||
}
|
||||
else if (LineSeek_Equals("1011")) // 左微调
|
||||
if (LineSeek_Equals("1011")) // 左微调
|
||||
{
|
||||
state = TUNE_LEFT;
|
||||
}
|
||||
|
@ -117,18 +135,24 @@ void App_LineSeek(void)
|
|||
}
|
||||
break;
|
||||
case TURN_LEFT: // 左直角
|
||||
|
||||
LED_Stop(LED_ALL);
|
||||
LED_Start(LED_G);
|
||||
MOTOR_SetDuty(-HIGH_SPEED, HIGH_SPEED);
|
||||
if (LineSeek_Equals("0000")) // 十字路口
|
||||
{
|
||||
Hanlde_Crossroad();
|
||||
}
|
||||
else if (LineSeek_Equals("1001") &&
|
||||
if (LineSeek_Equals("1001") &&
|
||||
((preState != TUNE_LEFT && turn_time >= MIN_TURN_TIME - 1) ||
|
||||
(preState == TUNE_LEFT && turn_time >= MIN_TUNE_TIME))) // 直行
|
||||
{
|
||||
state = MOVE_STRAIGHT;
|
||||
preState = TURN_LEFT;
|
||||
is_crossing = 0;
|
||||
LED_Stop(LED_ALL);
|
||||
LED_Start(LED_B);
|
||||
}
|
||||
else if (LineSeek_Equals("xxx0") && turn_time < MIN_TURN_TIME && !is_crossing) // 侧丁字路口
|
||||
{
|
||||
preState = TUNE_RIGHT;
|
||||
Hanlde_Crossroad();
|
||||
}
|
||||
else if (LineSeek_Equals("xxx0") && !is_crossing) // 转过头了
|
||||
{
|
||||
|
@ -139,11 +163,7 @@ void App_LineSeek(void)
|
|||
break;
|
||||
case TURN_RIGHT: // 右直角
|
||||
MOTOR_SetDuty(HIGH_SPEED, -HIGH_SPEED);
|
||||
if (LineSeek_Equals("0000")) // 十字路口
|
||||
{
|
||||
Hanlde_Crossroad();
|
||||
}
|
||||
else if (LineSeek_Equals("1001") &&
|
||||
if (LineSeek_Equals("1001") &&
|
||||
((preState != TUNE_RIGHT && turn_time >= MIN_TURN_TIME - 1) ||
|
||||
(preState == TUNE_RIGHT && turn_time >= MIN_TUNE_TIME))) // 直行
|
||||
{
|
||||
|
@ -151,6 +171,11 @@ void App_LineSeek(void)
|
|||
preState = TURN_RIGHT;
|
||||
is_crossing = 0;
|
||||
}
|
||||
else if (LineSeek_Equals("0xxx") && turn_time < MIN_TURN_TIME && !is_crossing) // 侧丁字路口
|
||||
{
|
||||
preState = TUNE_LEFT;
|
||||
Hanlde_Crossroad();
|
||||
}
|
||||
else if (LineSeek_Equals("0xxx") && !is_crossing) // 转过头了
|
||||
{
|
||||
turn_time = MIN_TURN_TIME;
|
||||
|
@ -160,11 +185,7 @@ void App_LineSeek(void)
|
|||
break;
|
||||
case TURN_LEFT_BIG: // 左锐角
|
||||
MOTOR_SetDuty(-MID_SPEED, MID_SPEED);
|
||||
if (LineSeek_Equals("0000")) // 十字路口
|
||||
{
|
||||
Hanlde_Crossroad();
|
||||
}
|
||||
else if (LineSeek_Equals("0001")) // 左直角
|
||||
if (LineSeek_Equals("0001")) // 左直角
|
||||
{
|
||||
turn_time = 0;
|
||||
state = TURN_LEFT;
|
||||
|
@ -178,11 +199,7 @@ void App_LineSeek(void)
|
|||
break;
|
||||
case TURN_RIGHT_BIG: // 右锐角
|
||||
MOTOR_SetDuty(MID_SPEED, -MID_SPEED);
|
||||
if (LineSeek_Equals("0000")) // 十字路口
|
||||
{
|
||||
Hanlde_Crossroad();
|
||||
}
|
||||
else if (LineSeek_Equals("1000")) // 右直角
|
||||
if (LineSeek_Equals("1000")) // 右直角
|
||||
{
|
||||
turn_time = 0;
|
||||
state = TURN_RIGHT;
|
||||
|
@ -200,13 +217,13 @@ void App_LineSeek(void)
|
|||
{
|
||||
state = MOVE_STRAIGHT;
|
||||
}
|
||||
else if (LineSeek_Equals("0xx1") && GetCurrentDirection() != STRAIGHT) // 左转
|
||||
else if (LineSeek_Equals("0xx1")) // 左转
|
||||
{
|
||||
turn_time = 0;
|
||||
state = TURN_LEFT;
|
||||
preState = TUNE_LEFT;
|
||||
}
|
||||
else if (LineSeek_Equals("1xx0") && GetCurrentDirection() != STRAIGHT) // 右转
|
||||
else if (LineSeek_Equals("1xx0")) // 右转
|
||||
{
|
||||
turn_time = 0;
|
||||
state = TURN_RIGHT;
|
||||
|
@ -219,47 +236,35 @@ void App_LineSeek(void)
|
|||
{
|
||||
state = MOVE_STRAIGHT;
|
||||
}
|
||||
else if (LineSeek_Equals("0xx1") && GetCurrentDirection() != STRAIGHT) // 左转
|
||||
else if (LineSeek_Equals("0xx1")) // 左转
|
||||
{
|
||||
turn_time = 0;
|
||||
state = TURN_LEFT;
|
||||
preState = TUNE_RIGHT;
|
||||
}
|
||||
else if (LineSeek_Equals("1xx0") && GetCurrentDirection() != STRAIGHT) // 右转
|
||||
else if (LineSeek_Equals("1xx0")) // 右转
|
||||
{
|
||||
turn_time = 0;
|
||||
state = TURN_RIGHT;
|
||||
preState = TUNE_RIGHT;
|
||||
}
|
||||
break;
|
||||
case MOVE_STOP:
|
||||
MOTOR_Stop();
|
||||
break;
|
||||
default:
|
||||
state = MOVE_STRAIGHT;
|
||||
MOTOR_SetDuty(MID_SPEED, MID_SPEED);
|
||||
break;
|
||||
}
|
||||
|
||||
// if (turn_time >= MAX_TURN_TIME)
|
||||
// {
|
||||
// // state = MOVE_STRAIGHT;
|
||||
// MOTOR_SetDuty(0, 0);
|
||||
// }
|
||||
|
||||
// printf("curr state: %d \n", state);
|
||||
}
|
||||
|
||||
void Hanlde_Crossroad(void)
|
||||
{
|
||||
if (is_crossing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
beep_time = 0;
|
||||
HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_RESET);
|
||||
// state = MOVE_STRAIGHT;
|
||||
// buzzer(1);
|
||||
// HAL_Delay(50);
|
||||
// buzzer(0);
|
||||
// 开启蜂鸣器
|
||||
BUZZER_StartTimed(1);
|
||||
|
||||
// 根据规划的路径进行决断
|
||||
is_crossing = 1;
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
|
||||
#include "app_line_seek.h"
|
||||
|
||||
#include "line_seek.h"
|
||||
#include "main.h"
|
||||
#include "motor.h"
|
||||
#include "path_plan.h"
|
||||
#include "syscalls.h"
|
||||
|
||||
// #define LOW_SPEED 30
|
||||
// #define MID_SPEED 35
|
||||
// #define HIGH_SPEED 40
|
||||
|
||||
#define LOW_SPEED 25
|
||||
#define MID_SPEED 30
|
||||
#define HIGH_SPEED 35
|
||||
|
||||
|
||||
void App_LineSeek(void)
|
||||
{
|
||||
int LineL1 = 1, LineL2 = 1, LineR1 = 1, LineR2 = 1;
|
||||
|
||||
LineSeek_GetStatus(&LineL1, &LineL2, &LineR1, &LineR2); // 获取黑线检测状态
|
||||
|
||||
LineSeek_GetStatusStr();
|
||||
printf("%s\n", LineSeek_Status);
|
||||
|
||||
// return;
|
||||
|
||||
if (LineSeek_Equals("0000")) // 丁字(十字)路口
|
||||
{
|
||||
buzzer(1);
|
||||
|
||||
// 根据规划的路径进行决断
|
||||
switch (GetNextDirection())
|
||||
{
|
||||
case STRAIGHT:
|
||||
MOTOR_SetDuty(HIGH_SPEED, HIGH_SPEED); // 直走
|
||||
break;
|
||||
case LEFT:
|
||||
MOTOR_SetDuty(HIGH_SPEED, -HIGH_SPEED); // 左转
|
||||
break;
|
||||
case RIGHT:
|
||||
MOTOR_SetDuty(-HIGH_SPEED, HIGH_SPEED); // 右转
|
||||
break;
|
||||
default:
|
||||
MOTOR_Stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
buzzer(0);
|
||||
}
|
||||
|
||||
if (LineSeek_Equals("1000")) // 右直角
|
||||
{
|
||||
MOTOR_SetDuty(HIGH_SPEED, -HIGH_SPEED); // 右旋
|
||||
// HAL_Delay(80);
|
||||
}
|
||||
else if (LineSeek_Equals("0001")) // 左直角
|
||||
{
|
||||
MOTOR_SetDuty(-HIGH_SPEED, HIGH_SPEED); // 左旋;
|
||||
// HAL_Delay(80);
|
||||
}
|
||||
else if (LineSeek_Equals("0xx1")) // 左最外侧检测(锐角)
|
||||
{
|
||||
MOTOR_SetDuty(-HIGH_SPEED, MID_SPEED); // 左旋
|
||||
// HAL_Delay(80);
|
||||
}
|
||||
else if (LineSeek_Equals("1xx0")) // 右最外侧检测(锐角)
|
||||
{
|
||||
MOTOR_SetDuty(MID_SPEED, -HIGH_SPEED); // 右旋
|
||||
// HAL_Delay(80);
|
||||
}
|
||||
else if (LineSeek_Equals("x01x")) // 中间黑线上的传感器微调车左转
|
||||
{
|
||||
MOTOR_SetDuty(0, LOW_SPEED); // 左转
|
||||
}
|
||||
else if (LineSeek_Equals("x10x")) // 中间黑线上的传感器微调车右转
|
||||
{
|
||||
MOTOR_SetDuty(LOW_SPEED, 0); // 右转
|
||||
}
|
||||
else if (LineSeek_Equals("x00x")) // 都是黑色, 加速前进
|
||||
{
|
||||
MOTOR_SetDuty(MID_SPEED, MID_SPEED); // 直走
|
||||
}
|
||||
}
|
|
@ -35,7 +35,8 @@ int APP_Find_Direction(void)
|
|||
else if(left_block < BLOCK_DISTANCE && right_block < BLOCK_DISTANCE && straight_block < BLOCK_DISTANCE)// 前左右均有障碍物,停止并鸣笛
|
||||
{
|
||||
LED_SetDuty(255,0,0);
|
||||
return STOP;
|
||||
// return STOP;
|
||||
return -1;
|
||||
}
|
||||
else if(straight_block < BLOCK_DISTANCE && left_block < BLOCK_DISTANCE)// 前左有障碍物,右转
|
||||
{
|
||||
|
|
17
CAR.ioc
17
CAR.ioc
|
@ -4,7 +4,17 @@ CAD.pinconfig=
|
|||
CAD.provider=
|
||||
Dma.Request0=USART2_RX
|
||||
Dma.Request1=USART2_TX
|
||||
Dma.RequestsNb=2
|
||||
Dma.Request2=USART1_TX
|
||||
Dma.RequestsNb=3
|
||||
Dma.USART1_TX.2.Direction=DMA_MEMORY_TO_PERIPH
|
||||
Dma.USART1_TX.2.Instance=DMA1_Channel4
|
||||
Dma.USART1_TX.2.MemDataAlignment=DMA_MDATAALIGN_BYTE
|
||||
Dma.USART1_TX.2.MemInc=DMA_MINC_ENABLE
|
||||
Dma.USART1_TX.2.Mode=DMA_NORMAL
|
||||
Dma.USART1_TX.2.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
|
||||
Dma.USART1_TX.2.PeriphInc=DMA_PINC_DISABLE
|
||||
Dma.USART1_TX.2.Priority=DMA_PRIORITY_LOW
|
||||
Dma.USART1_TX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
||||
Dma.USART2_RX.0.Direction=DMA_PERIPH_TO_MEMORY
|
||||
Dma.USART2_RX.0.Instance=DMA1_Channel6
|
||||
Dma.USART2_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE
|
||||
|
@ -82,7 +92,6 @@ MxCube.Version=6.12.0
|
|||
MxDb.Version=DB.6.0.120
|
||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.DMA1_Channel6_IRQn=true\:3\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.DMA1_Channel7_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.EXTI15_10_IRQn=true\:2\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.ForceEnableDMAVector=false
|
||||
|
@ -228,7 +237,7 @@ ProjectManager.ProjectName=CAR
|
|||
ProjectManager.ProjectStructure=
|
||||
ProjectManager.RegisterCallBack=TIM
|
||||
ProjectManager.StackSize=0x400
|
||||
ProjectManager.TargetToolchain=MDK-ARM V5.32
|
||||
ProjectManager.TargetToolchain=Makefile
|
||||
ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
|
@ -296,7 +305,7 @@ TIM4.Period=100 - 1
|
|||
TIM4.Prescaler=720 - 1
|
||||
TIM4.Pulse-PWM\ Generation1\ CH1=0
|
||||
TIM4.Pulse-PWM\ Generation2\ CH2=0
|
||||
USART1.BaudRate=115200
|
||||
USART1.BaudRate=9600
|
||||
USART1.IPParameters=VirtualMode,BaudRate,Parity,WordLength
|
||||
USART1.Parity=PARITY_NONE
|
||||
USART1.VirtualMode=VM_ASYNC
|
||||
|
|
10
Core/Inc/delay.h
Normal file
10
Core/Inc/delay.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef __DELAY_H
|
||||
#define __DELAY_H
|
||||
|
||||
#include "main.h"
|
||||
|
||||
extern void delay_init(void);
|
||||
extern void delay_us(uint32_t nus);
|
||||
extern void delay_ms(uint32_t nms);
|
||||
|
||||
#endif
|
|
@ -8,11 +8,19 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "usart.h"
|
||||
|
||||
#define DEFAULT_HUART 1
|
||||
#define HUART1 (&huart1)
|
||||
#define HUART2 (&huart2)
|
||||
|
||||
#if DEFAULT_HUART == 1
|
||||
#define HUART HUART1
|
||||
#else
|
||||
#define HUART HUART2
|
||||
#endif
|
||||
|
||||
// 条件编译,适配不同平台 (GNU, GCC)
|
||||
#ifdef __GNUC__
|
||||
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
||||
|
@ -25,10 +33,7 @@
|
|||
int _read(int file, char *ptr, int len);
|
||||
int _write(int file, char *ptr, int len);
|
||||
|
||||
PUTCHAR_PROTOTYPE;
|
||||
GETCHAR_PROTOTYPE;
|
||||
|
||||
void delay_us(uint16_t us);
|
||||
int myprintf(const char *format, ...);
|
||||
void my_printf(UART_HandleTypeDef *huart, const char *buf, ...);
|
||||
|
||||
#endif
|
||||
|
|
127
Core/Src/delay.c
Normal file
127
Core/Src/delay.c
Normal file
|
@ -0,0 +1,127 @@
|
|||
#include "main.h"
|
||||
|
||||
#define USE_HAL_LEGACY
|
||||
#include "stm32_hal_legacy.h"
|
||||
|
||||
#define Timebase_Source_is_SysTick 1 //当Timebase Source为SysTick时改为1
|
||||
//#define Timebase_Source_is_SysTick 0 //当使用FreeRTOS,Timebase Source为其他定时器时改为0
|
||||
|
||||
#if (!Timebase_Source_is_SysTick)
|
||||
extern TIM_HandleTypeDef htimx; //当使用FreeRTOS,Timebase Source为其他定时器时,修改为对应的定时器
|
||||
#define Timebase_htim htimx
|
||||
|
||||
#define Delay_GetCounter() __HAL_TIM_GetCounter(&Timebase_htim)
|
||||
#define Delay_GetAutoreload() __HAL_TIM_GetAutoreload(&Timebase_htim)
|
||||
#else
|
||||
#define Delay_GetCounter() (SysTick->VAL)
|
||||
#define Delay_GetAutoreload() (SysTick->LOAD)
|
||||
#endif
|
||||
|
||||
static uint16_t fac_us = 0;
|
||||
static uint32_t fac_ms = 0;
|
||||
|
||||
/*初始化*/
|
||||
void delay_init(void)
|
||||
{
|
||||
#if (!Timebase_Source_is_SysTick)
|
||||
fac_ms = 1000000; //作为时基的计数器时钟频率在HAL_InitTick()中被设为了1MHz
|
||||
fac_us = fac_ms / 1000;
|
||||
#else
|
||||
fac_ms = SystemCoreClock / 1000;
|
||||
fac_us = fac_ms / 1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*微秒级延时*/
|
||||
void delay_us(uint32_t nus)
|
||||
{
|
||||
uint32_t ticks = 0;
|
||||
uint32_t told = 0;
|
||||
uint32_t tnow = 0;
|
||||
uint32_t tcnt = 0;
|
||||
uint32_t reload = 0;
|
||||
|
||||
reload = Delay_GetAutoreload();
|
||||
|
||||
ticks = nus * fac_us;
|
||||
|
||||
told = Delay_GetCounter();
|
||||
|
||||
while (1)
|
||||
{
|
||||
tnow = Delay_GetCounter();
|
||||
|
||||
if (tnow != told)
|
||||
{
|
||||
if (tnow < told)
|
||||
{
|
||||
tcnt += told - tnow;
|
||||
}
|
||||
else
|
||||
{
|
||||
tcnt += reload - tnow + told;
|
||||
}
|
||||
told = tnow;
|
||||
if (tcnt >= ticks)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*毫秒级延时*/
|
||||
void delay_ms(uint32_t nms)
|
||||
{
|
||||
uint32_t ticks = 0;
|
||||
uint32_t told = 0;
|
||||
uint32_t tnow = 0;
|
||||
uint32_t tcnt = 0;
|
||||
uint32_t reload = 0;
|
||||
|
||||
reload = Delay_GetAutoreload();
|
||||
|
||||
ticks = nms * fac_ms;
|
||||
|
||||
told = Delay_GetCounter();
|
||||
|
||||
while (1)
|
||||
{
|
||||
tnow = Delay_GetCounter();
|
||||
|
||||
if (tnow != told)
|
||||
{
|
||||
if (tnow < told)
|
||||
{
|
||||
tcnt += told - tnow;
|
||||
}
|
||||
else
|
||||
{
|
||||
tcnt += reload - tnow + told;
|
||||
}
|
||||
told = tnow;
|
||||
if (tcnt >= ticks)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*重写HAL_Delay*/
|
||||
void HAL_Delay(uint32_t Delay)
|
||||
{
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
uint32_t wait = Delay;
|
||||
|
||||
/*不太明白官方源码为啥这么写,会多延时1ms,注释掉后更准*/
|
||||
// /* Add a freq to guarantee minimum wait */
|
||||
// if (wait < HAL_MAX_DELAY)
|
||||
// {
|
||||
// wait += (uint32_t)(uwTickFreq);
|
||||
// }
|
||||
|
||||
while ((HAL_GetTick() - tickstart) < wait)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -18,20 +18,25 @@
|
|||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
#include "dma.h"
|
||||
#include "gpio.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "app_bus.h"
|
||||
#include "app_line_seek.h"
|
||||
#include "block_detect.h"
|
||||
#include "bluetooth.h"
|
||||
#include "buzzer.h"
|
||||
#include "delay.h"
|
||||
#include "hcsr04.h"
|
||||
#include "led.h"
|
||||
#include "motor.h"
|
||||
#include "path_plan.h"
|
||||
#include "servo.h"
|
||||
#include "syscalls.h"
|
||||
#include "timer.h"
|
||||
/* USER CODE END Includes */
|
||||
|
@ -54,7 +59,11 @@
|
|||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
int printf_event_id = -1;
|
||||
void Print(uint16_t time)
|
||||
{
|
||||
printf("timed print: %d\n", time);
|
||||
}
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
@ -77,10 +86,9 @@ void SystemClock_Config(void);
|
|||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
uint8_t pData[10] = {1, 2, 3};
|
||||
int i = 0;
|
||||
char pData[] = "hello world";
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
@ -107,39 +115,58 @@ int main(void)
|
|||
MX_TIM3_Init();
|
||||
MX_TIM4_Init();
|
||||
// MX_USART1_UART_Init();
|
||||
// MX_USART2_UART_Init();
|
||||
MX_USART2_UART_Init();
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
// HC_SR04_Init();
|
||||
// BLUETOOTH_Init();
|
||||
// MOTOR_Init();
|
||||
// PathPlanner_Init();
|
||||
// LineSeek_Init();
|
||||
HAL_Delay(500);
|
||||
|
||||
delay_init();
|
||||
TIMER_Init();
|
||||
HC_SR04_Init();
|
||||
BLUETOOTH_Init();
|
||||
MOTOR_Init();
|
||||
PathPlanner_Init();
|
||||
LineSeek_Init();
|
||||
BlockDetect_Init();
|
||||
SERVO_Init();
|
||||
SERVO_Rotate(90);
|
||||
|
||||
HAL_Delay(2000);
|
||||
|
||||
// BUZZER_StartNTimes(20, 500, 500);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
|
||||
BUZZER_StartTimed(3);
|
||||
HAL_Delay(1000);
|
||||
// my_printf(HUART1, "%s\r\n", *pData);
|
||||
// printf("printf: %s \r\n", pData);
|
||||
// myprintf("myprintf: %s \r\n", pData);
|
||||
// BUZZER_StartTimed(5);
|
||||
// HAL_Delay(1000);
|
||||
// my_printf(HUART1, "HUART1: %s \r\n", pData);
|
||||
// my_printf(HUART2, "HUART2: %s \r\n", pData);
|
||||
|
||||
// if (HAL_OK == HAL_UART_Receive(&huart2, (uint8_t *)pData, 2, 1000))
|
||||
// {
|
||||
// HAL_UART_Transmit(&huart2, (uint8_t *)pData, sizeof(pData), 1000);
|
||||
// HAL_UART_Transmit(&huart1, (uint8_t *)pData, sizeof(pData), 1000);
|
||||
// HAL_Delay(500);
|
||||
// }
|
||||
|
||||
// HAL_Delay(2000);
|
||||
// printf("printf: %s \r\n", pData);
|
||||
App_Bus();
|
||||
|
||||
// BUZZER_StartTimed(1000);
|
||||
// HAL_Delay(3000);
|
||||
// printf("ruunning\n");
|
||||
// BUZZER_StartNTimes(5, 500, 500);
|
||||
// HAL_Delay(5000);
|
||||
|
||||
// App_LineSeek();
|
||||
|
||||
// MOTOR_SetDuty(-20,20);
|
||||
|
||||
// HAL_Delay(300); // ??300??
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "syscalls.h"
|
||||
|
||||
extern UART_HandleTypeDef huart1;
|
||||
volatile uint8_t usart_dma_tx_over = 1;
|
||||
|
||||
// 条件编译,适配不同平台 (GNU, GCC)
|
||||
#ifdef __GNUC__
|
||||
|
@ -42,7 +42,7 @@ __attribute__((weak)) int _write(int file, char *ptr, int len)
|
|||
*/
|
||||
PUTCHAR_PROTOTYPE
|
||||
{
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // 阻塞式无限等待
|
||||
HAL_UART_Transmit(HUART, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
@ -58,20 +58,47 @@ PUTCHAR_PROTOTYPE
|
|||
GETCHAR_PROTOTYPE
|
||||
{
|
||||
uint8_t ch = 0;
|
||||
HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
|
||||
HAL_UART_Receive(HUART, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
|
||||
return ch;
|
||||
}
|
||||
|
||||
void delay_us(uint16_t us)
|
||||
// 串口发送完毕回调函数,设置usart_dma_tx_over标志为1
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
volatile uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us);
|
||||
while (delay--);
|
||||
#if DEFAULT_HUART == 1
|
||||
if (huart->Instance == USART1)
|
||||
#else
|
||||
if (huart->Instance == USART2)
|
||||
#endif
|
||||
{
|
||||
usart_dma_tx_over = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 自定义printf
|
||||
* @param huart, buf
|
||||
* @return void
|
||||
* @brief 自定义printf,串口使用头文件定义的DEFAULT_HUART,DMA串口中断方式发送
|
||||
*
|
||||
* @usage my_printf(HUART1, "USART1_Target:\r\n");
|
||||
*/
|
||||
int myprintf(const char *format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
static char SendBuff[256] = {0};
|
||||
int rv;
|
||||
while (!usart_dma_tx_over); // 等待前一次DMA发送完成
|
||||
|
||||
va_start(arg, format);
|
||||
rv = vsnprintf((char *)SendBuff, sizeof(SendBuff) + 1, (char *)format, arg);
|
||||
va_end(arg);
|
||||
|
||||
HAL_UART_Transmit_DMA(HUART, (uint8_t *)SendBuff, rv);
|
||||
usart_dma_tx_over = 0; // 清0全局标志,发送完成后重新置1
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 自定义printf, 需指定发送串口
|
||||
*
|
||||
* @usage my_printf(HUART1, "USART1_Target:\r\n");
|
||||
*/
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
UART_HandleTypeDef huart1;
|
||||
UART_HandleTypeDef huart2;
|
||||
DMA_HandleTypeDef hdma_usart1_tx;
|
||||
DMA_HandleTypeDef hdma_usart2_rx;
|
||||
DMA_HandleTypeDef hdma_usart2_tx;
|
||||
|
||||
|
@ -42,7 +43,7 @@ void MX_USART1_UART_Init(void)
|
|||
|
||||
/* USER CODE END USART1_Init 1 */
|
||||
huart1.Instance = USART1;
|
||||
huart1.Init.BaudRate = 115200;
|
||||
huart1.Init.BaudRate = 9600;
|
||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||
huart1.Init.Parity = UART_PARITY_NONE;
|
||||
|
@ -115,6 +116,23 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
|||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USART1 DMA Init */
|
||||
/* USART1_TX Init */
|
||||
hdma_usart1_tx.Instance = DMA1_Channel4;
|
||||
hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_usart1_tx.Init.Mode = DMA_NORMAL;
|
||||
hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx);
|
||||
|
||||
/* USART1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 3, 1);
|
||||
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||
|
@ -204,6 +222,9 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
|||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
|
||||
|
||||
/* USART1 DMA DeInit */
|
||||
HAL_DMA_DeInit(uartHandle->hdmatx);
|
||||
|
||||
/* USART1 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(USART1_IRQn);
|
||||
/* USER CODE BEGIN USART1_MspDeInit 1 */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd">
|
||||
|
||||
<SchemaVersion>1.0</SchemaVersion>
|
||||
|
@ -45,7 +45,7 @@
|
|||
<PageWidth>79</PageWidth>
|
||||
<PageLength>66</PageLength>
|
||||
<TabStop>8</TabStop>
|
||||
<ListingPath />
|
||||
<ListingPath></ListingPath>
|
||||
</OPTLEX>
|
||||
<ListingPage>
|
||||
<CreateCListing>1</CreateCListing>
|
||||
|
@ -104,16 +104,16 @@
|
|||
<bSchkAxf>0</bSchkAxf>
|
||||
<bTchkAxf>0</bTchkAxf>
|
||||
<nTsel>3</nTsel>
|
||||
<sDll />
|
||||
<sDllPa />
|
||||
<sDlgDll />
|
||||
<sDlgPa />
|
||||
<sIfile />
|
||||
<tDll />
|
||||
<tDllPa />
|
||||
<tDlgDll />
|
||||
<tDlgPa />
|
||||
<tIfile />
|
||||
<sDll></sDll>
|
||||
<sDllPa></sDllPa>
|
||||
<sDlgDll></sDlgDll>
|
||||
<sDlgPa></sDlgPa>
|
||||
<sIfile></sIfile>
|
||||
<tDll></tDll>
|
||||
<tDllPa></tDllPa>
|
||||
<tDlgDll></tDlgDll>
|
||||
<tDlgPa></tDlgPa>
|
||||
<tIfile></tIfile>
|
||||
<pMon>BIN\CMSIS_AGDI.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
|
@ -130,7 +130,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ARMDBGFLAGS</Key>
|
||||
<Name />
|
||||
<Name></Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -140,7 +140,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGUARM</Key>
|
||||
<Name />
|
||||
<Name></Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -152,25 +152,9 @@
|
|||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>34</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134226736</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\Peripheral\Src\bluetooth.c</Filename>
|
||||
<ExecCommand />
|
||||
<Expression>\\CAR\../Peripheral/Src/bluetooth.c\34</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>32</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134221058</Address>
|
||||
<Address>134222756</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
|
@ -178,28 +162,60 @@
|
|||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\Peripheral\Src\control.c</Filename>
|
||||
<ExecCommand />
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\CAR\../Peripheral/Src/control.c\32</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>2</Number>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>24</LineNumber>
|
||||
<LineNumber>15</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>0</Address>
|
||||
<Address>134222672</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>startup_stm32f103xb.s</Filename>
|
||||
<ExecCommand />
|
||||
<Expression />
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\Peripheral\Src\buzzer.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\CAR\../Peripheral/Src/buzzer.c\15</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>2</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>135</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134239198</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\Service\Src\timer.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\CAR\../Service/Src/timer.c\135</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>3</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>145</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134239330</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\Service\Src\timer.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\CAR\../Service/Src/timer.c\145</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>4</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>97</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>0</Address>
|
||||
|
@ -210,11 +226,11 @@
|
|||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>startup_stm32f103xb.s</Filename>
|
||||
<ExecCommand />
|
||||
<Expression />
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>4</Number>
|
||||
<Number>5</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>99</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
|
@ -226,8 +242,8 @@
|
|||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>startup_stm32f103xb.s</Filename>
|
||||
<ExecCommand />
|
||||
<Expression />
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
|
@ -282,19 +298,19 @@
|
|||
<newCpu>0</newCpu>
|
||||
<uProt>0</uProt>
|
||||
</DebugFlag>
|
||||
<LintExecutable />
|
||||
<LintConfigFile />
|
||||
<LintExecutable></LintExecutable>
|
||||
<LintConfigFile></LintConfigFile>
|
||||
<bLintAuto>0</bLintAuto>
|
||||
<bAutoGenD>0</bAutoGenD>
|
||||
<LntExFlags>0</LntExFlags>
|
||||
<pMisraName />
|
||||
<pszMrule />
|
||||
<pSingCmds />
|
||||
<pMultCmds />
|
||||
<pMisraNamep />
|
||||
<pszMrulep />
|
||||
<pSingCmdsp />
|
||||
<pMultCmdsp />
|
||||
<pMisraName></pMisraName>
|
||||
<pszMrule></pszMrule>
|
||||
<pSingCmds></pSingCmds>
|
||||
<pMultCmds></pMultCmds>
|
||||
<pMisraNamep></pMisraNamep>
|
||||
<pszMrulep></pszMrulep>
|
||||
<pSingCmdsp></pSingCmdsp>
|
||||
<pMultCmdsp></pMultCmdsp>
|
||||
<DebugDescription>
|
||||
<Enable>1</Enable>
|
||||
<EnableFlashSeq>1</EnableFlashSeq>
|
||||
|
@ -459,17 +475,29 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Core\Src\delay.c</PathWithFileName>
|
||||
<FilenameWithoutPath>delay.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
<GroupName>Application/User/Service</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -481,7 +509,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -491,17 +519,29 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Service\Src\block_detect.c</PathWithFileName>
|
||||
<FilenameWithoutPath>block_detect.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
<GroupName>Application/User/Peripheral</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -513,7 +553,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -525,7 +565,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -537,7 +577,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -549,7 +589,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -561,7 +601,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -573,7 +613,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -585,7 +625,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -597,7 +637,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileNumber>24</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -609,7 +649,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileNumber>25</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -629,7 +669,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>24</FileNumber>
|
||||
<FileNumber>26</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -641,7 +681,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>25</FileNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -653,7 +693,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>26</FileNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -665,7 +705,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -677,7 +717,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -689,7 +729,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -701,7 +741,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -713,7 +753,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -725,7 +765,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileNumber>34</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -737,7 +777,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileNumber>35</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -749,7 +789,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>34</FileNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -761,7 +801,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>35</FileNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -773,7 +813,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -785,7 +825,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -805,7 +845,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>7</GroupNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileNumber>40</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="project_projx.xsd">
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
|
||||
|
||||
<SchemaVersion>2.1</SchemaVersion>
|
||||
|
||||
<Header>### uVision Project, (C) Keil Software</Header>
|
||||
|
||||
<Targets>
|
||||
<Target>
|
||||
<TargetName>CAR</TargetName>
|
||||
|
@ -13,31 +16,31 @@
|
|||
<TargetCommonOption>
|
||||
<Device>STM32F103C8</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.4.1</PackID>
|
||||
<PackURL>https://www.keil.com/pack/</PackURL>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.2.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||
<Cpu>IRAM(0x20000000-0x20004FFF) IROM(0x8000000-0x800FFFF) CLOCK(8000000) CPUTYPE("Cortex-M3") TZ</Cpu>
|
||||
<FlashUtilSpec />
|
||||
<StartupFile />
|
||||
<FlashDriverDll />
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
<StartupFile></StartupFile>
|
||||
<FlashDriverDll></FlashDriverDll>
|
||||
<DeviceId>0</DeviceId>
|
||||
<RegisterFile />
|
||||
<MemoryEnv />
|
||||
<Cmp />
|
||||
<Asm />
|
||||
<Linker />
|
||||
<OHString />
|
||||
<InfinionOptionDll />
|
||||
<SLE66CMisc />
|
||||
<SLE66AMisc />
|
||||
<SLE66LinkerMisc />
|
||||
<RegisterFile></RegisterFile>
|
||||
<MemoryEnv></MemoryEnv>
|
||||
<Cmp></Cmp>
|
||||
<Asm></Asm>
|
||||
<Linker></Linker>
|
||||
<OHString></OHString>
|
||||
<InfinionOptionDll></InfinionOptionDll>
|
||||
<SLE66CMisc></SLE66CMisc>
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile>$$Device:STM32F103C8$SVD\STM32F103xx.svd</SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath />
|
||||
<IncludePath />
|
||||
<LibPath />
|
||||
<RegisterFilePath />
|
||||
<DBRegisterFilePath />
|
||||
<BinPath></BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
<LibPath></LibPath>
|
||||
<RegisterFilePath></RegisterFilePath>
|
||||
<DBRegisterFilePath></DBRegisterFilePath>
|
||||
<TargetStatus>
|
||||
<Error>0</Error>
|
||||
<ExitCodeStop>0</ExitCodeStop>
|
||||
|
@ -52,15 +55,15 @@
|
|||
<CreateHexFile>1</CreateHexFile>
|
||||
<DebugInformation>1</DebugInformation>
|
||||
<BrowseInformation>1</BrowseInformation>
|
||||
<ListingPath />
|
||||
<ListingPath></ListingPath>
|
||||
<HexFormatSelection>1</HexFormatSelection>
|
||||
<Merge32K>0</Merge32K>
|
||||
<CreateBatchFile>0</CreateBatchFile>
|
||||
<BeforeCompile>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name />
|
||||
<UserProg2Name />
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopU1X>0</nStopU1X>
|
||||
|
@ -69,8 +72,8 @@
|
|||
<BeforeMake>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name />
|
||||
<UserProg2Name />
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopB1X>0</nStopB1X>
|
||||
|
@ -79,15 +82,15 @@
|
|||
<AfterMake>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>1</RunUserProg2>
|
||||
<UserProg1Name />
|
||||
<UserProg2Name />
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopA1X>0</nStopA1X>
|
||||
<nStopA2X>0</nStopA2X>
|
||||
</AfterMake>
|
||||
<SelectedForBatchBuild>1</SelectedForBatchBuild>
|
||||
<SVCSIdString />
|
||||
<SVCSIdString></SVCSIdString>
|
||||
</TargetCommonOption>
|
||||
<CommonProperty>
|
||||
<UseCPPCompiler>0</UseCPPCompiler>
|
||||
|
@ -101,8 +104,8 @@
|
|||
<AssembleAssemblyFile>0</AssembleAssemblyFile>
|
||||
<PublicsOnly>0</PublicsOnly>
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument />
|
||||
<IncludeLibraryModules />
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>0</ComprImg>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
|
@ -111,7 +114,7 @@
|
|||
<SimDlgDll>DCM.DLL</SimDlgDll>
|
||||
<SimDlgDllArguments>-pCM3</SimDlgDllArguments>
|
||||
<TargetDllName>SARMCM3.DLL</TargetDllName>
|
||||
<TargetDllArguments />
|
||||
<TargetDllArguments></TargetDllArguments>
|
||||
<TargetDlgDll>TCM.DLL</TargetDlgDll>
|
||||
<TargetDlgDllArguments>-pCM3</TargetDlgDllArguments>
|
||||
</DllOption>
|
||||
|
@ -136,10 +139,10 @@
|
|||
<bUseTDR>1</bUseTDR>
|
||||
<Flash2>BIN\UL2CM3.DLL</Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4 />
|
||||
<pFcarmOut />
|
||||
<pFcarmGrp />
|
||||
<pFcArmRoot />
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<TargetArmAds>
|
||||
|
@ -172,7 +175,7 @@
|
|||
<RvctClst>0</RvctClst>
|
||||
<GenPPlst>0</GenPPlst>
|
||||
<AdsCpuType>"Cortex-M3"</AdsCpuType>
|
||||
<RvctDeviceName />
|
||||
<RvctDeviceName></RvctDeviceName>
|
||||
<mOS>0</mOS>
|
||||
<uocRom>0</uocRom>
|
||||
<uocRam>0</uocRam>
|
||||
|
@ -306,11 +309,11 @@
|
|||
<Size>0x0</Size>
|
||||
</OCR_RVCT10>
|
||||
</OnChipMemories>
|
||||
<RvctStartVector />
|
||||
<RvctStartVector></RvctStartVector>
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>2</Optim>
|
||||
<Optim>1</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
|
@ -333,9 +336,9 @@
|
|||
<v6WtE>0</v6WtE>
|
||||
<v6Rtti>0</v6Rtti>
|
||||
<VariousControls>
|
||||
<MiscControls />
|
||||
<MiscControls></MiscControls>
|
||||
<Define>USE_HAL_DRIVER,STM32F103xB</Define>
|
||||
<Undefine />
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>../App/Inc;../Core/Inc;../Service/Inc;../Peripheral/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
|
@ -351,10 +354,10 @@
|
|||
<useXO>0</useXO>
|
||||
<ClangAsOpt>1</ClangAsOpt>
|
||||
<VariousControls>
|
||||
<MiscControls />
|
||||
<Define />
|
||||
<Undefine />
|
||||
<IncludePath />
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath></IncludePath>
|
||||
</VariousControls>
|
||||
</Aads>
|
||||
<LDads>
|
||||
|
@ -364,15 +367,15 @@
|
|||
<noStLib>0</noStLib>
|
||||
<RepFail>1</RepFail>
|
||||
<useFile>0</useFile>
|
||||
<TextAddressRange />
|
||||
<DataAddressRange />
|
||||
<pXoBase />
|
||||
<ScatterFile />
|
||||
<IncludeLibs />
|
||||
<IncludeLibsPath />
|
||||
<Misc />
|
||||
<LinkerInputFile />
|
||||
<DisabledWarnings />
|
||||
<TextAddressRange></TextAddressRange>
|
||||
<DataAddressRange></DataAddressRange>
|
||||
<pXoBase></pXoBase>
|
||||
<ScatterFile></ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
<Misc></Misc>
|
||||
<LinkerInputFile></LinkerInputFile>
|
||||
<DisabledWarnings></DisabledWarnings>
|
||||
</LDads>
|
||||
</TargetArmAds>
|
||||
</TargetOption>
|
||||
|
@ -445,6 +448,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>../Core/Src/stm32f1xx_hal_msp.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>delay.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Core\Src\delay.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -460,6 +468,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Service\Src\timer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>block_detect.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Service\Src\block_detect.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -608,18 +621,20 @@
|
|||
</Groups>
|
||||
</Target>
|
||||
</Targets>
|
||||
|
||||
<RTE>
|
||||
<apis />
|
||||
<apis/>
|
||||
<components>
|
||||
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="4.3.0" condition="CMSIS Core">
|
||||
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="4.5.0" />
|
||||
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="4.5.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="CAR" />
|
||||
<targetInfo name="CAR"/>
|
||||
</targetInfos>
|
||||
</component>
|
||||
</components>
|
||||
<files />
|
||||
<files/>
|
||||
</RTE>
|
||||
|
||||
<LayerInfo>
|
||||
<Layers>
|
||||
<Layer>
|
||||
|
@ -628,5 +643,5 @@
|
|||
</Layer>
|
||||
</Layers>
|
||||
</LayerInfo>
|
||||
</Project>
|
||||
|
||||
</Project>
|
||||
|
|
15
Makefile
15
Makefile
|
@ -1,5 +1,5 @@
|
|||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [4.4.0-B60] date: [Wed Jul 17 21:44:09 CST 2024]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [4.4.0-B60] date: [Fri Jul 19 12:38:57 CST 2024]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
|
@ -38,15 +38,14 @@ BUILD_DIR = build
|
|||
C_SOURCES = \
|
||||
Core/Src/main.c \
|
||||
Core/Src/gpio.c \
|
||||
Core/Src/i2c.c \
|
||||
Core/Src/syscalls.c \
|
||||
Core/Src/tim.c \
|
||||
Core/Src/dma.c \
|
||||
Core/Src/usart.c \
|
||||
Core/Src/stm32f1xx_it.c \
|
||||
Core/Src/stm32f1xx_hal_msp.c \
|
||||
Core/Src/delay.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
|
||||
|
@ -68,11 +67,16 @@ 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 \
|
||||
Peripheral/Src/syn6288.c \
|
||||
Peripheral/Src/buzzer.c \
|
||||
App/Src/app_line_seek.c \
|
||||
App/Src/app_ultrasonic.c
|
||||
App/Src/app_ultrasonic.c \
|
||||
App/Src/app_bus.c \
|
||||
Service/Src/path_plan.c \
|
||||
Service/Src/timer.c \
|
||||
Service/Src/block_detect.c
|
||||
|
||||
|
||||
# ASM sources
|
||||
|
@ -134,6 +138,7 @@ AS_INCLUDES =
|
|||
# C includes
|
||||
C_INCLUDES = \
|
||||
-ICore/Inc \
|
||||
-IService/Inc \
|
||||
-IPeripheral/Inc \
|
||||
-IApp/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
void LED_Start(uint8_t led);
|
||||
void LED_Stop(uint8_t led);
|
||||
|
||||
|
||||
void LED_StartTimed(uint8_t led, uint16_t time);
|
||||
void LED_StartNTimes(uint8_t led, uint16_t on_time, uint16_t off_time);
|
||||
|
||||
// duty in [0, 255]
|
||||
void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
#include "bluetooth.h"
|
||||
#include "usart.h"
|
||||
#include "control.h"
|
||||
#include "line_seek.h"
|
||||
#include "infrared.h"
|
||||
#include "hcsr04.h"
|
||||
#include "timer.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "control.h"
|
||||
#include "hcsr04.h"
|
||||
#include "infrared.h"
|
||||
#include "line_seek.h"
|
||||
#include "timer.h"
|
||||
#include "usart.h"
|
||||
|
||||
#define BUFFER_SIZE 255
|
||||
#define MESSAGE_SIZE 19
|
||||
|
@ -17,24 +19,24 @@
|
|||
static int8_t rxBuffer[BUFFER_SIZE], txBuffer[BUFFER_SIZE];
|
||||
static uint16_t txLen;
|
||||
static uint8_t cmdIndex;
|
||||
|
||||
static uint8_t timer_event_id = -1;
|
||||
void sendSensor(void)
|
||||
{
|
||||
static uint8_t line_seek[5];
|
||||
strcpy(line_seek, LineSeek_GetStatusStr());
|
||||
for (uint8_t i = 0; i < 5; ++i)
|
||||
line_seek[i] ^= 1;
|
||||
BLUETOOTH_Send("$4WD,CSB%u,PV-,GS-,LF%s,HW%hhu%hhu,GM-#",
|
||||
(uint32_t)round((double)sonor_distance / 10),
|
||||
line_seek,
|
||||
!INFRARED_GetL(),
|
||||
!INFRARED_GetR());
|
||||
// static uint8_t line_seek[5];
|
||||
// strcpy(line_seek, LineSeek_GetStatusStr());
|
||||
// for (uint8_t i = 0; i < 5; ++i)
|
||||
// line_seek[i] ^= 1;
|
||||
// BLUETOOTH_Send("$4WD,CSB%u,PV-,GS-,LF%s,HW%hhu%hhu,GM-#",
|
||||
// (uint32_t)round((double)sonor_distance / 10),
|
||||
// line_seek,
|
||||
// !INFRARED_GetL(),
|
||||
// !INFRARED_GetR());
|
||||
}
|
||||
|
||||
void BLUETOOTH_Init(void)
|
||||
{
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart2, rxBuffer, 100);
|
||||
TIMER_AddLoopEvent(EVENT_BLUETOOTH, sendSensor, 200);
|
||||
timer_event_id = TIMER_AddInfiniteLoopEvent(timer_event_id, sendSensor, 1);
|
||||
}
|
||||
|
||||
void BLUETOOTH_Send(const char *str, ...)
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#include "hcsr04.h"
|
||||
#include "tim.h"
|
||||
|
||||
#include "syscalls.h"
|
||||
#include "delay.h"
|
||||
#include "tim.h"
|
||||
|
||||
static uint64_t time_start; // 声明变量,用来计时
|
||||
static uint64_t time_end; // 声明变量,存储回波信号时间
|
||||
uint8_t sonor_state; // 测距状态变量,0:未测量,1:正在测量,2:已测量
|
||||
uint32_t sonor_distance; // 测量出的距离,单位mm
|
||||
uint32_t sonor_distance = INT32_MAX; // 测量出的距离,单位mm
|
||||
|
||||
void HCSR04_HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
|
||||
|
||||
|
@ -18,6 +20,8 @@ void HC_SR04_Init(void)
|
|||
|
||||
// 注册定时器中断溢出回调
|
||||
HAL_TIM_RegisterCallback(&htim2, HAL_TIM_PERIOD_ELAPSED_CB_ID, HCSR04_HAL_TIM_PeriodElapsedCallback);
|
||||
|
||||
sonor_distance = INT32_MAX;
|
||||
}
|
||||
|
||||
// 启动测距,单位:mm
|
||||
|
@ -27,11 +31,7 @@ uint32_t sonar_mm(void)
|
|||
HAL_GPIO_WritePin(TRIG_GPIO_Port, TRIG_Pin, GPIO_PIN_SET); // 输出高电平
|
||||
delay_us(15); // 延时15微秒
|
||||
HAL_GPIO_WritePin(TRIG_GPIO_Port, TRIG_Pin, GPIO_PIN_RESET); // 输出低电平
|
||||
if (time_end / 100 < 38)
|
||||
{ // 判断是否小于38毫秒,大于38毫秒的就是超时,直接调到下面返回0
|
||||
sonor_distance = (time_end * 346) / 2; // 计算距离,25°C空气中的音速为346m/s
|
||||
sonor_distance = sonor_distance / 100; // 因为上面的time_end的单位是10微秒,所以要得出单位为毫米的距离结果,还得除以100
|
||||
}
|
||||
|
||||
return sonor_distance;
|
||||
}
|
||||
|
||||
|
@ -58,14 +58,15 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||
time_end = time_start;
|
||||
HAL_TIM_Base_Stop_IT(&htim2);
|
||||
sonor_state = 2;
|
||||
sonor_distance = (time_end / 100 < 38) ? (time_end * 346) / 200 : INT32_MAX;
|
||||
Sonar_CP_Callback();
|
||||
sonor_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 测距完毕回调,执行完自定义任务后将sonor_state置0
|
||||
// 测距完毕回调,执行完自定义任务后会将sonor_state置0
|
||||
__attribute__((weak)) void Sonar_CP_Callback()
|
||||
{
|
||||
my_printf(HUART1, "distance = %d (mm)\n", sonor_distance);
|
||||
sonor_state = 0;
|
||||
my_printf(HUART2, "distance = %d (mm)\n", sonor_distance);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "led.h"
|
||||
|
||||
#include "tim.h"
|
||||
#include "timer.h"
|
||||
|
||||
|
@ -36,6 +37,16 @@ void LED_Stop(uint8_t led)
|
|||
HAL_TIM_PWM_Stop(LED_TIM, LED_B_CHAN);
|
||||
}
|
||||
|
||||
void LED_StartTimed(uint8_t led, uint16_t time)
|
||||
{
|
||||
led_timed_id = TIMER_AddDelayEvent(led_timed_id, LED_Stop, time);
|
||||
}
|
||||
|
||||
void LED_StartNTimes(uint8_t led, uint16_t on_time, uint16_t off_time)
|
||||
{
|
||||
// led_times_id = TIMER_AddFiniteLoopEvent(led_times_id, LED_Stop, time);
|
||||
}
|
||||
|
||||
void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
__HAL_TIM_SetCompare(LED_TIM, LED_R_CHAN, r);
|
||||
|
|
|
@ -36,10 +36,12 @@ BUILD_DIR = build
|
|||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
App/Src/app_bus.c \
|
||||
App/Src/app_line_seek.c \
|
||||
App/Src/app_ultrasonic.c \
|
||||
Core/Src/delay.c \
|
||||
Core/Src/dma.c \
|
||||
Core/Src/gpio.c \
|
||||
Core/Src/i2c.c \
|
||||
Core/Src/main.c \
|
||||
Core/Src/stm32f1xx_hal_msp.c \
|
||||
Core/Src/stm32f1xx_it.c \
|
||||
|
@ -56,20 +58,25 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
|
|||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
||||
User/Src/bluetooth.c \
|
||||
User/Src/control.c \
|
||||
User/Src/hcsr04.c \
|
||||
User/Src/led.c \
|
||||
User/Src/line_seek.c \
|
||||
User/Src/motor.c \
|
||||
User/Src/path_plan.c
|
||||
Peripheral/Src/bluetooth.c \
|
||||
Peripheral/Src/buzzer.c \
|
||||
Peripheral/Src/control.c \
|
||||
Peripheral/Src/hcsr04.c \
|
||||
Peripheral/Src/infrared.c \
|
||||
Peripheral/Src/led.c \
|
||||
Peripheral/Src/line_seek.c \
|
||||
Peripheral/Src/motor.c \
|
||||
Peripheral/Src/servo.c \
|
||||
Peripheral/Src/syn6288.c \
|
||||
Service/Src/block_detect.c \
|
||||
Service/Src/path_plan.c \
|
||||
Service/Src/timer.c
|
||||
|
||||
|
||||
CPP_SOURCES = \
|
||||
|
@ -147,7 +154,8 @@ C_INCLUDES = \
|
|||
-IDrivers/CMSIS/Include \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
||||
-IUser/Inc
|
||||
-IPeripheral/Inc \
|
||||
-IService/Inc
|
||||
|
||||
|
||||
|
||||
|
|
15
Service/Inc/block_detect.h
Normal file
15
Service/Inc/block_detect.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef __BLOCK_DETECT_H
|
||||
#define __BLOCK_DETECT_H
|
||||
|
||||
// 定义障碍方向枚举
|
||||
typedef enum
|
||||
{
|
||||
FRONT,
|
||||
LEFT_FRONT,
|
||||
RIGHT_FRONT
|
||||
} BlockDirection;
|
||||
|
||||
void BlockDetect_Init();
|
||||
int Has_Block(BlockDirection direction);
|
||||
|
||||
#endif
|
|
@ -6,24 +6,13 @@ typedef enum
|
|||
{
|
||||
STRAIGHT,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
STOP
|
||||
RIGHT
|
||||
} Direction;
|
||||
|
||||
// 定义路径规划器结构
|
||||
typedef struct
|
||||
{
|
||||
int currentStep;
|
||||
Direction* path;
|
||||
int pathLength;
|
||||
} PathPlanner;
|
||||
|
||||
// 全局路径规划器
|
||||
extern PathPlanner pathPlanner;
|
||||
|
||||
void PathPlanner_Init();
|
||||
Direction GetCurrentDirection();
|
||||
Direction GetNextDirection();
|
||||
void AddPathStep(Direction step);
|
||||
void ReplacePathStep(Direction* step, int n);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,14 +3,13 @@
|
|||
|
||||
#include "main.h"
|
||||
|
||||
#define EVENT_LED 0
|
||||
#define EVENT_BUZZER 1
|
||||
#define EVENT_BLUETOOTH 2
|
||||
#define EVENT_SERVO 3
|
||||
#define EVENT_MAX 4
|
||||
#define EVENT_MAX 20
|
||||
|
||||
void TIMER_Init(void);
|
||||
void TIMER_AddLoopEvent(uint8_t type, void (*func)(void), uint16_t loop_time);
|
||||
void TIMER_DelLoopEvent(uint8_t type);
|
||||
int8_t TIMER_AddInfiniteLoopEvent(int8_t id, void (*func)(void), uint16_t loop_time);
|
||||
int8_t TIMER_AddFiniteLoopEvent(int8_t id, void (*func)(void), uint16_t loop_time, uint16_t loop_cnt);
|
||||
int8_t TIMER_AddFiniteLoopEventWithParam(int8_t event_id, void (*func)(uint16_t param), uint16_t loop_time, uint16_t loop_cnt, uint16_t param);
|
||||
int8_t TIMER_AddDelayEvent(int8_t id, void (*func)(void), uint16_t delay_time);
|
||||
void TIMER_DelLoopEvent(int8_t id);
|
||||
|
||||
#endif
|
||||
|
|
64
Service/Src/block_detect.c
Normal file
64
Service/Src/block_detect.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include "block_detect.h"
|
||||
|
||||
#include "bluetooth.h"
|
||||
#include "buzzer.h"
|
||||
#include "hcsr04.h"
|
||||
#include "infrared.h"
|
||||
#include "syscalls.h"
|
||||
#include "timer.h"
|
||||
|
||||
int has_block_front;
|
||||
int has_block_left;
|
||||
int has_block_right;
|
||||
static uint8_t timer_event_id = -1;
|
||||
static uint8_t timer_event_id2 = -1;
|
||||
|
||||
void INFRARED_Detect();
|
||||
void Sonar_Detect();
|
||||
|
||||
// 避障检测初始化
|
||||
void BlockDetect_Init()
|
||||
{
|
||||
timer_event_id = TIMER_AddInfiniteLoopEvent(timer_event_id, INFRARED_Detect, 20);
|
||||
timer_event_id2 = TIMER_AddInfiniteLoopEvent(timer_event_id2, Sonar_Detect, 150);
|
||||
}
|
||||
|
||||
// 每20ms红外检测一次障碍物
|
||||
void INFRARED_Detect()
|
||||
{
|
||||
has_block_left = INFRARED_GetL() == INFRARED_MEET;
|
||||
has_block_right = INFRARED_GetR() == INFRARED_MEET;
|
||||
}
|
||||
|
||||
// 每100ms超声波检测一次障碍物
|
||||
void Sonar_Detect()
|
||||
{
|
||||
if (sonor_state == 0) sonar_mm();
|
||||
}
|
||||
|
||||
// 超声波测距完毕回调
|
||||
void Sonar_CP_Callback()
|
||||
{
|
||||
// BLUETOOTH_Send("f: %d, l: %d, r: %d\n sonar distance = %d (mm)\n", has_block_front, has_block_left, has_block_right, sonor_distance);
|
||||
has_block_front = sonor_distance < 200;
|
||||
}
|
||||
|
||||
int Has_Block(BlockDirection direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case FRONT:
|
||||
BUZZER_StartTimed(10);
|
||||
return has_block_front;
|
||||
break;
|
||||
case LEFT_FRONT:
|
||||
BUZZER_StartTimed(2);
|
||||
return has_block_left;
|
||||
break;
|
||||
case RIGHT_FRONT:
|
||||
BUZZER_StartTimed(2);
|
||||
return has_block_right;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -4,8 +4,16 @@
|
|||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
// 全局路径规划器
|
||||
PathPlanner pathPlanner;
|
||||
// 定义路径规划器结构
|
||||
typedef struct
|
||||
{
|
||||
int currentStep;
|
||||
Direction* path;
|
||||
int pathLength;
|
||||
} PathPlanner;
|
||||
|
||||
// 路径规划器
|
||||
static PathPlanner pathPlanner;
|
||||
|
||||
void SetPath();
|
||||
|
||||
|
@ -24,9 +32,38 @@ void SetPath()
|
|||
int i;
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
AddPathStep(LEFT);
|
||||
AddPathStep(RIGHT);
|
||||
AddPathStep(STRAIGHT);
|
||||
AddPathStep(STRAIGHT);
|
||||
AddPathStep(STRAIGHT);
|
||||
AddPathStep(RIGHT);
|
||||
AddPathStep(LEFT);
|
||||
AddPathStep(STRAIGHT);
|
||||
AddPathStep(STRAIGHT);
|
||||
AddPathStep(LEFT);
|
||||
AddPathStep(STRAIGHT);
|
||||
AddPathStep(STRAIGHT);
|
||||
AddPathStep(STRAIGHT);
|
||||
AddPathStep(LEFT);
|
||||
AddPathStep(LEFT);
|
||||
AddPathStep(LEFT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(LEFT);
|
||||
// AddPathStep(LEFT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(RIGHT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(LEFT);
|
||||
// AddPathStep(LEFT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
// AddPathStep(STRAIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,3 +89,13 @@ void AddPathStep(Direction step)
|
|||
pathPlanner.path = realloc(pathPlanner.path, ++pathPlanner.pathLength * sizeof(Direction));
|
||||
pathPlanner.path[pathPlanner.pathLength - 1] = step;
|
||||
}
|
||||
|
||||
// 替换接下来的n个路径方向
|
||||
void ReplacePathStep(Direction* step, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
pathPlanner.path[(pathPlanner.currentStep + 1 + i) % pathPlanner.pathLength] = step[i];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,35 @@
|
|||
#include "timer.h"
|
||||
#include "tim.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "tim.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INFINITE_LOOP_EVENT, // 无限循环事件
|
||||
FINITE_LOOP_EVENT, // 有限循环事件
|
||||
FINITE_LOOP_EVENT_WITH_PARAM,
|
||||
DELAY_EVENT // 延迟事件
|
||||
} EventType;
|
||||
|
||||
typedef struct Event
|
||||
{
|
||||
uint8_t id;
|
||||
void (*func)(void);
|
||||
void (*param_func)(uint16_t);
|
||||
uint16_t time;
|
||||
EventType type;
|
||||
uint8_t enabled;
|
||||
uint16_t loop_cnt;
|
||||
uint32_t begin_time;
|
||||
uint16_t param;
|
||||
} Event;
|
||||
|
||||
static Event event[EVENT_MAX];
|
||||
static uint32_t time_cnt;
|
||||
static uint32_t time_lcm = 1;
|
||||
static int event_cnt;
|
||||
static uint32_t current_time;
|
||||
|
||||
uint32_t gcd(uint32_t a, uint32_t b);
|
||||
uint32_t lcm(uint32_t a, uint32_t b);
|
||||
|
||||
void TIMER_Count(void);
|
||||
void TIMER_Count(TIM_HandleTypeDef *htim);
|
||||
|
||||
void TIMER_Init(void)
|
||||
{
|
||||
|
@ -24,41 +37,124 @@ void TIMER_Init(void)
|
|||
HAL_TIM_Base_Start_IT(&htim4);
|
||||
}
|
||||
|
||||
/// @brief 注册定时回调事件
|
||||
/// @brief 注册无限循环定时回调事件
|
||||
/// @param func 回调函数 void func(void)
|
||||
/// @param loop_time 定时时间,单位毫秒
|
||||
void TIMER_AddLoopEvent(uint8_t type, void (*func)(void), uint16_t loop_time)
|
||||
int8_t TIMER_AddInfiniteLoopEvent(int8_t event_id, void (*func)(void), uint16_t loop_time)
|
||||
{
|
||||
event[type].func = func;
|
||||
event[type].time = loop_time;
|
||||
event[type].enabled = 1;
|
||||
time_lcm = lcm(time_lcm, loop_time);
|
||||
if (event_id == -1) event_id = event_cnt++;
|
||||
event[event_id].type = INFINITE_LOOP_EVENT;
|
||||
event[event_id].id = event_id;
|
||||
event[event_id].func = func;
|
||||
event[event_id].time = loop_time;
|
||||
event[event_id].begin_time = current_time;
|
||||
event[event_id].enabled = 1;
|
||||
return event_id;
|
||||
}
|
||||
|
||||
void TIMER_DelLoopEvent(uint8_t type)
|
||||
/// @brief 注册有限循环定时回调事件
|
||||
/// @param func 回调函数 void func(void)
|
||||
/// @param loop_time 定时时间,单位毫秒
|
||||
/// @param loop_cnt 循环次数
|
||||
int8_t TIMER_AddFiniteLoopEventWithParam(int8_t event_id, void (*func)(uint16_t param), uint16_t loop_time, uint16_t loop_cnt, uint16_t param)
|
||||
{
|
||||
event[type].enabled = 0;
|
||||
time_lcm /= event[type].time;
|
||||
if (event_id == -1) event_id = event_cnt++;
|
||||
event[event_id].type = FINITE_LOOP_EVENT_WITH_PARAM;
|
||||
event[event_id].id = event_id;
|
||||
event[event_id].param_func = func;
|
||||
event[event_id].time = loop_time;
|
||||
event[event_id].begin_time = current_time;
|
||||
event[event_id].enabled = 1;
|
||||
event[event_id].param = param;
|
||||
event[event_id].loop_cnt = loop_cnt;
|
||||
return event_id;
|
||||
}
|
||||
|
||||
void TIMER_Count(void)
|
||||
int8_t TIMER_AddFiniteLoopEvent(int8_t event_id, void (*func)(void), uint16_t loop_time, uint16_t loop_cnt)
|
||||
{
|
||||
++time_cnt;
|
||||
for (uint8_t i = 0; i < EVENT_MAX; ++i)
|
||||
if (event[i].enabled && time_cnt % event[i].time == 0)
|
||||
if (event_id == -1) event_id = event_cnt++;
|
||||
event[event_id].type = FINITE_LOOP_EVENT;
|
||||
event[event_id].id = event_id;
|
||||
event[event_id].func = func;
|
||||
event[event_id].time = loop_time;
|
||||
event[event_id].begin_time = current_time;
|
||||
event[event_id].enabled = 1;
|
||||
event[event_id].loop_cnt = loop_cnt;
|
||||
return event_id;
|
||||
}
|
||||
|
||||
/// @brief 注册延迟定时回调事件(单次)
|
||||
/// @param func 回调函数 void func(void)
|
||||
/// @param loop_time 定时时间,单位毫秒
|
||||
int8_t TIMER_AddDelayEvent(int8_t event_id, void (*func)(void), uint16_t delay_time)
|
||||
{
|
||||
if (event_id == -1) event_id = event_cnt++;
|
||||
event[event_id].type = DELAY_EVENT;
|
||||
event[event_id].id = event_id;
|
||||
event[event_id].func = func;
|
||||
event[event_id].time = delay_time;
|
||||
event[event_id].begin_time = current_time;
|
||||
event[event_id].enabled = 1;
|
||||
return event_id;
|
||||
}
|
||||
|
||||
void TIMER_DelLoopEvent(int8_t id)
|
||||
{
|
||||
event[id].enabled = 0;
|
||||
}
|
||||
|
||||
void TIMER_Count(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
++current_time;
|
||||
for (uint8_t i = 0; i < event_cnt; ++i)
|
||||
{
|
||||
if (event[i].enabled == 0)
|
||||
continue;
|
||||
|
||||
switch (event[i].type)
|
||||
{
|
||||
case INFINITE_LOOP_EVENT: // 无限循环事件
|
||||
if ((current_time - event[i].begin_time) % event[i].time == 0)
|
||||
{
|
||||
event[i].func();
|
||||
if (time_cnt == time_lcm)
|
||||
time_cnt = 0;
|
||||
}
|
||||
|
||||
uint32_t gcd(uint32_t a, uint32_t b)
|
||||
{
|
||||
if (b == 0)
|
||||
return a;
|
||||
return gcd(b, a % b);
|
||||
}
|
||||
|
||||
uint32_t lcm(uint32_t a, uint32_t b)
|
||||
{
|
||||
return a / gcd(a, b) * b;
|
||||
}
|
||||
break;
|
||||
case FINITE_LOOP_EVENT: // 有限循环事件
|
||||
if ((current_time - event[i].begin_time) % event[i].time == 0)
|
||||
{
|
||||
event[i].func();
|
||||
if (event[i].loop_cnt-- <= 0)
|
||||
{
|
||||
TIMER_DelLoopEvent(event[i].id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FINITE_LOOP_EVENT_WITH_PARAM:
|
||||
if ((current_time - event[i].begin_time) % event[i].time == 0)
|
||||
{
|
||||
printf("FINITE_LOOP_EVENT_WITH_PARAM %d, %d, %d\n",
|
||||
current_time, event[i].begin_time, event[i].time);
|
||||
event[i].param_func(event[i].param);
|
||||
if (--event[i].loop_cnt <= 0)
|
||||
{
|
||||
printf("remove FINITE_LOOP_EVENT_WITH_PARAM %d, %d, %d\n",
|
||||
current_time, event[i].begin_time, event[i].time);
|
||||
TIMER_DelLoopEvent(event[i].id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DELAY_EVENT: // 延迟事件
|
||||
if (current_time > event[i].begin_time &&
|
||||
(current_time - event[i].begin_time) % event[i].time == 0)
|
||||
{
|
||||
event[i].func();
|
||||
printf("DELAY_EVENT %d, %d, %d\n",
|
||||
current_time, event[i].begin_time, event[i].time);
|
||||
TIMER_DelLoopEvent(event[i].id);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user