找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3015|回復: 3
打印 上一主題 下一主題
收起左側(cè)

基于MPU6050的二輪平衡車 STM32程序

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:183217 發(fā)表于 2019-7-18 21:03 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
基于MPU6050的二輪平衡車,注釋比較多,方便理解。

單片機源程序如下:
  1. /******************** (C) COPYRIGHT (2015)BST BALANCECAR **************************
  2. * 文件名  :main.c
  3. **********************************************************************************/
  4. #include "stm32f10x.h"
  5. #include "mpu6050.h"
  6. #include "i2c_mpu6050.h"
  7. #include "motor.h"
  8. #include "upstandingcar.h"
  9. #include "SysTick.h"
  10. #include "led.h"
  11. #include "usart.h"
  12. #include "i2c.h"
  13. #include "outputdata.h"
  14. #include "timer.h"
  15. #include "UltrasonicWave.h"
  16. #include "stm32f10x_usart.h"

  17. float gyz;
  18. int acc;
  19. int acc1;

  20. /*協(xié)議相關*/
  21. //extern u8 newLineReceived = 0;

  22. /*
  23. * 函數(shù)名:main
  24. * 描述  :主函數(shù)
  25. */
  26. int main(void)
  27. {       
  28.       
  29.        
  30.           SystemInit();                   //=====系統(tǒng)初始化
  31.         Timerx_Init(5000,7199);                                   //定時器TIM1
  32.         UltrasonicWave_Configuration();            //超聲波初始化設置 IO口及中斷設置                            

  33.         USART1_Config();                                                //串口1初始化 上位機
  34.         USART3_Config();                                                //串口3初始化 藍牙與USART3公用相同IO口
  35.        
  36.         TIM2_PWM_Init();                                           //PWM輸出初始化
  37.         MOTOR_GPIO_Config();                                  //電機IO口初始化
  38.           LED_GPIO_Config();
  39.        
  40.    TIM3_External_Clock_CountingMode();           //左電機脈沖輸出外部中斷口PA7使用TIM3定時器用作為脈沖數(shù)計算
  41.    TIM4_External_Clock_CountingMode();           //右電機脈沖輸出外部中斷口PB7使用TIM4定時器用作為脈沖數(shù)計算
  42.           TIM3_Encoder_Init();                       //編碼器獲取脈沖數(shù) PA6 7
  43.           TIM4_Encoder_Init();                       //編碼器獲取脈沖數(shù) PB6 7       
  44.         ////////////////////DMP/////////////////////////////////
  45.         i2cInit();                                                           //IIC初始化 用于掛靠在總線上的設備使用
  46.         delay_nms(10);                                                   //延時10ms
  47.         MPU6050_Init();                                                   //MPU6050 DMP陀螺儀初始化
  48.        
  49.         SysTick_Init();                                                  //SysTick函數(shù)初始化       
  50.         CarUpstandInit();                                          //小車直立參數(shù)初始化
  51.         SysTick->CTRL |=  SysTick_CTRL_ENABLE_Msk;         //使能總算法時鐘

  52.         while (1)
  53.         {

  54.                 GPIO_ResetBits(GPIOC, GPIO_Pin_13);
  55.                         MPU6050_Pose();                                                 //獲取MPU6050角度狀態(tài)
  56.                 gy0=gyro[0];
  57. //                 UltrasonicWave_StartMeasure();           //調(diào)用超聲波發(fā)送程序 給Trig腳 <10us 高電平                 
  58. //                 chaoshengbo();                               //計算超聲波測距距離
  59. //    printf("%d",ucBluetoothValue);
  60. //                printf("\t");
  61. //                printf("%f",BST_fSpeedControlOutNew);
  62. //                printf("\t");
  63. //                printf("%f",BST_fCarAngle);
  64. //                printf("\t");
  65. //                 printf("%f",BST_fLeftMotorOut);
  66. //                printf("\t");
  67. //                printf("\n");
  68.                
  69.                 if (newLineReceived)
  70.                    {
  71.                         ProtocolCpyData();
  72.                         Protocol();
  73.                 }
  74.                 /*通過狀態(tài)控制小車*/
  75.                 CarStateOut();
  76.                
  77.                 SendAutoUp();
  78.                
  79.                          
  80.          }
  81.                                                                     
  82. }
復制代碼

所有資料51hei提供下載:
STM32平衡車.7z (500.19 KB, 下載次數(shù): 93)



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

使用道具 舉報

沙發(fā)
ID:448382 發(fā)表于 2019-11-30 16:58 | 只看該作者
你好,程序我有下載,我想問一下里面編碼器讀取到的數(shù)據(jù)在哪有用到的?
回復

使用道具 舉報

板凳
ID:448382 發(fā)表于 2019-11-30 17:00 | 只看該作者
本帖最后由 帕里亞奇 于 2019-12-11 20:42 編輯

霍爾編碼器也適用嗎?
回復

使用道具 舉報

地板
ID:332041 發(fā)表于 2020-1-12 19:06 | 只看該作者
這個貼子不錯,真心收藏了。
回復

使用道具 舉報

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

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

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

快速回復 返回頂部 返回列表