|
這是一個使用STM32驅(qū)動小車實現(xiàn)超聲波避障功能的程序,親測可用
實驗器材:
ZYSTM32-A0智能機器人產(chǎn)品
實驗?zāi)康?
本實驗為新建工程實驗,僅供大家新建工程時參考。
新建工程詳細步驟,請看《STM32不完全手冊-庫函數(shù)版本》第3.3節(jié)。
實驗現(xiàn)象:
本實驗下載后,控制板上接到13端口的LED會閃爍!
注意事項:
無.
單片機源程序如下:
- #include "stm32f10x.h"
- #include "delay.h"
- #include "motor.h"
- #include "keysacn.h"
- #include "IRSEARCH.h"
- #include "IRAvoid.h"
- #include "usart.h"
- #include "UltrasonicWave.h"
- #include "timer.h"
- //extern int U_temp;
- /*
- void ZYSTM32_run(int speed,int time); //前進函數(shù)
- void ZYSTM32_brake(int time); //剎車函數(shù)
- void ZYSTM32_Left(int speed,int time); //左轉(zhuǎn)函數(shù)
- void ZYSTM32_Spin_Left(int speed,int time); //左旋轉(zhuǎn)函數(shù)
- void ZYSTM32_Right(int speed,int time); //右轉(zhuǎn)函數(shù)
- void ZYSTM32_Spin_Right(int speed,int time);//右旋轉(zhuǎn)函數(shù)
- void ZYSTM32_back(int speed,int time); //后退函數(shù)
- */
- int main(void)
- {
- delay_init();
- KEY_Init();
- IRSearchInit();
- IRAvoidInit();
- Timerx_Init(5000,7199); //10Khz的計數(shù)頻率,計數(shù)到5000為500ms
- UltrasonicWave_Configuration(); //對超聲波模塊初始化
- uart_init(115200);
- TIM4_PWM_Init(7199,0); //初始化PWM
- ZYSTM32_brake(500);
- keysacn();
- while(1)
- {
- //printf("測到的距離值為:%d\n",UltrasonicWave_StartMeasure());
- if(UltrasonicWave_StartMeasure()<40)
- {
-
- ZYSTM32_back(50,500);
- ZYSTM32_Right(50,500);
- BEEP_SET;
- }
- else
- {
- ZYSTM32_run(50,1);
- BEEP_RESET;
- }
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
超聲波避障程序(無舵機).rar
(297.69 KB, 下載次數(shù): 173)
2017-9-15 02:17 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
-
功能說明圖.jpg
(275.82 KB, 下載次數(shù): 135)
下載附件
2017-9-14 23:35 上傳
避障小車
|