444 lines
14 KiB
C
444 lines
14 KiB
C
#include <stdio.h>
|
|
#include "stm32f4xx.h"
|
|
#include "delay.h"
|
|
#include "infrared.h"
|
|
#include "cba.h"
|
|
#include "ultrasonic.h"
|
|
#include "CanP_HostCom.h"
|
|
#include "hard_can.h"
|
|
#include "bh1750.h"
|
|
#include "syn7318.h"
|
|
#include "power_check.h"
|
|
#include "can_user.h"
|
|
#include "data_base.h"
|
|
#include "roadway_check.h"
|
|
#include "tba.h"
|
|
#include "data_base.h"
|
|
#include "swopt_drv.h"
|
|
#include "uart_a72.h"
|
|
#include "Can_check.h"
|
|
#include "Timer.h"
|
|
#include "Rc522.h"
|
|
#include "drive.h"
|
|
#include "bkrc_voice.h"
|
|
|
|
/***************************** 自定义变量 *****************************/
|
|
|
|
static uint32_t Power_check_times; // 电量检测周期
|
|
static uint32_t LED_twinkle_times; // LED闪烁周期
|
|
static uint32_t WIFI_Upload_data_times; // 通过Wifi上传数据周期
|
|
static uint32_t RFID_Init_Check_times; // RFID初始化检测时间周期
|
|
|
|
uint8_t Go_Speed = 40; // 前进速度
|
|
uint8_t wheel_Speed = 50; // 转弯速度
|
|
uint16_t Go_Temp = 280; // 前进码盘值
|
|
|
|
uint16_t dis_size = 0; // 超声波测距值缓存
|
|
|
|
uint8_t make = 0; // 全自动驾驶标志位
|
|
uint8_t SYN7318_Flag = 0; // SYN7318语音识别命令ID编号
|
|
uint8_t number = 0; // 计数值
|
|
uint8_t coordinate; //随机坐标点返回值
|
|
|
|
int suduzhi1;//=0;//判断码盘值1
|
|
int suduzhi2;//=0;//判断码盘值2
|
|
int suduzhi3;//=0;//判断码盘值3
|
|
|
|
|
|
static void KEY_Check(void); // 按键检测函数
|
|
static void Hardware_Init(void); // 硬件初始化函数
|
|
char Data[5];
|
|
|
|
/* 全自动运行函数 */
|
|
void Car_Thread(void)
|
|
{
|
|
switch(make)
|
|
{
|
|
case CITY_PATROL_INSPECTION:
|
|
{
|
|
Send_ZigbeeData_To_Fifo(SEG_TimOpen, 8); // LED显示 -> 计时模式开启
|
|
delay_ms(200);
|
|
Send_ZigbeeData_To_Fifo(SEG_TimOpen, 8); // LED显示 -> 计时模式开启
|
|
delay_ms(200);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Tba_L_LED = 0; //左转灯开
|
|
Car_L(wheel_Speed); //左转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_L_LED = 1; //左转灯关
|
|
delay_ms(500);
|
|
Car_Time_Track(30,800); //前进一半(路中间等待红绿灯)
|
|
delay_ms(500);
|
|
Send_ZigbeeData_To_Fifo(TrafficA_Open,8); //交通灯进入识别
|
|
delay_ms(500);
|
|
Send_ZigbeeData_To_Fifo(TrafficA_Red,8); //红灯状态
|
|
delay_ms(500);
|
|
Control(0,0); //停车
|
|
delay_ms(15000);
|
|
Send_ZigbeeData_To_Fifo(TrafficA_Open,8); //交通灯进入识别
|
|
delay_ms(500);
|
|
Send_ZigbeeData_To_Fifo(TrafficA_Green,8); //绿灯
|
|
delay_ms(1500);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Qv_Car_HW("前方无法通行");//立体显示路况
|
|
delay_ms(500);
|
|
Tba_L_LED = 0; //左转灯开
|
|
Car_L(wheel_Speed); //左转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_L_LED = 1; //左转灯关
|
|
delay_ms(500);
|
|
Infrared_Send(Alarm_Open,6);//烽火台开启
|
|
delay_ms(1000);
|
|
Car_L(90); // 右旋转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
delay_ms(500);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Gate_Open_Zigbee(); //开启道闸
|
|
Gate_Show_Zigbee("A11451"); // 道闸显示车牌
|
|
delay_ms(200);
|
|
Gate_Show_Zigbee("A11451"); // 道闸显 示车牌
|
|
delay_ms(600);
|
|
YY_Comm_Zigbee(0x20, 0x01);
|
|
Car_Track(Go_Speed); // 循迹
|
|
Car_Go(Go_Speed,Go_Temp); // 前进
|
|
delay_ms(500);
|
|
delay_ms(200);
|
|
Tba_R_LED = 0; //右转灯开
|
|
Car_R(wheel_Speed); //右转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_R_LED = 1; //右转灯关
|
|
delay_ms(500);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Tba_L_LED = 0; //左转灯开
|
|
Car_L(wheel_Speed); //左转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
delay_ms(500);
|
|
Tba_L_LED = 1; //左转灯关
|
|
delay_ms(200);
|
|
Light_Inf(3); // 自动调节光照强度函数
|
|
delay_ms(200);
|
|
Car_R(80); // 右旋转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
delay_ms(500);
|
|
Car_Time_Track(20,1500); //人行道减速前进
|
|
delay_ms(500);
|
|
Control(0,0); //斑马线前停车观望
|
|
delay_ms(5000);
|
|
YY_Play_Zigbee("即将通行过斑马线,请注意");
|
|
Car_Track(Go_Speed); // 循迹
|
|
Car_Go(80,2000); //过人行道前进
|
|
delay_ms(500);
|
|
Tba_L_LED = 0; //左转灯开
|
|
Car_L(wheel_Speed); //左转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_L_LED = 1; //左转灯关
|
|
delay_ms(500);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Tba_L_LED = 0; //左转灯开
|
|
Car_L(wheel_Speed); //左转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_L_LED = 1; //左转灯关
|
|
delay_ms(500);
|
|
Car_Time_Track(20,1000);
|
|
ETC_Get_Zigbee(); //ETC系统检测
|
|
delay_ms(500);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(200);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Tba_L_LED = 0; //左转灯开
|
|
Car_L(wheel_Speed); //左转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_L_LED = 1; //左转灯关
|
|
delay_ms(500);
|
|
Car_Back(Go_Speed,1000);//后退
|
|
delay_ms(500);
|
|
Garage_Cont_Zigbee('A', 1); // 立体车库A 到达第1层
|
|
delay_ms(100);
|
|
Send_ZigbeeData_To_Fifo(SMG_TimClose, 8); // 数码管计时 -> 关闭
|
|
delay_ms(300);
|
|
Send_ZigbeeData_To_Fifo(SMG_TimClose, 8); // 数码管计时 -> 关闭
|
|
delay_ms(500);
|
|
Send_ZigbeeData_To_Fifo(Charge_Open, 8); // 无线充电 -> 开启
|
|
delay_ms(200);
|
|
Send_ZigbeeData_To_Fifo(Charge_Open, 8); // 无线充电 -> 开启
|
|
delay_ms(200);
|
|
YY_Play_Zigbee("结束任务");
|
|
delay_ms(500);
|
|
Car_Go(0,0);
|
|
make = 0x00;
|
|
break;
|
|
}
|
|
case EXEC_DETECT_TASK:
|
|
{
|
|
Garage_Cont_Zigbee('A', 0); //立体车库到达0层
|
|
//初始化计时器 _set_timer(SEG_TimOpen, 8);
|
|
Send_ZigbeeData_To_Fifo(SEG_TimOpen, 8); // LED显示 -> 计时模式开启
|
|
delay_ms(200);
|
|
Send_ZigbeeData_To_Fifo(SEG_TimOpen, 8); // LED显示 -> 计时模式开启
|
|
delay_ms(200);
|
|
//debug zigbee stop the car
|
|
delay_ms(10000);
|
|
//
|
|
{
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Tba_R_LED = 0; //右转灯开
|
|
Car_R(wheel_Speed); //右转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_R_LED = 1; //右转灯关
|
|
delay_ms(500);
|
|
}
|
|
Ultrasonic_Ranging(); // 采集超声波测距距离
|
|
dis_size = dis;
|
|
TFT_Dis_Zigbee('A',dis_size); // LED显示标志物发送测距信息
|
|
delay_ms(200);
|
|
LED_Dis_Zigbee(dis_size); // LED显示标志物发送测距信息
|
|
TFT_Dis_Zigbee('A',dis_size);
|
|
delay_ms(500);
|
|
Tba_L_LED = 0; //左转灯开
|
|
Car_L(wheel_Speed); //左转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_L_LED = 1; //左转灯关
|
|
delay_ms(500);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Tba_R_LED = 0; //右转灯开
|
|
Car_R(wheel_Speed); //右转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Tba_R_LED = 1; //右转灯关
|
|
delay_ms(500);
|
|
Ultrasonic_Ranging(); // 采集超声波测距距离
|
|
dis_size = dis;
|
|
TFT_Dis_Zigbee('B',dis_size); // LED显示标志物发送测距信息
|
|
delay_ms(200);
|
|
LED_Dis_Zigbee(dis_size); // LED显示标志物发送测距信息
|
|
TFT_Dis_Zigbee('B',dis_size);
|
|
delay_ms(500);
|
|
Car_R(40); // 右旋转
|
|
delay_ms(500);
|
|
Control(0,0);
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
Car_Track(Go_Speed); //循迹
|
|
Car_Go(Go_Speed,Go_Temp); //前进
|
|
delay_ms(500);
|
|
Car_R(80); // 右旋转
|
|
delay_ms(500);
|
|
Car_R(40); // 右旋转
|
|
Car_Back(Go_Speed,1000);//后退
|
|
Garage_Cont_Zigbee('A', 1); // 立体车库A 到达第1层
|
|
delay_ms(100);
|
|
Send_ZigbeeData_To_Fifo(SMG_TimClose, 8); // 数码管计时 -> 关闭
|
|
delay_ms(300);
|
|
Send_ZigbeeData_To_Fifo(SMG_TimClose, 8); // 数码管计时 -> 关闭
|
|
delay_ms(500);
|
|
Send_ZigbeeData_To_Fifo(Charge_Open, 8); // 无线充电 -> 开启
|
|
delay_ms(200);
|
|
Send_ZigbeeData_To_Fifo(Charge_Open, 8); // 无线充电 -> 开启
|
|
delay_ms(200);
|
|
YY_Play_Zigbee("结束任务");
|
|
delay_ms(500);
|
|
Car_Go(0,0);
|
|
make = 0x00;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/* 按键检测函数 */
|
|
void KEY_Check(void)
|
|
{
|
|
if(S1 == 0)
|
|
{
|
|
delay_ms(10);
|
|
if(S1 == 0)
|
|
{
|
|
LED1 = !LED1;
|
|
while(!S1);
|
|
make=CITY_PATROL_INSPECTION;
|
|
YY_Play_Zigbee("开始城市巡检");
|
|
|
|
|
|
}
|
|
}
|
|
if(S2 == 0)
|
|
{
|
|
delay_ms(10);
|
|
if(S2 == 0)
|
|
{
|
|
LED2 = !LED2;
|
|
while(!S2);
|
|
make = EXEC_DETECT_TASK;
|
|
YY_Play_Zigbee("执行检测任务");
|
|
}
|
|
}
|
|
if(S3 == 0)
|
|
{
|
|
delay_ms(10);
|
|
if(S3 == 0)
|
|
{
|
|
LED3 = !LED3;
|
|
while(!S3);
|
|
// Infrared_Send(Alarm_Open,6);//烽火台开启
|
|
// delay_ms(500);
|
|
}
|
|
}
|
|
if(S4 == 0)
|
|
{
|
|
delay_ms(10);
|
|
if(S4 == 0)
|
|
{
|
|
LED4 = !LED4;
|
|
while(!S4);
|
|
Car_Time_Track(20,3000);
|
|
delay_ms(300);
|
|
Car_R(80); // 右旋转
|
|
delay_ms(300);
|
|
Car_Time_Track(20,3000);
|
|
delay_ms(300);
|
|
Car_R(80); // 右旋转
|
|
Car_Go(0,0);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
uint16_t Light_Value = 0; // 光强度值
|
|
uint16_t CodedDisk_Value = 0; // 码盘值
|
|
Hardware_Init(); // 硬件初始化
|
|
LED_twinkle_times = gt_get() + 50;
|
|
Power_check_times = gt_get() + 200;
|
|
WIFI_Upload_data_times = gt_get() + 200;
|
|
RFID_Init_Check_times = gt_get() + 200;
|
|
Principal_Tab[0] = 0x55; // 主车数据上传指令包头
|
|
Principal_Tab[1] = 0xAA;
|
|
Follower_Tab[0] = 0x55; // 智能运输车数据上传指令包头
|
|
Follower_Tab[1] = 0x02;
|
|
Send_UpMotor(0, 0);
|
|
while(1)
|
|
{
|
|
KEY_Check(); // 按键检测
|
|
Can_WifiRx_Check(); // Wifi交互数据处理
|
|
Can_ZigBeeRx_Check(); // Zigbee交互数据处理
|
|
Car_Thread(); // 全自动运行函数
|
|
if(gt_get_sub(LED_twinkle_times) == 0) // 运行指示灯
|
|
{
|
|
LED_twinkle_times = gt_get() + 50; // LED4状态取反
|
|
LED4 = !LED4;
|
|
}
|
|
|
|
if(gt_get_sub(Power_check_times) == 0) // 电池电量检测
|
|
{
|
|
Power_check_times = gt_get() + 200;
|
|
Power_Check();
|
|
}
|
|
|
|
#if 1
|
|
if(gt_get_sub(RFID_Init_Check_times) == 0) // RFID初始化检测
|
|
{
|
|
RFID_Init_Check_times = gt_get() + 200;
|
|
if(Rc522_GetLinkFlag() == 0)
|
|
{
|
|
Readcard_daivce_Init();
|
|
MP_SPK = !MP_SPK;
|
|
}
|
|
else
|
|
{
|
|
MP_SPK = 0;
|
|
LED1 = !LED1;
|
|
Rc522_LinkTest();
|
|
}
|
|
}
|
|
#endif
|
|
if(gt_get_sub(WIFI_Upload_data_times) == 0) // 数据上传
|
|
{
|
|
WIFI_Upload_data_times = gt_get() + 500;
|
|
if(Host_AGV_Return_Flag == RESET) // 主车数据上传
|
|
{
|
|
Principal_Tab[2] = Stop_Flag; // 运行状态
|
|
Principal_Tab[3] = Get_tba_phsis_value(); // 光敏状态
|
|
|
|
Ultrasonic_Ranging(); // 超声波数据采集
|
|
Principal_Tab[4] = dis % 256; // 超声波数据低八位
|
|
Principal_Tab[5] = dis / 256; // 超声波数据高八位
|
|
|
|
Light_Value = Get_Bh_Value(); // 光强度传感器数据采集
|
|
Principal_Tab[6] = Light_Value % 256; // 光强度数据低八位
|
|
Principal_Tab[7] = Light_Value / 256; // 光强度数据高八位
|
|
|
|
CodedDisk_Value = CanHost_Mp; // 码盘值
|
|
Principal_Tab[8] = CodedDisk_Value % 256;
|
|
Principal_Tab[9] = CodedDisk_Value / 256;
|
|
|
|
Principal_Tab[10] = coordinate; //随机救援坐标点返回值
|
|
|
|
Send_WifiData_To_Fifo(Principal_Tab, 13); // 通过Wifi上传主车数据
|
|
UartA72_TxClear();
|
|
UartA72_TxAddStr(Principal_Tab, 13); // 通过串口上传主车数据
|
|
UartA72_TxStart();
|
|
coordinate = 0 ;
|
|
}
|
|
else if((Host_AGV_Return_Flag == SET) && (AGV_data_Falg == SET))
|
|
{
|
|
|
|
UartA72_TxClear();
|
|
UartA72_TxAddStr(Follower_Tab, 50); // 通过串口上传主车数据
|
|
UartA72_TxStart();
|
|
Send_WifiData_To_Fifo(Follower_Tab, 50); // 通过Wifi上传主车数据
|
|
AGV_data_Falg = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* 硬件初始化函数 */
|
|
void Hardware_Init(void)
|
|
{
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); // 中断分组
|
|
delay_init(168); // 延时初始化
|
|
Tba_Init(); // 任务板初始化
|
|
Infrared_Init(); // 红外初始化
|
|
Cba_Init(); // 核心板初始化
|
|
Ultrasonic_Init(); // 超声波初始化
|
|
Hard_Can_Init(); // CAN总线初始化
|
|
BH1750_Configure(); // BH1750初始化配置
|
|
SYN7318_Init(); // 语音识别初始化
|
|
Electricity_Init(); // 电量检测初始化
|
|
UartA72_Init(); // A72硬件串口通讯初始化
|
|
Can_check_Init(7, 83); // CAN总线定时器初始化
|
|
roadway_check_TimInit(999, 167); // 路况检测
|
|
Timer_Init(999, 167); // 串行数据通讯时间帧
|
|
Readcard_daivce_Init(); // RFID初始化
|
|
BKRC_Voice_Init(); // 小创语音初始化
|
|
}
|