標(biāo)題: STM32驅(qū)動的超聲波避障程序 [打印本頁]

作者: LVDOUBI    時間: 2017-9-14 23:36
標(biāo)題: STM32驅(qū)動的超聲波避障程序
這是一個使用STM32驅(qū)動小車實現(xiàn)超聲波避障功能的程序,親測可用

實驗器材:
    ZYSTM32-A0智能機器人產(chǎn)品
實驗?zāi)康?
    本實驗為新建工程實驗,僅供大家新建工程時參考。
    新建工程詳細(xì)步驟,請看《STM32不完全手冊-庫函數(shù)版本》第3.3節(jié)。
實驗現(xiàn)象:
    本實驗下載后,控制板上接到13端口的LED會閃爍!
注意事項:
    無.

單片機源程序如下:
  1. #include "stm32f10x.h"
  2. #include "delay.h"
  3. #include "motor.h"
  4. #include "keysacn.h"
  5. #include "IRSEARCH.h"
  6. #include "IRAvoid.h"
  7. #include "usart.h"
  8. #include "UltrasonicWave.h"
  9. #include "timer.h"


  10. //extern int U_temp;
  11. /*
  12. void ZYSTM32_run(int speed,int time);       //前進函數(shù)
  13. void ZYSTM32_brake(int time);               //剎車函數(shù)
  14. void ZYSTM32_Left(int speed,int time);      //左轉(zhuǎn)函數(shù)
  15. void ZYSTM32_Spin_Left(int speed,int time); //左旋轉(zhuǎn)函數(shù)
  16. void ZYSTM32_Right(int speed,int time);     //右轉(zhuǎn)函數(shù)
  17. void ZYSTM32_Spin_Right(int speed,int time);//右旋轉(zhuǎn)函數(shù)
  18. void ZYSTM32_back(int speed,int time);      //后退函數(shù)
  19. */

  20. int main(void)
  21. {       

  22.          delay_init();
  23.          KEY_Init();
  24.          IRSearchInit();
  25.          IRAvoidInit();
  26.    Timerx_Init(5000,7199);   //10Khz的計數(shù)頻率,計數(shù)到5000為500ms
  27.          UltrasonicWave_Configuration();               //對超聲波模塊初始化
  28.          uart_init(115200);
  29.          TIM4_PWM_Init(7199,0);  //初始化PWM
  30.          ZYSTM32_brake(500);
  31.          keysacn();               
  32.                 while(1)
  33.                 {                 
  34.                    //printf("測到的距離值為:%d\n",UltrasonicWave_StartMeasure());
  35.                         if(UltrasonicWave_StartMeasure()<40)
  36.       {
  37.      
  38.                                 ZYSTM32_back(50,500);
  39.         ZYSTM32_Right(50,500);                               
  40.         BEEP_SET;
  41.       }
  42.     else     
  43.       {
  44.         ZYSTM32_run(50,1);
  45.         BEEP_RESET;
  46.       }                       
  47.                 }
  48. }

復(fù)制代碼

所有資料51hei提供下載:
超聲波避障程序(無舵機).rar (297.69 KB, 下載次數(shù): 173)


功能說明圖.jpg (275.82 KB, 下載次數(shù): 135)

避障小車

避障小車

作者: 余生喜喜    時間: 2018-8-9 08:12
用的電機是什么

作者: 輕微二    時間: 2018-11-6 16:23
用的是減速電機??




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1