找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4772|回復(fù): 8
收起左側(cè)

STM32多功能智能小車制作(循跡+壁障+遙控)源碼

[復(fù)制鏈接]
ID:321874 發(fā)表于 2018-5-8 11:01 | 顯示全部樓層 |閱讀模式
分享一個STM32 自巡邏避障小車。 共勉
功能智能小車


功能:循跡+避障+遙控
制作難點(diǎn):
1.超聲波,舵機(jī),電機(jī)三者的協(xié)調(diào)。
2.實(shí)時快速反應(yīng),整個過程的程序要流暢,不能停留在某一處。
3.STM32超聲波捕獲也是一個亮點(diǎn)。
程序的亮點(diǎn):

    藍(lán)牙HC-06模塊使用STM32 DMA控制器,使小車在循跡+避障+遙控功能的切換中運(yùn)行流暢,解決了藍(lán)牙串口發(fā)送數(shù)據(jù)延遲問題。
    超聲波,舵機(jī),電機(jī)三者的協(xié)調(diào)得比較好。

總結(jié):剛開始軟硬件搭配不擋,沒有按照科學(xué)的方法一步一步排除遇到的問題。讓很容易解決的問題拖了很久,浪費(fèi)了很多時間。同時,由于沒考慮到stm32這塊主控芯片的電壓安全問題,燒了幾塊芯片。這是我們得到的教訓(xùn)?偟膩碚f,功能全部實(shí)現(xiàn)。

單片機(jī)源程序如下:
  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. * 函數(shù)名         : main
  36. * 描述           : 主函數(shù)
  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.          
  65. //         Delay_ms(1500);

  66.    while (1)
  67.   {
  68.                
  69.                 //        Auto_run();
  70.                
  71.          if(Onward_flag==1)
  72.           {
  73.             Forward_run();                         //前進(jìn)
  74.           }
  75.          else if(Backward_flag==1)
  76.           {
  77.             Backward_run();                  //后退
  78.           }
  79.          else if(Left_flag==1)
  80.           {
  81.             Left_turn();                     //左轉(zhuǎn)
  82.           }
  83.          else if(Right_flag==1)
  84.           {
  85.             Right_turn();                    // 右轉(zhuǎn)
  86.           }
  87.           else if(Auto_flag==1)
  88.           {
  89.             Auto_run();                                         //自動避障行駛
  90.           }
  91.                 else if(Xunji_flag==1)
  92.           {
  93.             Xunji_run();                                         //自動循跡行駛
  94.           }
  95.           else
  96.           {
  97.            Stop();                           //暫停
  98.           }
  99.         }
  100.   }                       
  101.   




  102. /*******************************************************************************
  103. * 函數(shù)名         : NVIC_Configuration
  104. * 描述           : 初始化NVIC
  105. * 輸入           : 無
  106. * 輸出           : 無
  107. * 返回           : 無
  108. *******************************************************************************/
  109. void NVIC_Configuration(void)
  110. {
  111.    NVIC_InitTypeDef NVIC_InitStructure;

  112.    /* Configure the Priority Group to 2 bits */
  113.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  114.   
  115.   NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn ;                // Enable the DMA_Channel5 Interrupt
  116.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  117.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  118.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  119.   NVIC_Init(&NVIC_InitStructure);

  120.   NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;          
  121.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  122.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;       
  123.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  124.   NVIC_Init(&NVIC_InitStructure);
  125. }
  126.   


  127. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
復(fù)制代碼

所有資料51hei提供下載:
stm32-超聲波避障.rar (3.15 MB, 下載次數(shù): 74)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復(fù)

使用道具 舉報

ID:326004 發(fā)表于 2018-5-10 14:40 | 顯示全部樓層
請問有沒有具體的電路圖,提供參考,謝謝
回復(fù)

使用道具 舉報

ID:311115 發(fā)表于 2018-5-12 19:51 | 顯示全部樓層
用什么模塊做電機(jī)驅(qū)動?
回復(fù)

使用道具 舉報

ID:225778 發(fā)表于 2018-5-19 16:57 | 顯示全部樓層

用什么模塊做電機(jī)驅(qū)動?298N?
回復(fù)

使用道具 舉報

ID:225778 發(fā)表于 2018-5-19 16:59 | 顯示全部樓層
很好的。用什么模塊做電機(jī)驅(qū)動?
回復(fù)

使用道具 舉報

ID:158588 發(fā)表于 2019-4-7 14:15 | 顯示全部樓層
源碼在MOTOR的文檔中對GPIO的配置有問題
回復(fù)

使用道具 舉報

ID:505599 發(fā)表于 2019-4-11 10:24 | 顯示全部樓層
好,非常好
回復(fù)

使用道具 舉報

ID:507145 發(fā)表于 2019-4-14 15:11 | 顯示全部樓層
你好,請問一下編譯時顯示缺少stdint的頭文件該怎么辦?
回復(fù)

使用道具 舉報

ID:512250 發(fā)表于 2019-4-14 22:34 | 顯示全部樓層
強(qiáng)者的帖子
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

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