Go Down

Topic: Balancing robot PID tuning trouble (Read 25807 times) previous topic - next topic


Jul 17, 2017, 08:21 am Last Edit: Jul 17, 2017, 08:41 am by Southpark
Hi Sancho. It's possible that your Kp value may be too large. At the moment, you have a value of 700 for Kp.

I guess it all depends on the relative scaling factors for your error signal...... but I think values of Kp are typically in the range of 10 to 20 or so. Having very large values of Kp can make the bot become unstable.

For testing..... just set Ki to zero for now. And leave Kd as it is. And, if possible.....make Kp much smaller than 700..... such as 15. But then again, it all depends on the what sort of error voltages you have. Although, 700 appears way too large.

Also, the code that you posted....... this code doesn't run within your robot, right? If it does.... then avoid using delay() functions. Delay() functions will slow the loop iteration time, and can make a control system sluggish and maybe glitchy.


Hi Sancho. It's possible that your Kp value may be too large. At the moment, you have a value of 700 for Kp.

Thanks Southpark.
For my robot, only kp around 500 and 700 can keep it balance(even without kd), the value of kp from 0 to 100 makes it slow-responding and from 200 to 500 makes it swings back and forward (with my hand-holding), but that case it's just when I use the Kalman filter, I have tried the Complementary Filter before but I can't get it balance as easy as the Kalman filter, meanwhile the data from the Kalman seems like not really accurate than the Complementary filter.
And until now, I am sill not having a right way to tune my robot.


Hi Friends,
I have a question. I am making a self-balancing robot and I want to use encoders to increase the stability with two PID's. One PID for MPU 6050 and other PID for encoders. The question is: kp, ki, kd are the same values for both PID's??


Thanks again Kas!

I added encoders but don't use them for stability, only speed control.

Then I added a ultrasonic sensor and made it autonomous. Hope I get my 2.4Ghz modules soon!



Some details:

I used two cascading PI loops. The global input to the system is the velocity of the Centre Of Gravity (Vcog_target). To have a stationary robot it's Vcog_target = 0 etc.

The IMU raw readings are fed to a Kalman filter to get the robot tilt angle (theta) and tilt velocity:
theta_dot = angle - last_angle

Encoders read from each motors (928 counts / turn each) then I get wheel velocity:
Vwheel = count - last_count

The actual cog velocity Vcog is calculated from wheel velocity and tilt velocity:
Vcog = K x theta_dot + Vwheel

The factor K is to account for various things such as difference in units and height of the cog.

This then feeds the first PI loop which output is the desired tilt angle of the robot:

theta_target = PI (Vcog_target, Vcog)

The target tilt angle is fed into the second PI loop, the "classic" one used for balance:

motor_PWM = PI (theta_target, theta)

and this is sent to the motors.

The autonomous mode works by setting a desired speed. Then it reads the ultrasound sensor, and when an obstacle is detected, sets target speed to 0, waits a small delay, then spins the robot until it finds a path. Then sets speed again, etc.

With the two PI loops the robot is very stable to perturbation (pushes) but doesn't maintain a stationary position very well. I think it's due to my very crappy tuning of the stability PI parameters :D

I still can't get proper, clean balance when robot stays stationary. I looked at the Balanduino and it's very still when stationary, it uses the same motors as me so I know it's doable.

I still have the same problem, either the robot is too "soft" (low P and I values) and doesn't balance properly, or when I increase P and I it starts jittering a lot.

I think the root of the problem is backlash, and I'm looking at ways to deal with it. Then I will have better stability. I'm thinking of adding a 3rd PID loop to control motor speed: the 2nd PID output (desired motor speed) is fed to a 3rd PID which takes desired speed and actual speed (from encoders) to drive PWM. this loop would have to run very fast though to achieve anything. I don't know if that could work, gonna try it now!

I'm turning this topic into a "project progress" kind of post, hope it's OK.
Hi, I see that you V_cog PID takes velocity as an input but you get "Angle" as an output. How is that transformation happening?

Go Up