Balance_Car


双轮平衡小车

项目地址

https://github.com/we-worker/Balance_car

设备材料:

  • STM32F103RCT6 –主控芯片
  • MPU6050 –6轴姿态传感器
  • L298N –电机驱动芯片
  • GM37-520 *2 – 霍尔直流减速电机
  • 0.72寸oled –屏幕
  • 充电宝&3.7v升压模块 –供电

思路设计:

设计

不同点

此项目完全使用hal库开发,每一个原件的控制基本都要改写。

踩坑点:

  • 一开始没用过STM32CubeMX,忘记配置debug,所以导致一写入程序,stm32就“废了”,需要通过更改boot其他启动方式才能下载程序。我一开始不知道,以为真坏了,又买了一个,又坏了,又买了一个导致最后买了近150元。
  • oled显示的巨大延迟。这个问题导致我荒废消沉了好几天,pid怎么调都调不好。最后怀疑是oled显示导致各种姿态数据读取不及时,电机调节滞后,把oled显示的注释掉之后,果然出来了,哭死,太痛苦了。
  • MPU6050的hal库移植真的麻烦,踩坑踩在了mpu6050的设备地址。

PID

这里的PID我只做直立部分,如果需要转弯的话,也是需要一个转向pid的。

直立环PD

直立环只使用了P和D

int balance(float Angle,float Gyro,float kp,float kd)
{  
   float Bias;
	 int balance;
	 Bias=Angle-0;       // Angle减几就是平衡到哪个角度
	 balance=kp*Bias+Gyro*kd;   
	 return balance;
}

速度环PI

int velocity(int encoder_left,int encoder_right,float velocity_KP,float velocity_KI)
{  
    static float Velocity,Encoder_Least,Encoder,Movement = 0;
    static float Encoder_Integral;
    //=============speed PI controller=======================//	
    Encoder_Least =(MotorSpeed1+MotorSpeed2)-0;                   
    Encoder *= 0.8;		                                               
    Encoder += Encoder_Least*0.2;	                                 
    Encoder_Integral +=Encoder;                                       
    Encoder_Integral=Encoder_Integral-Movement;                       
    if(Encoder_Integral>1500)  	
        Encoder_Integral=1500;             //intergral limit
    if(Encoder_Integral<-1500)		
        Encoder_Integral=-1500;            //intergral limit
    Velocity=Encoder*velocity_KP+Encoder_Integral*velocity_KI;        
    if(mpu_pose_msg.pitch<-30	||mpu_pose_msg.pitch>30) 			
        Encoder_Integral=0;     		  //clean intergral if motor close
    return -Velocity;
}

成品展示

改进点

  • 转向pid
  • 直立pid优化
  • 充电宝输出功率不太稳导致电机急速改变转速会直接断电源重启

Author: Dark Arc
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Dark Arc !
评论
  TOC