feat: 公交车

This commit is contained in:
JasonChen 2024-07-20 10:44:59 +08:00
parent a76a286859
commit e518c278d7
30 changed files with 1120 additions and 557 deletions

View File

@ -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; CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousUsedMakefileFiles] [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; 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; CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER;

8
App/Inc/app_bus.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __APP_BUS_H
#define __APP_BUS_H
void BlockDetect_Init();
void App_Bus(void);
#endif

View File

@ -3,8 +3,13 @@
#include "tim.h" #include "tim.h"
extern int beep_time;
void LineSeek_Init(void); void LineSeek_Init(void);
void LineSeek_Start(void);
void LineSeek_Stop(void);
void App_LineSeek(void); void App_LineSeek(void);
void Hanlde_Crossroad(void); void Hanlde_Crossroad(void);
#endif #endif

98
App/Src/app_bus.c Normal file
View 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();
}

View File

@ -1,6 +1,9 @@
#include "app_line_seek.h" #include "app_line_seek.h"
#include "bluetooth.h"
#include "buzzer.h"
#include "led.h"
#include "line_seek.h" #include "line_seek.h"
#include "main.h" #include "main.h"
#include "motor.h" #include "motor.h"
@ -8,16 +11,15 @@
#include "stm32f1xx_hal_tim.h" #include "stm32f1xx_hal_tim.h"
#include "syscalls.h" #include "syscalls.h"
#include "tim.h" #include "tim.h"
#include "timer.h"
#define LOW_TUNE_SPEED -5 #define LOW_TUNE_SPEED -5
#define LOW_SPEED 35 #define LOW_SPEED 35
#define MID_SPEED 40 #define MID_SPEED 40
#define HIGH_SPEED 45 #define HIGH_SPEED 45
#define MIN_TURN_TIME 300 // 最小转直角时间 #define MIN_TURN_TIME 200 // 最小转直角时间
#define MIN_CROSSING_TIME 200 // 最小走十字路口时间 #define MIN_CROSSING_TIME 300 // 最小走十字路口时间
#define MIN_CROSSING_STRAIGHT_TIME 50 // 最小走十字路口时间 #define MIN_TUNE_TIME 30 // 最小微调时间
#define MIN_TUNE_TIME 40 // 最小微调时间
#define MAX_TURN_TIME 4000 // 最大转弯时间
typedef enum typedef enum
{ {
@ -27,41 +29,53 @@ typedef enum
TUNE_LEFT, // 左微调 TUNE_LEFT, // 左微调
TUNE_RIGHT, // 右微调 TUNE_RIGHT, // 右微调
TURN_LEFT_BIG, TURN_LEFT_BIG,
TURN_RIGHT_BIG TURN_RIGHT_BIG,
MOVE_STOP
} MoveState; } MoveState;
MoveState state, preState; // 运动状态 static MoveState state, preState; // 运动状态
int turn_time; // 转弯时间 int turn_time; // 转弯时间
int beep_time; // 蜂鸣器鸣叫时间
int is_crossing; // 是否正在走十字路口 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) if (turn_time < INT16_MAX)
{ {
turn_time++; // 每1ms自增一 turn_time++;
}
if (beep_time++ > 100)
{
HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_SET);
} }
} }
// 巡线功能初始化
void LineSeek_Init(void) void LineSeek_Init(void)
{ {
// 注册定时器中断溢出回调 // 注册定时器事件
HAL_TIM_RegisterCallback(&htim4, HAL_TIM_PERIOD_ELAPSED_CB_ID, LINESEEK_HAL_TIM_PeriodElapsedCallback); timer_event_id = TIMER_AddInfiniteLoopEvent(timer_event_id, LINESEEK_TURN_TIME, 1);
HAL_TIM_Base_Start_IT(&htim4); }
void LineSeek_Start(void)
{
if (state == MOVE_STOP)
{
state = MOVE_STRAIGHT;
}
}
void LineSeek_Stop(void)
{
state = MOVE_STOP;
} }
void App_LineSeek(void) void App_LineSeek(void)
{ {
int LineL1 = 1, LineL2 = 1, LineR1 = 1, LineR2 = 1; // LineSeek_GetStatusStr();
// LineSeek_GetStatus(&LineL1, &LineL2, &LineR1, &LineR2); // 获取黑线检测状态 // if (state != MOVE_STOP)
// {
LineSeek_GetStatusStr(); // 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); // printf("%s %d \n", LineSeek_Status, turn_time);
// return; // return;
@ -77,15 +91,19 @@ void App_LineSeek(void)
LineSeek_Status[3] = '1'; LineSeek_Status[3] = '1';
} }
if (LineSeek_Equals("0000") && !is_crossing && state != MOVE_STOP) // 十字路口
{
Hanlde_Crossroad();
return;
}
switch (state) switch (state)
{ {
case MOVE_STRAIGHT: // 直行 case MOVE_STRAIGHT: // 直行
LED_Stop(LED_ALL);
LED_Start(LED_R);
MOTOR_SetDuty(HIGH_SPEED, HIGH_SPEED); MOTOR_SetDuty(HIGH_SPEED, HIGH_SPEED);
if (LineSeek_Equals("0000")) // 十字路口 if (LineSeek_Equals("1011")) // 左微调
{
Hanlde_Crossroad();
}
else if (LineSeek_Equals("1011")) // 左微调
{ {
state = TUNE_LEFT; state = TUNE_LEFT;
} }
@ -117,18 +135,24 @@ void App_LineSeek(void)
} }
break; break;
case TURN_LEFT: // 左直角 case TURN_LEFT: // 左直角
LED_Stop(LED_ALL);
LED_Start(LED_G);
MOTOR_SetDuty(-HIGH_SPEED, HIGH_SPEED); MOTOR_SetDuty(-HIGH_SPEED, HIGH_SPEED);
if (LineSeek_Equals("0000")) // 十字路口 if (LineSeek_Equals("1001") &&
{
Hanlde_Crossroad();
}
else if (LineSeek_Equals("1001") &&
((preState != TUNE_LEFT && turn_time >= MIN_TURN_TIME - 1) || ((preState != TUNE_LEFT && turn_time >= MIN_TURN_TIME - 1) ||
(preState == TUNE_LEFT && turn_time >= MIN_TUNE_TIME))) // 直行 (preState == TUNE_LEFT && turn_time >= MIN_TUNE_TIME))) // 直行
{ {
state = MOVE_STRAIGHT; state = MOVE_STRAIGHT;
preState = TURN_LEFT; preState = TURN_LEFT;
is_crossing = 0; 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) // 转过头了 else if (LineSeek_Equals("xxx0") && !is_crossing) // 转过头了
{ {
@ -139,11 +163,7 @@ void App_LineSeek(void)
break; break;
case TURN_RIGHT: // 右直角 case TURN_RIGHT: // 右直角
MOTOR_SetDuty(HIGH_SPEED, -HIGH_SPEED); MOTOR_SetDuty(HIGH_SPEED, -HIGH_SPEED);
if (LineSeek_Equals("0000")) // 十字路口 if (LineSeek_Equals("1001") &&
{
Hanlde_Crossroad();
}
else if (LineSeek_Equals("1001") &&
((preState != TUNE_RIGHT && turn_time >= MIN_TURN_TIME - 1) || ((preState != TUNE_RIGHT && turn_time >= MIN_TURN_TIME - 1) ||
(preState == TUNE_RIGHT && turn_time >= MIN_TUNE_TIME))) // 直行 (preState == TUNE_RIGHT && turn_time >= MIN_TUNE_TIME))) // 直行
{ {
@ -151,6 +171,11 @@ void App_LineSeek(void)
preState = TURN_RIGHT; preState = TURN_RIGHT;
is_crossing = 0; 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) // 转过头了 else if (LineSeek_Equals("0xxx") && !is_crossing) // 转过头了
{ {
turn_time = MIN_TURN_TIME; turn_time = MIN_TURN_TIME;
@ -160,11 +185,7 @@ void App_LineSeek(void)
break; break;
case TURN_LEFT_BIG: // 左锐角 case TURN_LEFT_BIG: // 左锐角
MOTOR_SetDuty(-MID_SPEED, MID_SPEED); MOTOR_SetDuty(-MID_SPEED, MID_SPEED);
if (LineSeek_Equals("0000")) // 十字路口 if (LineSeek_Equals("0001")) // 左直角
{
Hanlde_Crossroad();
}
else if (LineSeek_Equals("0001")) // 左直角
{ {
turn_time = 0; turn_time = 0;
state = TURN_LEFT; state = TURN_LEFT;
@ -178,11 +199,7 @@ void App_LineSeek(void)
break; break;
case TURN_RIGHT_BIG: // 右锐角 case TURN_RIGHT_BIG: // 右锐角
MOTOR_SetDuty(MID_SPEED, -MID_SPEED); MOTOR_SetDuty(MID_SPEED, -MID_SPEED);
if (LineSeek_Equals("0000")) // 十字路口 if (LineSeek_Equals("1000")) // 右直角
{
Hanlde_Crossroad();
}
else if (LineSeek_Equals("1000")) // 右直角
{ {
turn_time = 0; turn_time = 0;
state = TURN_RIGHT; state = TURN_RIGHT;
@ -200,13 +217,13 @@ void App_LineSeek(void)
{ {
state = MOVE_STRAIGHT; state = MOVE_STRAIGHT;
} }
else if (LineSeek_Equals("0xx1") && GetCurrentDirection() != STRAIGHT) // 左转 else if (LineSeek_Equals("0xx1")) // 左转
{ {
turn_time = 0; turn_time = 0;
state = TURN_LEFT; state = TURN_LEFT;
preState = TUNE_LEFT; preState = TUNE_LEFT;
} }
else if (LineSeek_Equals("1xx0") && GetCurrentDirection() != STRAIGHT) // 右转 else if (LineSeek_Equals("1xx0")) // 右转
{ {
turn_time = 0; turn_time = 0;
state = TURN_RIGHT; state = TURN_RIGHT;
@ -219,47 +236,35 @@ void App_LineSeek(void)
{ {
state = MOVE_STRAIGHT; state = MOVE_STRAIGHT;
} }
else if (LineSeek_Equals("0xx1") && GetCurrentDirection() != STRAIGHT) // 左转 else if (LineSeek_Equals("0xx1")) // 左转
{ {
turn_time = 0; turn_time = 0;
state = TURN_LEFT; state = TURN_LEFT;
preState = TUNE_RIGHT; preState = TUNE_RIGHT;
} }
else if (LineSeek_Equals("1xx0") && GetCurrentDirection() != STRAIGHT) // 右转 else if (LineSeek_Equals("1xx0")) // 右转
{ {
turn_time = 0; turn_time = 0;
state = TURN_RIGHT; state = TURN_RIGHT;
preState = TUNE_RIGHT; preState = TUNE_RIGHT;
} }
break; break;
case MOVE_STOP:
MOTOR_Stop();
break;
default: default:
state = MOVE_STRAIGHT; state = MOVE_STRAIGHT;
MOTOR_SetDuty(MID_SPEED, MID_SPEED); MOTOR_SetDuty(MID_SPEED, MID_SPEED);
break; break;
} }
// if (turn_time >= MAX_TURN_TIME)
// {
// // state = MOVE_STRAIGHT;
// MOTOR_SetDuty(0, 0);
// }
// printf("curr state: %d \n", state); // printf("curr state: %d \n", state);
} }
void Hanlde_Crossroad(void) void Hanlde_Crossroad(void)
{ {
if (is_crossing) // 开启蜂鸣器
{ BUZZER_StartTimed(1);
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);
// 根据规划的路径进行决断 // 根据规划的路径进行决断
is_crossing = 1; is_crossing = 1;

View File

@ -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); // 直走
}
}

View File

@ -35,7 +35,8 @@ int APP_Find_Direction(void)
else if(left_block < BLOCK_DISTANCE && right_block < BLOCK_DISTANCE && straight_block < BLOCK_DISTANCE)// 前左右均有障碍物,停止并鸣笛 else if(left_block < BLOCK_DISTANCE && right_block < BLOCK_DISTANCE && straight_block < BLOCK_DISTANCE)// 前左右均有障碍物,停止并鸣笛
{ {
LED_SetDuty(255,0,0); LED_SetDuty(255,0,0);
return STOP; // return STOP;
return -1;
} }
else if(straight_block < BLOCK_DISTANCE && left_block < BLOCK_DISTANCE)// 前左有障碍物,右转 else if(straight_block < BLOCK_DISTANCE && left_block < BLOCK_DISTANCE)// 前左有障碍物,右转
{ {

17
CAR.ioc
View File

@ -4,7 +4,17 @@ CAD.pinconfig=
CAD.provider= CAD.provider=
Dma.Request0=USART2_RX Dma.Request0=USART2_RX
Dma.Request1=USART2_TX 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.Direction=DMA_PERIPH_TO_MEMORY
Dma.USART2_RX.0.Instance=DMA1_Channel6 Dma.USART2_RX.0.Instance=DMA1_Channel6
Dma.USART2_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE Dma.USART2_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE
@ -82,7 +92,6 @@ MxCube.Version=6.12.0
MxDb.Version=DB.6.0.120 MxDb.Version=DB.6.0.120
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 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_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.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.EXTI15_10_IRQn=true\:2\:0\:true\:false\:true\:true\:true\:true
NVIC.ForceEnableDMAVector=false NVIC.ForceEnableDMAVector=false
@ -228,7 +237,7 @@ ProjectManager.ProjectName=CAR
ProjectManager.ProjectStructure= ProjectManager.ProjectStructure=
ProjectManager.RegisterCallBack=TIM ProjectManager.RegisterCallBack=TIM
ProjectManager.StackSize=0x400 ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=MDK-ARM V5.32 ProjectManager.TargetToolchain=Makefile
ProjectManager.ToolChainLocation= ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath= ProjectManager.UAScriptBeforePath=
@ -296,7 +305,7 @@ TIM4.Period=100 - 1
TIM4.Prescaler=720 - 1 TIM4.Prescaler=720 - 1
TIM4.Pulse-PWM\ Generation1\ CH1=0 TIM4.Pulse-PWM\ Generation1\ CH1=0
TIM4.Pulse-PWM\ Generation2\ CH2=0 TIM4.Pulse-PWM\ Generation2\ CH2=0
USART1.BaudRate=115200 USART1.BaudRate=9600
USART1.IPParameters=VirtualMode,BaudRate,Parity,WordLength USART1.IPParameters=VirtualMode,BaudRate,Parity,WordLength
USART1.Parity=PARITY_NONE USART1.Parity=PARITY_NONE
USART1.VirtualMode=VM_ASYNC USART1.VirtualMode=VM_ASYNC

10
Core/Inc/delay.h Normal file
View 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

View File

@ -8,11 +8,19 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "usart.h" #include "usart.h"
#define DEFAULT_HUART 1
#define HUART1 (&huart1) #define HUART1 (&huart1)
#define HUART2 (&huart2) #define HUART2 (&huart2)
#if DEFAULT_HUART == 1
#define HUART HUART1
#else
#define HUART HUART2
#endif
// 条件编译,适配不同平台 (GNU, GCC) // 条件编译,适配不同平台 (GNU, GCC)
#ifdef __GNUC__ #ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
@ -25,10 +33,7 @@
int _read(int file, char *ptr, int len); int _read(int file, char *ptr, int len);
int _write(int file, char *ptr, int len); int _write(int file, char *ptr, int len);
PUTCHAR_PROTOTYPE; int myprintf(const char *format, ...);
GETCHAR_PROTOTYPE;
void delay_us(uint16_t us);
void my_printf(UART_HandleTypeDef *huart, const char *buf, ...); void my_printf(UART_HandleTypeDef *huart, const char *buf, ...);
#endif #endif

127
Core/Src/delay.c Normal file
View 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 //当使用FreeRTOSTimebase Source为其他定时器时改为0
#if (!Timebase_Source_is_SysTick)
extern TIM_HandleTypeDef htimx; //当使用FreeRTOSTimebase 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)
{
}
}

View File

@ -18,20 +18,25 @@
/* USER CODE END Header */ /* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "main.h" #include "main.h"
#include "dma.h" #include "dma.h"
#include "gpio.h"
#include "tim.h" #include "tim.h"
#include "usart.h" #include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include "app_bus.h"
#include "app_line_seek.h" #include "app_line_seek.h"
#include "block_detect.h"
#include "bluetooth.h" #include "bluetooth.h"
#include "buzzer.h" #include "buzzer.h"
#include "delay.h"
#include "hcsr04.h" #include "hcsr04.h"
#include "led.h" #include "led.h"
#include "motor.h" #include "motor.h"
#include "path_plan.h" #include "path_plan.h"
#include "servo.h"
#include "syscalls.h" #include "syscalls.h"
#include "timer.h" #include "timer.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@ -54,7 +59,11 @@
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */ /* USER CODE BEGIN PV */
int printf_event_id = -1;
void Print(uint16_t time)
{
printf("timed print: %d\n", time);
}
/* USER CODE END PV */ /* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
@ -77,10 +86,9 @@ void SystemClock_Config(void);
*/ */
int main(void) int main(void)
{ {
/* USER CODE BEGIN 1 */ /* USER CODE BEGIN 1 */
int i = 0;
uint8_t pData[10] = {1, 2, 3}; char pData[] = "hello world";
/* USER CODE END 1 */ /* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/ /* MCU Configuration--------------------------------------------------------*/
@ -107,39 +115,58 @@ int main(void)
MX_TIM3_Init(); MX_TIM3_Init();
MX_TIM4_Init(); MX_TIM4_Init();
// MX_USART1_UART_Init(); // MX_USART1_UART_Init();
// MX_USART2_UART_Init(); MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
// HC_SR04_Init(); HAL_Delay(500);
// BLUETOOTH_Init();
// MOTOR_Init(); delay_init();
// PathPlanner_Init();
// LineSeek_Init();
TIMER_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 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
while (1) while (1)
{ {
// printf("printf: %s \r\n", pData);
BUZZER_StartTimed(3); // myprintf("myprintf: %s \r\n", pData);
HAL_Delay(1000); // BUZZER_StartTimed(5);
// my_printf(HUART1, "%s\r\n", *pData); // 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)) // 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(500);
// } // }
// HAL_Delay(2000); // 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(); // App_LineSeek();
// MOTOR_SetDuty(-20,20); // MOTOR_SetDuty(-20,20);
// HAL_Delay(300); // ??300??
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */

View File

@ -1,7 +1,7 @@
#include "syscalls.h" #include "syscalls.h"
extern UART_HandleTypeDef huart1; volatile uint8_t usart_dma_tx_over = 1;
// 条件编译,适配不同平台 (GNU, GCC) // 条件编译,适配不同平台 (GNU, GCC)
#ifdef __GNUC__ #ifdef __GNUC__
@ -42,7 +42,7 @@ __attribute__((weak)) int _write(int file, char *ptr, int len)
*/ */
PUTCHAR_PROTOTYPE 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; return ch;
} }
@ -58,20 +58,47 @@ PUTCHAR_PROTOTYPE
GETCHAR_PROTOTYPE GETCHAR_PROTOTYPE
{ {
uint8_t ch = 0; 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; 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); #if DEFAULT_HUART == 1
while (delay--); if (huart->Instance == USART1)
#else
if (huart->Instance == USART2)
#endif
{
usart_dma_tx_over = 1;
}
} }
/** /**
* @brief printf * @brief printf使DEFAULT_HUARTDMA串口中断方式发送
* @param huart, buf *
* @return void * @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"); * @usage my_printf(HUART1, "USART1_Target:\r\n");
*/ */

View File

@ -26,6 +26,7 @@
UART_HandleTypeDef huart1; UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2; UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart1_tx;
DMA_HandleTypeDef hdma_usart2_rx; DMA_HandleTypeDef hdma_usart2_rx;
DMA_HandleTypeDef hdma_usart2_tx; DMA_HandleTypeDef hdma_usart2_tx;
@ -42,7 +43,7 @@ void MX_USART1_UART_Init(void)
/* USER CODE END USART1_Init 1 */ /* USER CODE END USART1_Init 1 */
huart1.Instance = USART1; huart1.Instance = USART1;
huart1.Init.BaudRate = 115200; huart1.Init.BaudRate = 9600;
huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Parity = UART_PARITY_NONE;
@ -115,6 +116,23 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 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 */ /* USART1 interrupt Init */
HAL_NVIC_SetPriority(USART1_IRQn, 3, 1); HAL_NVIC_SetPriority(USART1_IRQn, 3, 1);
HAL_NVIC_EnableIRQ(USART1_IRQn); 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); HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
/* USART1 DMA DeInit */
HAL_DMA_DeInit(uartHandle->hdmatx);
/* USART1 interrupt Deinit */ /* USART1 interrupt Deinit */
HAL_NVIC_DisableIRQ(USART1_IRQn); HAL_NVIC_DisableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE BEGIN USART1_MspDeInit 1 */

View File

@ -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"> <ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd">
<SchemaVersion>1.0</SchemaVersion> <SchemaVersion>1.0</SchemaVersion>
@ -45,7 +45,7 @@
<PageWidth>79</PageWidth> <PageWidth>79</PageWidth>
<PageLength>66</PageLength> <PageLength>66</PageLength>
<TabStop>8</TabStop> <TabStop>8</TabStop>
<ListingPath /> <ListingPath></ListingPath>
</OPTLEX> </OPTLEX>
<ListingPage> <ListingPage>
<CreateCListing>1</CreateCListing> <CreateCListing>1</CreateCListing>
@ -104,16 +104,16 @@
<bSchkAxf>0</bSchkAxf> <bSchkAxf>0</bSchkAxf>
<bTchkAxf>0</bTchkAxf> <bTchkAxf>0</bTchkAxf>
<nTsel>3</nTsel> <nTsel>3</nTsel>
<sDll /> <sDll></sDll>
<sDllPa /> <sDllPa></sDllPa>
<sDlgDll /> <sDlgDll></sDlgDll>
<sDlgPa /> <sDlgPa></sDlgPa>
<sIfile /> <sIfile></sIfile>
<tDll /> <tDll></tDll>
<tDllPa /> <tDllPa></tDllPa>
<tDlgDll /> <tDlgDll></tDlgDll>
<tDlgPa /> <tDlgPa></tDlgPa>
<tIfile /> <tIfile></tIfile>
<pMon>BIN\CMSIS_AGDI.dll</pMon> <pMon>BIN\CMSIS_AGDI.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
@ -130,7 +130,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>ARMDBGFLAGS</Key> <Key>ARMDBGFLAGS</Key>
<Name /> <Name></Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -140,7 +140,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGUARM</Key> <Key>DLGUARM</Key>
<Name /> <Name></Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -152,25 +152,9 @@
<Bp> <Bp>
<Number>0</Number> <Number>0</Number>
<Type>0</Type> <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> <LineNumber>32</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>134221058</Address> <Address>134222756</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
<HtxType>0</HtxType> <HtxType>0</HtxType>
<ManyObjects>0</ManyObjects> <ManyObjects>0</ManyObjects>
@ -178,28 +162,60 @@
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount> <BreakIfRCount>1</BreakIfRCount>
<Filename>..\Peripheral\Src\control.c</Filename> <Filename>..\Peripheral\Src\control.c</Filename>
<ExecCommand /> <ExecCommand></ExecCommand>
<Expression>\\CAR\../Peripheral/Src/control.c\32</Expression> <Expression>\\CAR\../Peripheral/Src/control.c\32</Expression>
</Bp> </Bp>
<Bp> <Bp>
<Number>2</Number> <Number>1</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>24</LineNumber> <LineNumber>15</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>0</Address> <Address>134222672</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
<HtxType>0</HtxType> <HtxType>0</HtxType>
<ManyObjects>0</ManyObjects> <ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject> <SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount> <BreakIfRCount>1</BreakIfRCount>
<Filename>startup_stm32f103xb.s</Filename> <Filename>..\Peripheral\Src\buzzer.c</Filename>
<ExecCommand /> <ExecCommand></ExecCommand>
<Expression /> <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>
<Bp> <Bp>
<Number>3</Number> <Number>3</Number>
<Type>0</Type> <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> <LineNumber>97</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>0</Address> <Address>0</Address>
@ -210,11 +226,11 @@
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount> <BreakIfRCount>0</BreakIfRCount>
<Filename>startup_stm32f103xb.s</Filename> <Filename>startup_stm32f103xb.s</Filename>
<ExecCommand /> <ExecCommand></ExecCommand>
<Expression /> <Expression></Expression>
</Bp> </Bp>
<Bp> <Bp>
<Number>4</Number> <Number>5</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>99</LineNumber> <LineNumber>99</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
@ -226,8 +242,8 @@
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount> <BreakIfRCount>0</BreakIfRCount>
<Filename>startup_stm32f103xb.s</Filename> <Filename>startup_stm32f103xb.s</Filename>
<ExecCommand /> <ExecCommand></ExecCommand>
<Expression /> <Expression></Expression>
</Bp> </Bp>
</Breakpoint> </Breakpoint>
<WatchWindow1> <WatchWindow1>
@ -282,19 +298,19 @@
<newCpu>0</newCpu> <newCpu>0</newCpu>
<uProt>0</uProt> <uProt>0</uProt>
</DebugFlag> </DebugFlag>
<LintExecutable /> <LintExecutable></LintExecutable>
<LintConfigFile /> <LintConfigFile></LintConfigFile>
<bLintAuto>0</bLintAuto> <bLintAuto>0</bLintAuto>
<bAutoGenD>0</bAutoGenD> <bAutoGenD>0</bAutoGenD>
<LntExFlags>0</LntExFlags> <LntExFlags>0</LntExFlags>
<pMisraName /> <pMisraName></pMisraName>
<pszMrule /> <pszMrule></pszMrule>
<pSingCmds /> <pSingCmds></pSingCmds>
<pMultCmds /> <pMultCmds></pMultCmds>
<pMisraNamep /> <pMisraNamep></pMisraNamep>
<pszMrulep /> <pszMrulep></pszMrulep>
<pSingCmdsp /> <pSingCmdsp></pSingCmdsp>
<pMultCmdsp /> <pMultCmdsp></pMultCmdsp>
<DebugDescription> <DebugDescription>
<Enable>1</Enable> <Enable>1</Enable>
<EnableFlashSeq>1</EnableFlashSeq> <EnableFlashSeq>1</EnableFlashSeq>
@ -459,17 +475,29 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<bShared>0</bShared> <bShared>0</bShared>
</File> </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>
<Group> <Group>
<GroupName>Application/User/Service</GroupName> <GroupName>Application/User/Service</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>4</GroupNumber> <GroupNumber>4</GroupNumber>
<FileNumber>12</FileNumber> <FileNumber>13</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -481,7 +509,7 @@
</File> </File>
<File> <File>
<GroupNumber>4</GroupNumber> <GroupNumber>4</GroupNumber>
<FileNumber>13</FileNumber> <FileNumber>14</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -491,17 +519,29 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<bShared>0</bShared> <bShared>0</bShared>
</File> </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>
<Group> <Group>
<GroupName>Application/User/Peripheral</GroupName> <GroupName>Application/User/Peripheral</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>14</FileNumber> <FileNumber>16</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -513,7 +553,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>15</FileNumber> <FileNumber>17</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -525,7 +565,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>16</FileNumber> <FileNumber>18</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -537,7 +577,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>17</FileNumber> <FileNumber>19</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -549,7 +589,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>18</FileNumber> <FileNumber>20</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -561,7 +601,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>19</FileNumber> <FileNumber>21</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -573,7 +613,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>20</FileNumber> <FileNumber>22</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -585,7 +625,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>21</FileNumber> <FileNumber>23</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -597,7 +637,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>22</FileNumber> <FileNumber>24</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -609,7 +649,7 @@
</File> </File>
<File> <File>
<GroupNumber>5</GroupNumber> <GroupNumber>5</GroupNumber>
<FileNumber>23</FileNumber> <FileNumber>25</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -629,7 +669,7 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>24</FileNumber> <FileNumber>26</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -641,7 +681,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>25</FileNumber> <FileNumber>27</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -653,7 +693,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>26</FileNumber> <FileNumber>28</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -665,7 +705,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>27</FileNumber> <FileNumber>29</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -677,7 +717,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>28</FileNumber> <FileNumber>30</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -689,7 +729,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>29</FileNumber> <FileNumber>31</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -701,7 +741,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>30</FileNumber> <FileNumber>32</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -713,7 +753,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>31</FileNumber> <FileNumber>33</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -725,7 +765,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>32</FileNumber> <FileNumber>34</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -737,7 +777,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>33</FileNumber> <FileNumber>35</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -749,7 +789,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>34</FileNumber> <FileNumber>36</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -761,7 +801,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>35</FileNumber> <FileNumber>37</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -773,7 +813,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>36</FileNumber> <FileNumber>38</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -785,7 +825,7 @@
</File> </File>
<File> <File>
<GroupNumber>6</GroupNumber> <GroupNumber>6</GroupNumber>
<FileNumber>37</FileNumber> <FileNumber>39</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@ -805,7 +845,7 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>7</GroupNumber> <GroupNumber>7</GroupNumber>
<FileNumber>38</FileNumber> <FileNumber>40</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>

View File

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="project_projx.xsd"> <Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
<SchemaVersion>2.1</SchemaVersion> <SchemaVersion>2.1</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header> <Header>### uVision Project, (C) Keil Software</Header>
<Targets> <Targets>
<Target> <Target>
<TargetName>CAR</TargetName> <TargetName>CAR</TargetName>
@ -13,31 +16,31 @@
<TargetCommonOption> <TargetCommonOption>
<Device>STM32F103C8</Device> <Device>STM32F103C8</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.2.4.1</PackID> <PackID>Keil.STM32F1xx_DFP.2.2.0</PackID>
<PackURL>https://www.keil.com/pack/</PackURL> <PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000-0x20004FFF) IROM(0x8000000-0x800FFFF) CLOCK(8000000) CPUTYPE("Cortex-M3") TZ</Cpu> <Cpu>IRAM(0x20000000-0x20004FFF) IROM(0x8000000-0x800FFFF) CLOCK(8000000) CPUTYPE("Cortex-M3") TZ</Cpu>
<FlashUtilSpec /> <FlashUtilSpec></FlashUtilSpec>
<StartupFile /> <StartupFile></StartupFile>
<FlashDriverDll /> <FlashDriverDll></FlashDriverDll>
<DeviceId>0</DeviceId> <DeviceId>0</DeviceId>
<RegisterFile /> <RegisterFile></RegisterFile>
<MemoryEnv /> <MemoryEnv></MemoryEnv>
<Cmp /> <Cmp></Cmp>
<Asm /> <Asm></Asm>
<Linker /> <Linker></Linker>
<OHString /> <OHString></OHString>
<InfinionOptionDll /> <InfinionOptionDll></InfinionOptionDll>
<SLE66CMisc /> <SLE66CMisc></SLE66CMisc>
<SLE66AMisc /> <SLE66AMisc></SLE66AMisc>
<SLE66LinkerMisc /> <SLE66LinkerMisc></SLE66LinkerMisc>
<SFDFile>$$Device:STM32F103C8$SVD\STM32F103xx.svd</SFDFile> <SFDFile>$$Device:STM32F103C8$SVD\STM32F103xx.svd</SFDFile>
<bCustSvd>0</bCustSvd> <bCustSvd>0</bCustSvd>
<UseEnv>0</UseEnv> <UseEnv>0</UseEnv>
<BinPath /> <BinPath></BinPath>
<IncludePath /> <IncludePath></IncludePath>
<LibPath /> <LibPath></LibPath>
<RegisterFilePath /> <RegisterFilePath></RegisterFilePath>
<DBRegisterFilePath /> <DBRegisterFilePath></DBRegisterFilePath>
<TargetStatus> <TargetStatus>
<Error>0</Error> <Error>0</Error>
<ExitCodeStop>0</ExitCodeStop> <ExitCodeStop>0</ExitCodeStop>
@ -52,15 +55,15 @@
<CreateHexFile>1</CreateHexFile> <CreateHexFile>1</CreateHexFile>
<DebugInformation>1</DebugInformation> <DebugInformation>1</DebugInformation>
<BrowseInformation>1</BrowseInformation> <BrowseInformation>1</BrowseInformation>
<ListingPath /> <ListingPath></ListingPath>
<HexFormatSelection>1</HexFormatSelection> <HexFormatSelection>1</HexFormatSelection>
<Merge32K>0</Merge32K> <Merge32K>0</Merge32K>
<CreateBatchFile>0</CreateBatchFile> <CreateBatchFile>0</CreateBatchFile>
<BeforeCompile> <BeforeCompile>
<RunUserProg1>0</RunUserProg1> <RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2> <RunUserProg2>0</RunUserProg2>
<UserProg1Name /> <UserProg1Name></UserProg1Name>
<UserProg2Name /> <UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopU1X>0</nStopU1X> <nStopU1X>0</nStopU1X>
@ -69,8 +72,8 @@
<BeforeMake> <BeforeMake>
<RunUserProg1>0</RunUserProg1> <RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2> <RunUserProg2>0</RunUserProg2>
<UserProg1Name /> <UserProg1Name></UserProg1Name>
<UserProg2Name /> <UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopB1X>0</nStopB1X> <nStopB1X>0</nStopB1X>
@ -79,15 +82,15 @@
<AfterMake> <AfterMake>
<RunUserProg1>0</RunUserProg1> <RunUserProg1>0</RunUserProg1>
<RunUserProg2>1</RunUserProg2> <RunUserProg2>1</RunUserProg2>
<UserProg1Name /> <UserProg1Name></UserProg1Name>
<UserProg2Name /> <UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopA1X>0</nStopA1X> <nStopA1X>0</nStopA1X>
<nStopA2X>0</nStopA2X> <nStopA2X>0</nStopA2X>
</AfterMake> </AfterMake>
<SelectedForBatchBuild>1</SelectedForBatchBuild> <SelectedForBatchBuild>1</SelectedForBatchBuild>
<SVCSIdString /> <SVCSIdString></SVCSIdString>
</TargetCommonOption> </TargetCommonOption>
<CommonProperty> <CommonProperty>
<UseCPPCompiler>0</UseCPPCompiler> <UseCPPCompiler>0</UseCPPCompiler>
@ -101,8 +104,8 @@
<AssembleAssemblyFile>0</AssembleAssemblyFile> <AssembleAssemblyFile>0</AssembleAssemblyFile>
<PublicsOnly>0</PublicsOnly> <PublicsOnly>0</PublicsOnly>
<StopOnExitCode>3</StopOnExitCode> <StopOnExitCode>3</StopOnExitCode>
<CustomArgument /> <CustomArgument></CustomArgument>
<IncludeLibraryModules /> <IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>0</ComprImg> <ComprImg>0</ComprImg>
</CommonProperty> </CommonProperty>
<DllOption> <DllOption>
@ -111,7 +114,7 @@
<SimDlgDll>DCM.DLL</SimDlgDll> <SimDlgDll>DCM.DLL</SimDlgDll>
<SimDlgDllArguments>-pCM3</SimDlgDllArguments> <SimDlgDllArguments>-pCM3</SimDlgDllArguments>
<TargetDllName>SARMCM3.DLL</TargetDllName> <TargetDllName>SARMCM3.DLL</TargetDllName>
<TargetDllArguments /> <TargetDllArguments></TargetDllArguments>
<TargetDlgDll>TCM.DLL</TargetDlgDll> <TargetDlgDll>TCM.DLL</TargetDlgDll>
<TargetDlgDllArguments>-pCM3</TargetDlgDllArguments> <TargetDlgDllArguments>-pCM3</TargetDlgDllArguments>
</DllOption> </DllOption>
@ -136,10 +139,10 @@
<bUseTDR>1</bUseTDR> <bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2> <Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3>"" ()</Flash3> <Flash3>"" ()</Flash3>
<Flash4 /> <Flash4></Flash4>
<pFcarmOut /> <pFcarmOut></pFcarmOut>
<pFcarmGrp /> <pFcarmGrp></pFcarmGrp>
<pFcArmRoot /> <pFcArmRoot></pFcArmRoot>
<FcArmLst>0</FcArmLst> <FcArmLst>0</FcArmLst>
</Utilities> </Utilities>
<TargetArmAds> <TargetArmAds>
@ -172,7 +175,7 @@
<RvctClst>0</RvctClst> <RvctClst>0</RvctClst>
<GenPPlst>0</GenPPlst> <GenPPlst>0</GenPPlst>
<AdsCpuType>"Cortex-M3"</AdsCpuType> <AdsCpuType>"Cortex-M3"</AdsCpuType>
<RvctDeviceName /> <RvctDeviceName></RvctDeviceName>
<mOS>0</mOS> <mOS>0</mOS>
<uocRom>0</uocRom> <uocRom>0</uocRom>
<uocRam>0</uocRam> <uocRam>0</uocRam>
@ -306,11 +309,11 @@
<Size>0x0</Size> <Size>0x0</Size>
</OCR_RVCT10> </OCR_RVCT10>
</OnChipMemories> </OnChipMemories>
<RvctStartVector /> <RvctStartVector></RvctStartVector>
</ArmAdsMisc> </ArmAdsMisc>
<Cads> <Cads>
<interw>1</interw> <interw>1</interw>
<Optim>2</Optim> <Optim>1</Optim>
<oTime>0</oTime> <oTime>0</oTime>
<SplitLS>0</SplitLS> <SplitLS>0</SplitLS>
<OneElfS>1</OneElfS> <OneElfS>1</OneElfS>
@ -333,9 +336,9 @@
<v6WtE>0</v6WtE> <v6WtE>0</v6WtE>
<v6Rtti>0</v6Rtti> <v6Rtti>0</v6Rtti>
<VariousControls> <VariousControls>
<MiscControls /> <MiscControls></MiscControls>
<Define>USE_HAL_DRIVER,STM32F103xB</Define> <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> <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> </VariousControls>
</Cads> </Cads>
@ -351,10 +354,10 @@
<useXO>0</useXO> <useXO>0</useXO>
<ClangAsOpt>1</ClangAsOpt> <ClangAsOpt>1</ClangAsOpt>
<VariousControls> <VariousControls>
<MiscControls /> <MiscControls></MiscControls>
<Define /> <Define></Define>
<Undefine /> <Undefine></Undefine>
<IncludePath /> <IncludePath></IncludePath>
</VariousControls> </VariousControls>
</Aads> </Aads>
<LDads> <LDads>
@ -364,15 +367,15 @@
<noStLib>0</noStLib> <noStLib>0</noStLib>
<RepFail>1</RepFail> <RepFail>1</RepFail>
<useFile>0</useFile> <useFile>0</useFile>
<TextAddressRange /> <TextAddressRange></TextAddressRange>
<DataAddressRange /> <DataAddressRange></DataAddressRange>
<pXoBase /> <pXoBase></pXoBase>
<ScatterFile /> <ScatterFile></ScatterFile>
<IncludeLibs /> <IncludeLibs></IncludeLibs>
<IncludeLibsPath /> <IncludeLibsPath></IncludeLibsPath>
<Misc /> <Misc></Misc>
<LinkerInputFile /> <LinkerInputFile></LinkerInputFile>
<DisabledWarnings /> <DisabledWarnings></DisabledWarnings>
</LDads> </LDads>
</TargetArmAds> </TargetArmAds>
</TargetOption> </TargetOption>
@ -445,6 +448,11 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>../Core/Src/stm32f1xx_hal_msp.c</FilePath> <FilePath>../Core/Src/stm32f1xx_hal_msp.c</FilePath>
</File> </File>
<File>
<FileName>delay.c</FileName>
<FileType>1</FileType>
<FilePath>..\Core\Src\delay.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@ -460,6 +468,11 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\Service\Src\timer.c</FilePath> <FilePath>..\Service\Src\timer.c</FilePath>
</File> </File>
<File>
<FileName>block_detect.c</FileName>
<FileType>1</FileType>
<FilePath>..\Service\Src\block_detect.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@ -608,6 +621,7 @@
</Groups> </Groups>
</Target> </Target>
</Targets> </Targets>
<RTE> <RTE>
<apis/> <apis/>
<components> <components>
@ -620,6 +634,7 @@
</components> </components>
<files/> <files/>
</RTE> </RTE>
<LayerInfo> <LayerInfo>
<Layers> <Layers>
<Layer> <Layer>
@ -628,5 +643,5 @@
</Layer> </Layer>
</Layers> </Layers>
</LayerInfo> </LayerInfo>
</Project>
</Project>

View File

@ -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 = \ C_SOURCES = \
Core/Src/main.c \ Core/Src/main.c \
Core/Src/gpio.c \ Core/Src/gpio.c \
Core/Src/i2c.c \
Core/Src/syscalls.c \ Core/Src/syscalls.c \
Core/Src/tim.c \ Core/Src/tim.c \
Core/Src/dma.c \ Core/Src/dma.c \
Core/Src/usart.c \ Core/Src/usart.c \
Core/Src/stm32f1xx_it.c \ Core/Src/stm32f1xx_it.c \
Core/Src/stm32f1xx_hal_msp.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_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.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.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_rcc_ex.c \
@ -68,11 +67,16 @@ Peripheral/Src/led.c \
Peripheral/Src/bluetooth.c \ Peripheral/Src/bluetooth.c \
Peripheral/Src/control.c \ Peripheral/Src/control.c \
Peripheral/Src/line_seek.c \ Peripheral/Src/line_seek.c \
Peripheral/Src/path_plan.c \
Peripheral/Src/servo.c \ Peripheral/Src/servo.c \
Peripheral/Src/infrared.c \ Peripheral/Src/infrared.c \
Peripheral/Src/syn6288.c \
Peripheral/Src/buzzer.c \
App/Src/app_line_seek.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 # ASM sources
@ -134,6 +138,7 @@ AS_INCLUDES =
# C includes # C includes
C_INCLUDES = \ C_INCLUDES = \
-ICore/Inc \ -ICore/Inc \
-IService/Inc \
-IPeripheral/Inc \ -IPeripheral/Inc \
-IApp/Inc \ -IApp/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc \

View File

@ -3,11 +3,13 @@
#include "main.h" #include "main.h"
extern int timed_beep_event_id;
extern int times_beep_event_id;
void BUZZER_Start(); void BUZZER_Start();
void BUZZER_Stop(); void BUZZER_Stop();
/// @brief 蜂鸣器定时鸣叫 void BUZZER_StartTimed(uint16_t time);
/// @param time 鸣叫时间单位100毫秒 void BUZZER_StartNTimes(uint8_t n, uint16_t on_time, uint16_t off_time);
void BUZZER_StartTimed(uint8_t time);
#endif #endif

View File

@ -11,6 +11,10 @@
void LED_Start(uint8_t led); void LED_Start(uint8_t led);
void LED_Stop(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] // duty in [0, 255]
void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b); void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b);

View File

@ -1,14 +1,16 @@
#include "bluetooth.h" #include "bluetooth.h"
#include "usart.h"
#include "control.h" #include <math.h>
#include "line_seek.h" #include <stdarg.h>
#include "infrared.h"
#include "hcsr04.h"
#include "timer.h"
#include <stdio.h> #include <stdio.h>
#include <string.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 BUFFER_SIZE 255
#define MESSAGE_SIZE 19 #define MESSAGE_SIZE 19
@ -17,24 +19,24 @@
static int8_t rxBuffer[BUFFER_SIZE], txBuffer[BUFFER_SIZE]; static int8_t rxBuffer[BUFFER_SIZE], txBuffer[BUFFER_SIZE];
static uint16_t txLen; static uint16_t txLen;
static uint8_t cmdIndex; static uint8_t cmdIndex;
static uint8_t timer_event_id = -1;
void sendSensor(void) void sendSensor(void)
{ {
static uint8_t line_seek[5]; // static uint8_t line_seek[5];
strcpy(line_seek, LineSeek_GetStatusStr()); // strcpy(line_seek, LineSeek_GetStatusStr());
for (uint8_t i = 0; i < 5; ++i) // for (uint8_t i = 0; i < 5; ++i)
line_seek[i] ^= 1; // line_seek[i] ^= 1;
BLUETOOTH_Send("$4WD,CSB%u,PV-,GS-,LF%s,HW%hhu%hhu,GM-#", // BLUETOOTH_Send("$4WD,CSB%u,PV-,GS-,LF%s,HW%hhu%hhu,GM-#",
(uint32_t)round((double)sonor_distance / 10), // (uint32_t)round((double)sonor_distance / 10),
line_seek, // line_seek,
!INFRARED_GetL(), // !INFRARED_GetL(),
!INFRARED_GetR()); // !INFRARED_GetR());
} }
void BLUETOOTH_Init(void) void BLUETOOTH_Init(void)
{ {
HAL_UARTEx_ReceiveToIdle_IT(&huart2, rxBuffer, 100); 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, ...) void BLUETOOTH_Send(const char *str, ...)

View File

@ -1,7 +1,9 @@
#include "buzzer.h" #include "buzzer.h"
#include "timer.h" #include "timer.h"
static uint8_t state; int timed_beep_event_id = -1;
int times_beep_event_id = -1;
inline void BUZZER_Start() inline void BUZZER_Start()
{ {
@ -11,16 +13,20 @@ inline void BUZZER_Start()
inline void BUZZER_Stop() inline void BUZZER_Stop()
{ {
HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_SET);
if (state == 1)
{
state = 0;
TIMER_DelLoopEvent(EVENT_BUZZER);
}
} }
void BUZZER_StartTimed(uint8_t time) /// @brief 启动蜂鸣器鸣叫
/// @param time 鸣叫时间单位1毫秒
void BUZZER_StartTimed(uint16_t time)
{ {
state = 1;
BUZZER_Start(); BUZZER_Start();
TIMER_AddLoopEvent(EVENT_BUZZER, BUZZER_Stop, time * 100); timed_beep_event_id = TIMER_AddDelayEvent(timed_beep_event_id, BUZZER_Stop, time);
}
/// @brief 启动蜂鸣器鸣叫n次每次叫on_time毫秒停off_time毫秒
/// @param on_time 鸣叫时间单位1毫秒
/// @param off_time 停止鸣叫时间单位1毫秒
void BUZZER_StartNTimes(uint8_t n, uint16_t on_time, uint16_t off_time)
{
times_beep_event_id = TIMER_AddFiniteLoopEventWithParam(times_beep_event_id, BUZZER_StartTimed, on_time + off_time, n, on_time);
} }

View File

@ -1,11 +1,13 @@
#include "hcsr04.h" #include "hcsr04.h"
#include "tim.h"
#include "syscalls.h" #include "syscalls.h"
#include "delay.h"
#include "tim.h"
static uint64_t time_start; // 声明变量,用来计时 static uint64_t time_start; // 声明变量,用来计时
static uint64_t time_end; // 声明变量,存储回波信号时间 static uint64_t time_end; // 声明变量,存储回波信号时间
uint8_t sonor_state; // 测距状态变量0未测量1正在测量2已测量 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); 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); HAL_TIM_RegisterCallback(&htim2, HAL_TIM_PERIOD_ELAPSED_CB_ID, HCSR04_HAL_TIM_PeriodElapsedCallback);
sonor_distance = INT32_MAX;
} }
// 启动测距单位mm // 启动测距单位mm
@ -27,11 +31,7 @@ uint32_t sonar_mm(void)
HAL_GPIO_WritePin(TRIG_GPIO_Port, TRIG_Pin, GPIO_PIN_SET); // 输出高电平 HAL_GPIO_WritePin(TRIG_GPIO_Port, TRIG_Pin, GPIO_PIN_SET); // 输出高电平
delay_us(15); // 延时15微秒 delay_us(15); // 延时15微秒
HAL_GPIO_WritePin(TRIG_GPIO_Port, TRIG_Pin, GPIO_PIN_RESET); // 输出低电平 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; return sonor_distance;
} }
@ -58,14 +58,15 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
time_end = time_start; time_end = time_start;
HAL_TIM_Base_Stop_IT(&htim2); HAL_TIM_Base_Stop_IT(&htim2);
sonor_state = 2; sonor_state = 2;
sonor_distance = (time_end / 100 < 38) ? (time_end * 346) / 200 : INT32_MAX;
Sonar_CP_Callback(); Sonar_CP_Callback();
sonor_state = 0;
} }
} }
} }
// 测距完毕回调,执行完自定义任务后将sonor_state置0 // 测距完毕回调,执行完自定义任务后将sonor_state置0
__attribute__((weak)) void Sonar_CP_Callback() __attribute__((weak)) void Sonar_CP_Callback()
{ {
my_printf(HUART1, "distance = %d (mm)\n", sonor_distance); my_printf(HUART2, "distance = %d (mm)\n", sonor_distance);
sonor_state = 0;
} }

View File

@ -1,11 +1,16 @@
#include "led.h" #include "led.h"
#include "tim.h" #include "tim.h"
#include "timer.h"
#define LED_TIM (&htim3) #define LED_TIM (&htim3)
#define LED_R_CHAN TIM_CHANNEL_4 #define LED_R_CHAN TIM_CHANNEL_4
#define LED_G_CHAN TIM_CHANNEL_3 #define LED_G_CHAN TIM_CHANNEL_3
#define LED_B_CHAN TIM_CHANNEL_2 #define LED_B_CHAN TIM_CHANNEL_2
static led_timed_id = -1;
static led_times_id = -1;
void LED_Start(uint8_t led) void LED_Start(uint8_t led)
{ {
if (led & LED_R) if (led & LED_R)
@ -26,6 +31,16 @@ void LED_Stop(uint8_t led)
HAL_TIM_PWM_Stop(LED_TIM, LED_B_CHAN); 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) void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b)
{ {
__HAL_TIM_SetCompare(LED_TIM, LED_R_CHAN, r); __HAL_TIM_SetCompare(LED_TIM, LED_R_CHAN, r);

View File

@ -36,10 +36,12 @@ BUILD_DIR = build
###################################### ######################################
# C sources # C sources
C_SOURCES = \ C_SOURCES = \
App/Src/app_bus.c \
App/Src/app_line_seek.c \ App/Src/app_line_seek.c \
App/Src/app_ultrasonic.c \
Core/Src/delay.c \
Core/Src/dma.c \ Core/Src/dma.c \
Core/Src/gpio.c \ Core/Src/gpio.c \
Core/Src/i2c.c \
Core/Src/main.c \ Core/Src/main.c \
Core/Src/stm32f1xx_hal_msp.c \ Core/Src/stm32f1xx_hal_msp.c \
Core/Src/stm32f1xx_it.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_flash_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.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_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_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.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_rcc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.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_tim_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
User/Src/bluetooth.c \ Peripheral/Src/bluetooth.c \
User/Src/control.c \ Peripheral/Src/buzzer.c \
User/Src/hcsr04.c \ Peripheral/Src/control.c \
User/Src/led.c \ Peripheral/Src/hcsr04.c \
User/Src/line_seek.c \ Peripheral/Src/infrared.c \
User/Src/motor.c \ Peripheral/Src/led.c \
User/Src/path_plan.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 = \ CPP_SOURCES = \
@ -147,7 +154,8 @@ C_INCLUDES = \
-IDrivers/CMSIS/Include \ -IDrivers/CMSIS/Include \
-IDrivers/STM32F1xx_HAL_Driver/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \ -IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IUser/Inc -IPeripheral/Inc \
-IService/Inc

View 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

View File

@ -6,24 +6,13 @@ typedef enum
{ {
STRAIGHT, STRAIGHT,
LEFT, LEFT,
RIGHT, RIGHT
STOP
} Direction; } Direction;
// 定义路径规划器结构
typedef struct
{
int currentStep;
Direction* path;
int pathLength;
} PathPlanner;
// 全局路径规划器
extern PathPlanner pathPlanner;
void PathPlanner_Init(); void PathPlanner_Init();
Direction GetCurrentDirection(); Direction GetCurrentDirection();
Direction GetNextDirection(); Direction GetNextDirection();
void AddPathStep(Direction step); void AddPathStep(Direction step);
void ReplacePathStep(Direction* step, int n);
#endif #endif

View File

@ -3,14 +3,13 @@
#include "main.h" #include "main.h"
#define EVENT_LED 0 #define EVENT_MAX 20
#define EVENT_BUZZER 1
#define EVENT_BLUETOOTH 2
#define EVENT_SERVO 3
#define EVENT_MAX 4
void TIMER_Init(void); void TIMER_Init(void);
void TIMER_AddLoopEvent(uint8_t type, void (*func)(void), uint16_t loop_time); int8_t TIMER_AddInfiniteLoopEvent(int8_t id, void (*func)(void), uint16_t loop_time);
void TIMER_DelLoopEvent(uint8_t type); 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 #endif

View 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;
}

View File

@ -4,8 +4,16 @@
#include "stdio.h" #include "stdio.h"
#include "stdlib.h" #include "stdlib.h"
// 全局路径规划器 // 定义路径规划器结构
PathPlanner pathPlanner; typedef struct
{
int currentStep;
Direction* path;
int pathLength;
} PathPlanner;
// 路径规划器
static PathPlanner pathPlanner;
void SetPath(); void SetPath();
@ -24,9 +32,38 @@ void SetPath()
int i; int i;
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
AddPathStep(LEFT);
AddPathStep(RIGHT);
AddPathStep(STRAIGHT); 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 = realloc(pathPlanner.path, ++pathPlanner.pathLength * sizeof(Direction));
pathPlanner.path[pathPlanner.pathLength - 1] = step; 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];
}
}

View File

@ -1,22 +1,35 @@
#include "timer.h" #include "timer.h"
#include "tim.h"
#include <math.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 typedef struct Event
{ {
uint8_t id;
void (*func)(void); void (*func)(void);
void (*param_func)(uint16_t);
uint16_t time; uint16_t time;
EventType type;
uint8_t enabled; uint8_t enabled;
uint16_t loop_cnt;
uint32_t begin_time;
uint16_t param;
} Event; } Event;
static Event event[EVENT_MAX]; static Event event[EVENT_MAX];
static uint32_t time_cnt; static int event_cnt;
static uint32_t time_lcm = 1; static uint32_t current_time;
uint32_t gcd(uint32_t a, uint32_t b); void TIMER_Count(TIM_HandleTypeDef *htim);
uint32_t lcm(uint32_t a, uint32_t b);
void TIMER_Count(void);
void TIMER_Init(void) void TIMER_Init(void)
{ {
@ -24,41 +37,124 @@ void TIMER_Init(void)
HAL_TIM_Base_Start_IT(&htim4); HAL_TIM_Base_Start_IT(&htim4);
} }
/// @brief 注册定时回调事件 /// @brief 注册无限循环定时回调事件
/// @param func 回调函数 void func(void) /// @param func 回调函数 void func(void)
/// @param loop_time 定时时间,单位毫秒 /// @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; if (event_id == -1) event_id = event_cnt++;
event[type].time = loop_time; event[event_id].type = INFINITE_LOOP_EVENT;
event[type].enabled = 1; event[event_id].id = event_id;
time_lcm = lcm(time_lcm, loop_time); 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; if (event_id == -1) event_id = event_cnt++;
time_lcm /= event[type].time; 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)
{
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)
{ {
++time_cnt;
for (uint8_t i = 0; i < EVENT_MAX; ++i)
if (event[i].enabled && time_cnt % event[i].time == 0)
event[i].func(); event[i].func();
if (time_cnt == time_lcm)
time_cnt = 0;
} }
break;
uint32_t gcd(uint32_t a, uint32_t b) case FINITE_LOOP_EVENT: // 有限循环事件
if ((current_time - event[i].begin_time) % event[i].time == 0)
{ {
if (b == 0) event[i].func();
return a; if (event[i].loop_cnt-- <= 0)
return gcd(b, a % b);
}
uint32_t lcm(uint32_t a, uint32_t b)
{ {
return a / gcd(a, b) * b; 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;
}
}
} }