查看: 14665|回复: 65

[经验] STM32多功能智能小车制作(循迹+壁障+遥控)源码

  [复制链接]

该用户从未签到

发表于 2020-3-31 15:20:08 | 显示全部楼层 |阅读模式
分享到:
分享一个STM32 自巡逻避障小车。 共勉
多功能智能小车


功能:
循迹+避障+遥控

制作难点:

1.超声波,舵机,电机三者的协调。
2.实时快速反应,整个过程的程序要流畅,不能停留在某一处。
3.STM32超声波捕获也是一个亮点。

程序的亮点:



蓝牙HC-06模块使用STM32 DMA控制器,使小车在循迹+避障+遥控功能的切换中运行流畅,解决了蓝牙串口发送数据延迟问题。


超声波,舵机,电机三者的协调得比较好。

总结:
刚开始软硬件搭配不挡,没有按照科学的方法一步一步排除遇到的问题。让很容易解决的问题拖了很久,浪费了很多时间。同时,由于没考虑到stm32这块主控芯片的电压安全问题,烧了几块芯片。这是我们得到的教训。总的来说,功能全部实现。

单片机源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  MCD Application Team
  5.   * @version V3.5.0
  6.   * @date    08-April-2011
  7.   * @brief   Main program body
  8. **/
  9. /* Includes ------------------------------------------------------------------*/
  10. #include "stm32f10x.h"
  11. #include "usart1.h"
  12. #include "SysTick.h"
  13. #include "motor_control.h"
  14. #include "UltrasonicWave.h"
  15. #include "TIM3.h"
  16. #include "pwm_output.h"
  17. /* Private typedef -----------------------------------------------------------*/
  18. /* Private define ------------------------------------------------------------*/
  19. /* Private macro -------------------------------------------------------------*/
  20. /* Private variables ---------------------------------------------------------*/
  21. vu32 Onward_flag=0;
  22. vu8 RxBuffer[2];
  23. vu32 PWM_flag=0;
  24. vu32 Left_flag=0;
  25. vu32 Right_flag=0;
  26. vu32 Backward_flag=0;
  27. vu32 Stop_flag=0;
  28. vu32 Xunji_flag=0;
  29. vu32 Auto_flag=0;
  30. vu8  count=0;

  31. /* Private function prototypes -----------------------------------------------*/
  32. void NVIC_Configuration(void);

  33. /* Private functions ---------------------------------------------------------*/

  34. /*******************************************************************************
  35. * 函数名         : main
  36. * 描述           : 主函数
  37. * 输入           : 无
  38. * 输出           : 无
  39. * 返回           : 无
  40. *******************************************************************************/
  41. int main(void)
  42. {
  43.    /* NVIC configuration */
  44.    NVIC_Configuration();
  45.    /* Configure the Usart1 */
  46.    USART1_Config();
  47.    /* Configure the DMA1 */
  48.    DMA_Configuration();
  49.    /* Configure the GPIO */
  50.    GPIO_Configuration();
  51.    /* Configure the TIM2 */
  52.    TIM2_Configuration();
  53.    /* Configure the TIM3 */
  54.    TIM4_Configuration();
  55.    /* Configure the TIM4 */
  56.         Control_GPIOE_Config();  /*配置传感器输入信号管脚*/
  57. //   TIM4_Configuration();
  58.           TIM3_GPIO_Config();
  59.    /* Configure the systick */
  60.    SysTick_Init();
  61.    /* Configure the UltrasonicWave */
  62.    UltrasonicWave_Configuration();

  63.    Degree(85,1);


  64. //         Delay_ms(1500);

  65.    while (1)
  66.   {

  67.                 //        Auto_run();

  68.          IF(Onward_flag==1)
  69.           {
  70.             Forward_run();                         //前进
  71.           }
  72.          else if(Backward_flag==1)
  73.           {
  74.             Backward_run();                  //后退
  75.           }
  76.          else if(Left_flag==1)
  77.           {
  78.             Left_turn();                     //左转
  79.           }
  80.          else if(Right_flag==1)
  81.           {
  82.             Right_turn();                    // 右转
  83.           }
  84.           else if(Auto_flag==1)
  85.           {
  86.             Auto_run();                                         //自动避障行驶
  87.           }
  88.                 else if(Xunji_flag==1)
  89.           {
  90.             Xunji_run();                                         //自动循迹行驶
  91.           }
  92.           else
  93.           {
  94.            Stop();                           //暂停
  95.           }
  96.         }
  97.   }





  98. /*******************************************************************************
  99. * 函数名         : NVIC_Configuration
  100. * 描述           : 初始化NVIC
  101. * 输入           : 无
  102. * 输出           : 无
  103. * 返回           : 无
  104. *******************************************************************************/
  105. void NVIC_Configuration(void)
  106. {
  107.    NVIC_InitTypeDef NVIC_InitStructure;

  108.    /* Configure the Priority Group to 2 bits */
  109.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

  110.   NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn ;                // Enable the DMA_Channel5 Interrupt
  111.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  112.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  113.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  114.   NVIC_Init(&NVIC_InitStructure);

  115.   NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
  116.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  117.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  118.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  119.   NVIC_Init(&NVIC_InitStructure);
  120. }



  121. /******************* (C) COPYRIGHT 2011 STmicroelectronics *****END OF FILE****/
复制代码

游客,如果您要查看本帖隐藏内容请回复


只!下!载!不!顶!帖!的!都!是!坏!银!


回复

使用道具 举报

该用户从未签到

发表于 2020-5-13 09:30:30 | 显示全部楼层
感谢分享,很需要很有用
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2020-8-6 17:09:51 | 显示全部楼层
谢谢楼主,学习了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /2 下一条



手机版|小黑屋|与非网

GMT+8, 2024-3-29 21:56 , Processed in 0.200842 second(s), 35 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.