Self-balancing robot PID tuning #2058
Replies: 1 comment 1 reply
-
This is a common misconception. While a balancing robot can totally work, PID is not the way to do it 🙂 For some reason, there are a lot of youtube tutorials teaching this the wrong way. PID control is intended for single-input-single-output systems: Measure one error and control it with one actuation force. A self-balancing robot is an underactuated system. You have just one actuator to control two things (body angle and robot position). To teach PID, you might consider a simpler application, such as a motor that holds a weight with a horizontal beam. What is the role of the P, I, and D in this context? When is You can also do this interactively without writing much code. Open the REPL ( The motor will now hold the 0 position. Now type this: Then you will see the existing constants for the motor. They have the following units: Now you can change them interactively like this: Try different values. Use the up arrow key to bring back your last command so you don't have to type it every time. Try twisting the motor by hand. What if you set If you do want to build a balancer, check this post for inspiration. In your case, you'd need it for only one axis instead of repeating it for two axes like we did in this example. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Everybody, for a 6 weeks advanced robotics class I teach, I want to educate my students (16yrs) on the properties of a PID loop. What better than a self balancing robot was my thought. Because my students enter the class with only the basic knowledge of programming (ARDUINO if/then) they use pybricks blocks.
I will give them the basic structure of the code, together witch a short (10 min) instruction on the idea behing PID. I want them to optimise the parameters.
I'm still not sure wether to teach them on on the physics (calculate the torque needed to correct a certain angle of error) or just go empirically and have them start hands-on. Although the latter has my preference, since the program these students are in, is actually based on solving real-life problems, not theoretical physics.
Here is what I have so far:
I let them start with Ki and Kd set to zero and optimise Kp untill oscillation occurs.
I then let them increase Kd, starting at 1% of Kp untill the oscillation dampens
Finally Ki is varied, starting at 20% of Kp untill the whole system is stable.
This knowledge came from my own digital-control book dating 30yrs ago when I was a physics student myself.
The problem: I can't get this sytem to become stable myself!

I know I should be using motor-speed, rather than motor power but I don't think pybricks gives me that option.
Oh, and for my students, all variables are "Dutchinated". I'm still not sure whether I like doing this.
Beta Was this translation helpful? Give feedback.
All reactions