|
基于MPU6050的二輪平衡車(chē),注釋比較多,方便理解。
單片機(jī)源程序如下:
- /******************** (C) COPYRIGHT (2015)BST BALANCECAR **************************
- * 文件名 :main.c
- **********************************************************************************/
- #include "stm32f10x.h"
- #include "mpu6050.h"
- #include "i2c_mpu6050.h"
- #include "motor.h"
- #include "upstandingcar.h"
- #include "SysTick.h"
- #include "led.h"
- #include "usart.h"
- #include "i2c.h"
- #include "outputdata.h"
- #include "timer.h"
- #include "UltrasonicWave.h"
- #include "stm32f10x_usart.h"
- float gyz;
- int acc;
- int acc1;
- /*協(xié)議相關(guān)*/
- //extern u8 newLineReceived = 0;
- /*
- * 函數(shù)名:main
- * 描述 :主函數(shù)
- */
- int main(void)
- {
-
-
- SystemInit(); //=====系統(tǒng)初始化
- Timerx_Init(5000,7199); //定時(shí)器TIM1
- UltrasonicWave_Configuration(); //超聲波初始化設(shè)置 IO口及中斷設(shè)置
- USART1_Config(); //串口1初始化 上位機(jī)
- USART3_Config(); //串口3初始化 藍(lán)牙與USART3公用相同IO口
-
- TIM2_PWM_Init(); //PWM輸出初始化
- MOTOR_GPIO_Config(); //電機(jī)IO口初始化
- LED_GPIO_Config();
-
- TIM3_External_Clock_CountingMode(); //左電機(jī)脈沖輸出外部中斷口PA7使用TIM3定時(shí)器用作為脈沖數(shù)計(jì)算
- TIM4_External_Clock_CountingMode(); //右電機(jī)脈沖輸出外部中斷口PB7使用TIM4定時(shí)器用作為脈沖數(shù)計(jì)算
- TIM3_Encoder_Init(); //編碼器獲取脈沖數(shù) PA6 7
- TIM4_Encoder_Init(); //編碼器獲取脈沖數(shù) PB6 7
- ////////////////////DMP/////////////////////////////////
- i2cInit(); //IIC初始化 用于掛靠在總線上的設(shè)備使用
- delay_nms(10); //延時(shí)10ms
- MPU6050_Init(); //MPU6050 DMP陀螺儀初始化
-
- SysTick_Init(); //SysTick函數(shù)初始化
- CarUpstandInit(); //小車(chē)直立參數(shù)初始化
- SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; //使能總算法時(shí)鐘
- while (1)
- {
- GPIO_ResetBits(GPIOC, GPIO_Pin_13);
- MPU6050_Pose(); //獲取MPU6050角度狀態(tài)
- gy0=gyro[0];
- // UltrasonicWave_StartMeasure(); //調(diào)用超聲波發(fā)送程序 給Trig腳 <10us 高電平
- // chaoshengbo(); //計(jì)算超聲波測(cè)距距離
- // printf("%d",ucBluetoothValue);
- // printf("\t");
- // printf("%f",BST_fSpeedControlOutNew);
- // printf("\t");
- // printf("%f",BST_fCarAngle);
- // printf("\t");
- // printf("%f",BST_fLeftMotorOut);
- // printf("\t");
- // printf("\n");
-
- if (newLineReceived)
- {
- ProtocolCpyData();
- Protocol();
- }
- /*通過(guò)狀態(tài)控制小車(chē)*/
- CarStateOut();
-
- SendAutoUp();
-
-
- }
-
- }
復(fù)制代碼
所有資料51hei提供下載:
STM32平衡車(chē).7z
(500.19 KB, 下載次數(shù): 93)
2019-7-18 21:32 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|