標(biāo)題: stm32步進(jìn)電機(jī)平衡車 直立和速度控制代碼 [打印本頁]

作者: bannyff    時(shí)間: 2019-5-24 16:03
標(biāo)題: stm32步進(jìn)電機(jī)平衡車 直立和速度控制代碼
平衡之家的程序修改的。

單片機(jī)源程序如下:
  1. #include "sys.h"
  2. u8 Way_Angle=1;      //獲取角度的算法,1:四元數(shù)  2:卡爾曼  3:互補(bǔ)濾波 (有的6050使用DMP時(shí),需要開機(jī)后不停搖晃小車10S左右,等待數(shù)據(jù)穩(wěn)定)
  3. u8 Flag_Qian,Flag_Hou;
  4. float Angle_Balance,Gyro_Balance,Acceleration_Z;
  5. int Moto1,Moto2,Final_Moto1,Final_Moto2;    //電機(jī)PWM變量
  6. float Balance_Kp=190,Balance_Kd=0,Velocity_Kp=42,Velocity_Ki=0.21;
  7. //float Zhongzhi=3.89;
  8. int Zhongzhi,Flag_Zhongzhi=0;
  9. int main(void)
  10. {
  11.         Stm32_Clock_Init(9);            //系統(tǒng)時(shí)鐘設(shè)置
  12.         MY_NVIC_PriorityGroupConfig(2); //=====中斷分組
  13.         delay_init(72);                 //延時(shí)初始化
  14.         uart_init(72,9600);           //初始化串口1
  15.         LED_Init();
  16.         IIC_Init();                     //模擬IIC初始化
  17.   MPU6050_initialize();           //=====MPU6050初始化       
  18.         DMP_Init();                     //初始化DMP
  19.         Timer2_Init(50,7200);
  20.         //MiniBalance_EXTI_Init();
  21.         MiniBalance_Motor_Init();       //=====電機(jī)方向IO控制初始化
  22.   MiniBalance_PWM_Init();         //=====初始化PWM 輸出
  23.        
  24.         while(1)
  25.                 {
  26.                         //Read_DMP();                      //===讀取傾角
  27.                         //printf("Roll:%f  ",Roll);  //X
  28.                         //printf("Pitch:%f  ",Pitch); //Y
  29.                         //printf("Yaw:%f\r\n",Yaw);   //Z
  30.                         //delay_ms(10);
  31.                        
  32.                 }
  33. }
復(fù)制代碼

所有資料51hei提供下載:
步進(jìn)電機(jī)平衡車(DMP).7z (219.41 KB, 下載次數(shù): 82)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1