Self-balancing robot using MPU-6050



  • Hi there,
    I recently made a self-balancing robot using Arduino Nano and gyroscope MPU-6050 and DC motors. But I am having issues regarding the setting of PID values in the code in the Arduino IDE. No matter what values I set, the bot seems to have trouble balancing by itself. I saw various videos which told me the change the kp, ki and kd values accordingly but nothing seems to work. Can anyone help me on this?



  • HI @Henil179

    I made one myself a couple of years ago, and yes, it was a fair bit of trial and error to get it working.
    Of course, the gain values will be dependent on a number of factors, for example, the torque constant of your motor, the gear ratio, the mass of the robot, where your centre of gravity is located, your loop rate, and where you've located your mpu-6050.
    I located my mpu-6050 over the axis at 12 o'clock near the vertical centre of my bot.

    What are you control variables?
    I used pitch (angle of rotation around motor axis) calculated from gx, gz and tan function.
    I also used pitch rate from the gyro.

    Are you using the onboard DSP of the mpu-6050 to do the calculations?
    I had no luck with this, the mpu-6050 kept freezing up, bad clone I guess.

    You also have to verify the direction of rotation of your motor versus your control variables.
    If you have the wrong direction, it will just run away.

    My gains are Kp:41, Ki:160, Kd:0.4

    I started with only Kp and kept increasing the value until the system became unstable, then I backed off to a stable point.
    Next, I began increasing Ki. This will bring you to steady state stability. It should balance itself when Kp & Ki.
    You will likely have to reduce Kp somewhat as you move to higher Ki values, if your system becomes unstable.
    Finally, I added Kd, to help it react more quickly to changes in angle.

    How do you change your gains?
    I have a bluetooth module on mine, to allow me to send serial commands to the robot, to set the gains and other things.

    My robot's biggest problem is gear backlash. This generates acceleration noise as it vibrates backward/forward, balancing itself. This vibration can feedback on itself and cause instability (when you increase Kp too high). It looks like the robot has Parkinsons when this happens! 😀

    I'd like to update my design to use a belt/gear drive or continuous rotation servo, but I haven't had a chance to get back to it.

    I hope this helps.


Log in to reply
 

Suggested Topics

  • 87
  • 7
  • 5
  • 10
  • 7
  • 6

23
Online

11.2k
Users

11.1k
Topics

112.5k
Posts