標(biāo)題:
stm32步進(jìn)電機(jī)平衡車 直立和速度控制代碼
[打印本頁]
作者:
bannyff
時(shí)間:
2019-5-24 16:03
標(biāo)題:
stm32步進(jìn)電機(jī)平衡車 直立和速度控制代碼
平衡之家的程序修改的。
單片機(jī)源程序如下:
#include "sys.h"
u8 Way_Angle=1; //獲取角度的算法,1:四元數(shù) 2:卡爾曼 3:互補(bǔ)濾波 (有的6050使用DMP時(shí),需要開機(jī)后不停搖晃小車10S左右,等待數(shù)據(jù)穩(wěn)定)
u8 Flag_Qian,Flag_Hou;
float Angle_Balance,Gyro_Balance,Acceleration_Z;
int Moto1,Moto2,Final_Moto1,Final_Moto2; //電機(jī)PWM變量
float Balance_Kp=190,Balance_Kd=0,Velocity_Kp=42,Velocity_Ki=0.21;
//float Zhongzhi=3.89;
int Zhongzhi,Flag_Zhongzhi=0;
int main(void)
{
Stm32_Clock_Init(9); //系統(tǒng)時(shí)鐘設(shè)置
MY_NVIC_PriorityGroupConfig(2); //=====中斷分組
delay_init(72); //延時(shí)初始化
uart_init(72,9600); //初始化串口1
LED_Init();
IIC_Init(); //模擬IIC初始化
MPU6050_initialize(); //=====MPU6050初始化
DMP_Init(); //初始化DMP
Timer2_Init(50,7200);
//MiniBalance_EXTI_Init();
MiniBalance_Motor_Init(); //=====電機(jī)方向IO控制初始化
MiniBalance_PWM_Init(); //=====初始化PWM 輸出
while(1)
{
//Read_DMP(); //===讀取傾角
//printf("Roll:%f ",Roll); //X
//printf("Pitch:%f ",Pitch); //Y
//printf("Yaw:%f\r\n",Yaw); //Z
//delay_ms(10);
}
}
復(fù)制代碼
所有資料51hei提供下載:
步進(jìn)電機(jī)平衡車(DMP).7z
(219.41 KB, 下載次數(shù): 82)
2019-5-24 18:49 上傳
點(diǎn)擊文件名下載附件
自己修改的代碼
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1