19参加江苏省机器人大赛获得一等奖该程序部分包括内容有:
1.车道两边有挡板,利用超声波模块测量距离两边的距离,以此达到车道保持的效果。
2.利用激光测距模块测量与前车的距离,当距离小于200mm时转向超车。
3.利用灰度模块检查地面的菱形标志
4.利用红外管检查是否到达人行横道线并停车,
主控板是STM32C8T6
底盘部分包括2个驱动电机+1个转向电机,由平衡小车之家购买。
激光测距模块/红外/超声波/灰度模块可在正点原子官网买到。
单片机源程序如下:
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "24cxx.h"
- #include "vl53l0x.h"
- #include "dianji.h"
- #include "timer.h"
- #include "huidu.h"
- #include "led.h"
- #include "vl53l0x_gen.h"
- #include "Ultrasonic.h"
- int main(void)
- { delay_init(); //延时函数初始化
- delay_init();
- //uart_init2(115200);
- uart_init2(115200);
- TIM2_time_init(6999,719); //70ms
- Ultrasonic_IO_Init();
- Start_hc_sr04();
- NVIC_Configuration();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- Led_Init();
- TIM4_PWM_Init(19999,71);
- TIM_SetCompare4(TIM4, 18500);
- TIM3_PWM_Init(7199,0);
- Dianji_Init();
- TIM_SetCompare3(TIM3, 2800);//电机A占空比
- TIM_SetCompare4(TIM3, 2800);//电机B占空
- Huidu_Init();
- HongWai_Init();
- AT24CXX_Init();
- while(AT24CXX_Check())//检测不到24c02
- {
-
- Led_Red=!Led_Red;//
- delay_ms(200);
- }
- //while(1)
- //{
- // GPIO_SetBits(GPIOC,GPIO_Pin_13);
- // delay_ms(200);
- // GPIO_ResetBits(GPIOC,GPIO_Pin_13);
- // delay_ms(200);
- //}
- Read_data();
- tingzhi();
- // while(1)
- // {
- // u8 flag = 0;
- // flag = Read_data();
- // if(flag)
- // {
- //
- //
- // GPIO_SetBits(GPIOC,GPIO_Pin_13);
- // delay_ms(200);
- // GPIO_ResetBits(GPIOC,GPIO_Pin_13);
- // delay_ms(200);
- //
- // }
- // }
- while(1)
- {
- // zhixing();
- vl53l0x_test();//vl53l0x测试
- }
- }
复制代码
所有资料51hei提供下载:
锥形标.7z
(314.28 KB, 下载次数: 37)
在这里将源码公布
|