4

I am working on a self-balancing robot, trying to obtain the best values for the angle PID regulator. I have a working program, but I am stuck on the tuning part.

The robot can hold position after start, but then it collapses or starts to oscillate.

What I understand:

  • Kp - proportional value works as an amplifier, so for a small angle error we can have enough response to keep the robot in vertical position
  • Kd - derived value "add smooth effect" - lower oscillation
  • Ki - integral value, ??? (I can't figure out what effect I can obtain with this part)

Here is a simple schematic how it works

I need help to understand the theoretical effect of value Ki for the angle PID regulator in self-balancing robot, and find a way to safely tune the robot so that it can hold a stable vertical position.

ocrdu
  • 8,705
  • 21
  • 30
  • 42
Crax
  • 41
  • 1
  • Since the control is involving balance your system is probably inherently open loop unstable. You will need to stabilize the system before you can design your PID controller. – Carl Apr 20 '22 at 14:24
  • @Carl can you explain more what you mean by 'inherently open loop unstable'? – Crax Apr 20 '22 at 14:31
  • 2
    This is a good read - https://www.wescottdesign.com/articles/pid/pidWithoutAPhd.pdf – HandyHowie Apr 20 '22 at 14:45
  • @Crax The open loop transfer function from reference to robot tilt angle will probably have a pole in the RHP. Ergo, an inherently unstable system. – Carl Apr 20 '22 at 16:02
  • Excess Ki made your loop unstable, that is normally correct by lead/lag network near unity gain. – Tony Stewart EE75 Jul 22 '22 at 03:38

2 Answers2

2

I dont know if you have found the desired gains (Kp, Ki, Kd). But here are some things you can do and understand:

Ki, is the integral term:

The purpose of Ki is to remove steady state error. For example, in the event of disturbance, with only Kp and Kd gains, the robot will oscillate back "close" to desired reference (vertical position) but will never be 100% vertical. Increasing Kp might reduce this error, however, it might also made the robot unstable. For this reason, Ki is usually used instead of increasing Kp. However, too much Ki may result to overshoot and too much oscillation.

From diagram you shown, your system is clearly a cascaded control system

  1. It is often best to let the gains of the outer PID control (PID angle) constant to some value first.
  2. After that, set Kd and Ki of the inner PID controls (motor left and motor right) to zero first.
  3. Then increase Kp of inner PID until the robot become unstable (oscillate). At this stage, it doesnt really matter if the robot is not yet vertical. It just have to have enough Kp to be able to reach the vertical point from an angle offset before falling down.
  4. Set (Kt = 1.2 * Kp / A) and Kd = (3 * Kp * A / 40), where "A" is the oscillation period you desired, im guessing you want to set A to be as low as possible, without getting the motor to be saturated.
  5. Repeat step 2 to 4 for the outer PID control (PID angle).

This tuning method is called the Ziegler–Nichols cascaded tuning method.

That being said, you still might need to make small adjustment of the gains to fit your requirement. From the description you gave of it initially stable, but then start to oscillate, it sounds like you need to increase Kd to stabilized it and minimize overshoot (making it more smooth steady movement)

The "proper" method of gain tuning in PID:

There isn't a proper method, it depends on your circumstances. But usually, trial and error is not a viable option. Therefore, you would want to actually build a mathematical model and calculate the kinematics of the system. From there you can get an differential equation, where you can calculate exactly the Kp, Ki, Kd you need based on a time specification you required (rise time, settling time, amount of overshoot, etc).

The other way is loop shaping. This is where you can estimate at what frequency the disturbance and sensor measurement noise happened at. From there, you shape the loop in bode plot to the shape you desire so that it has sufficient gain and phase margin. Then, you divide it by the plant transfer function to get the control transfer function. Converting to time domain, you get a control system that is often more robust to disturbance and noise rejection.

John.Apple
  • 21
  • 4
0

There are two things you could do two stop the oscillations.

  1. Find the plant model and use control theory to tune in the system so it's stable. You will probably have to

  2. You could play with the PID values until it works. If the robot is oscillating then that means the system is unstable and probably to high P\I coefficients.

Tip, sometimes throwing a negative value in front of the controller can help to stabilize inverted pendulums

Voltage Spike
  • 75,799
  • 36
  • 80
  • 208