标题: STM32驱动的超声波避障程序 [打印本页]

作者: LVDOUBI    时间: 2017-9-14 23:36
标题: STM32驱动的超声波避障程序
这是一个使用STM32驱动小车实现超声波避障功能的程序,亲测可用

实验器材:
    ZYSTM32-A0智能机器人产品
实验目的:
    本实验为新建工程实验,仅供大家新建工程时参考。
    新建工程详细步骤,请看《STM32不完全手册-库函数版本》第3.3节。
实验现象:
    本实验下载后,控制板上接到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);       //前进函数
  13. void ZYSTM32_brake(int time);               //刹车函数
  14. void ZYSTM32_Left(int speed,int time);      //左转函数
  15. void ZYSTM32_Spin_Left(int speed,int time); //左旋转函数
  16. void ZYSTM32_Right(int speed,int time);     //右转函数
  17. void ZYSTM32_Spin_Right(int speed,int time);//右旋转函数
  18. void ZYSTM32_back(int speed,int time);      //后退函数
  19. */

  20. int main(void)
  21. {       

  22.          delay_init();
  23.          KEY_Init();
  24.          IRSearchInit();
  25.          IRAvoidInit();
  26.    Timerx_Init(5000,7199);   //10Khz的计数频率,计数到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. }

复制代码

所有资料51hei提供下载:
超声波避障程序(无舵机).rar (297.69 KB, 下载次数: 173)


功能说明图.jpg (275.82 KB, 下载次数: 135)

避障小车

避障小车

作者: 余生喜喜    时间: 2018-8-9 08:12
用的电机是什么

作者: 轻微二    时间: 2018-11-6 16:23
用的是减速电机??




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1