找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 6167|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

stm32智能小車超聲波避障實(shí)驗(yàn)(有舵機(jī))源碼

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:297748 發(fā)表于 2018-10-24 21:08 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
這是一個(gè)stm32小車的避障程序,親測(cè)可行,歡迎大家下載

單片機(jī)源程序如下:
  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. #include "Server.h"

  11. // 超聲波轉(zhuǎn)頭函數(shù)
  12. int front_detection()
  13. {

  14. //        ZYSTM32_brake(0);
  15.         SetJointAngle(90);
  16.         delay_ms(100);
  17.         return UltrasonicWave_StartMeasure();
  18. }
  19. int left_detection()
  20. {

  21. //        ZYSTM32_brake(0);
  22.         SetJointAngle(175);
  23.         delay_ms(300);
  24.         return UltrasonicWave_StartMeasure();
  25. }
  26. int right_detection()
  27. {

  28. //        ZYSTM32_brake(0);
  29.         SetJointAngle(5);
  30.         delay_ms(300);
  31.         return UltrasonicWave_StartMeasure();
  32. }
  33. //extern int U_temp;
  34. /*
  35. void ZYSTM32_run(int speed,int time);       //前進(jìn)函數(shù)
  36. void ZYSTM32_brake(int time);               //剎車函數(shù)
  37. void ZYSTM32_Left(int speed,int time);      //左轉(zhuǎn)函數(shù)
  38. void ZYSTM32_Spin_Left(int speed,int time); //左旋轉(zhuǎn)函數(shù)
  39. void ZYSTM32_Right(int speed,int time);     //右轉(zhuǎn)函數(shù)
  40. void ZYSTM32_Spin_Right(int speed,int time);//右旋轉(zhuǎn)函數(shù)
  41. void ZYSTM32_back(int speed,int time);      //后退函數(shù)
  42. */

  43. int main(void)
  44. {       
  45.    int Q_temp,L_temp,R_temp;
  46.          delay_init();
  47.          KEY_Init();
  48.          IRSearchInit();
  49.          IRAvoidInit();
  50.    Timerx_Init(5000,7199);                //10Khz的計(jì)數(shù)頻率,計(jì)數(shù)到5000為500ms
  51.          UltrasonicWave_Configuration();        //對(duì)超聲波模塊初始化
  52.          uart_init(115200);
  53.          TIM4_PWM_Init(7199,0);                 //初始化PWM
  54.          TIM5_PWM_Init(9999,143);               //不分頻,PWM頻率=72*10^6/(9999+1)/(143+1)=50Hz         
  55.          ZYSTM32_brake(500);
  56.          keysacn();               
  57.         while(1)
  58.         {                 
  59.         //        Q_temp = front_detection();
  60.         //  printf("測(cè)到的距離值為:%d\n",Q_temp);
  61.                 Q_temp = front_detection();
  62.                 if(Q_temp<60 && Q_temp>0) //測(cè)量距離值       
  63.                 {
  64.                         ZYSTM32_brake(500);               
  65.                         ZYSTM32_back(60,500);       
  66.                         ZYSTM32_brake(1000);       
  67.                        
  68.                         L_temp=left_detection();//測(cè)量左邊障礙物的距離值
  69.                         delay_ms(500);
  70.                         R_temp=right_detection();//測(cè)量右邊障礙物的距離值
  71.                         delay_ms(500);
  72.                        
  73.                         if((L_temp < 60 ) &&( R_temp < 60 ))//當(dāng)左右兩側(cè)均有障礙物靠的比較近
  74.                         {
  75.                                 ZYSTM32_Spin_Left(60,500);
  76.                         }                               
  77.       else if(L_temp > R_temp)
  78.                         {
  79.                                 ZYSTM32_Left(60,700);
  80.                                 ZYSTM32_brake(500);
  81.                         }       
  82.       else
  83.                         {
  84.                                 ZYSTM32_Right(60,700);
  85.                                 ZYSTM32_brake(500);                                       
  86.                         }                                                       
  87.                 }       
  88.                 else
  89.                 {
  90.                         ZYSTM32_run(60,10);
  91.                 }
  92.         }
  93. }
復(fù)制代碼

所有資料51hei提供下載:
stm32智能小車超聲波避障實(shí)驗(yàn)(有舵機(jī)).rar (338.1 KB, 下載次數(shù): 163)


評(píng)分

參與人數(shù) 2黑幣 +60 收起 理由
qxc548542 + 10 共享資料的黑幣獎(jiǎng)勵(lì)!
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏4 分享淘帖 頂1 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:423055 發(fā)表于 2018-11-8 16:02 | 只看該作者
不錯(cuò)的資源
回復(fù)

使用道具 舉報(bào)

板凳
ID:1022994 發(fā)表于 2022-10-23 10:33 | 只看該作者
有原理圖嗎
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表