No video

How to Visually Tune PID Control Loops

  Рет қаралды 95,775

upgrdman

upgrdman

Күн бұрын

This video shows how I tuned the PID control loop of a balancing robot. The behavior of the robot is shown, and perhaps more importantly, I also show live graphs of the error, set point, proportional component, integral component and derivative component. Finally the source code is shown and explained.
The video starts with a brief demo of how the robot performs with a tuned PID control loop. The balancing robot does not have any wheel encoders or other position feedback, so the only control loop inputs are the pitch of the robot and the throttle input from the user. Because of that, the robot can drift a little if it picks up speed, but even so, with a properly tuned PID control loop it performs fairly well.
I then show a proportional-only control loop and we see how it performs when the gain is too low or too high.
Next I add the integral part, forming a PI control loop. Again, I show how it looks when the gain is set too low or too high.
Then I add the derivative part, forming the PID control loop. The derivative part helps to dampen oscillations and really brings everything together. Like before, I also show how it behaves when the gain is too low or too high.
Finally I show the source code written for an STM32F0 microcontroller, and explain how it works.
The source code is available here:
github.com/far...
This video is part of a series showing how to build a balancing robot:
Part 1: Modify RC Servos for Continuous Rotation and External H-Bridge Control
• Modify RC Servos for C...
Part 2: Building a Robot Chassis with Brass Square Tube, a Dremel, and Solder
• Building a Robot Chass...
Part 3: First Steps with a GY-86 10DOF Sensor: MPU6050, HMC5883L and MS5611
• First Steps with a GY-...
Part 4: 6DOF & 9DOF Sensor Fusion with Madgwick's Filter, MPU6050, HMC5883L (GY-86 Module)
• 6DOF & 9DOF Sensor Fus...
Part 5: How to Use CC2500 PA LNA 2.4GHz Wireless RF Modules
• How to Use CC2500 PA L...
Part 6: GPU-Accelerated Data Logging and Telemetry
• GPU-Accelerated Arduin...
Part 7: [THIS VIDEO] How to Tune PID Control Loops Visually
• How to Visually Tune P...

Пікірлер: 81
@jeanbenoit6468
@jeanbenoit6468 7 жыл бұрын
You are my savior....I was desperate to find one day somebody with enough knowledge of the subject and with the desire to really help others understand it...thank you very much !!!
@send2murph
@send2murph Жыл бұрын
I've been looking at balancing robot code on the internet for some time now, and this is by far the most exceptional example I have come across. Thanks for sharing this great project, and thanks for also sharing all of the extremely well written source code. Well done!
@upgrdman
@upgrdman Жыл бұрын
Glad it was helpful!
@tamim24
@tamim24 5 жыл бұрын
somebody get this man some wheel encoders
@human.earthling
@human.earthling 7 жыл бұрын
Very nice display and dynamic control for P, I, D constants! Thank you
@ObsequiousV4
@ObsequiousV4 7 ай бұрын
Awesome video thank you!
@privatefactory1173
@privatefactory1173 5 жыл бұрын
Great video, thanks for sharing the code , thumbs up! I am trying to construct a very similar system but which does is some way the opposite( not to maintain an equilibrium\balance at a set target but to stay away from it) . A safety mechanism that prevents a motorcycle from flipping over when wheeling, when it reaches a critical angle, system kicks in and a servo motor pushes a brake pedal and brings the motorcycle back to "safe" angle range.
@queenidog1
@queenidog1 Жыл бұрын
sounds like a great idea. patent it!
@dominicraico1167
@dominicraico1167 5 жыл бұрын
best informational video i have seen on the subject. thank you so much
@alfonshomac
@alfonshomac 7 жыл бұрын
dude you have a series!... I'm in!. great videos!
@powling8361
@powling8361 5 жыл бұрын
Great visualisation of my Problem :)
@davidtitley4130
@davidtitley4130 3 ай бұрын
How would you add an additional device that only turn on when the wheels are moving, so if the robot was still the additional device object also stays off but does not have the same voltage.
@iwasz
@iwasz 6 жыл бұрын
I'm watching this for nth time, and my robot still wobbles like sh*t :(
@osamahfarhan
@osamahfarhan 6 жыл бұрын
That's great video.. Thank you very much..
@mikelemon5109
@mikelemon5109 7 жыл бұрын
I'm sure there is an auto PID system tuner library out there after all what visually is visible is also visible for the sensors.
@edencheung8468
@edencheung8468 5 жыл бұрын
very very very helpful. I fully understand it (im in middle school and 13 years old) and is using PID to do robotics stuff!
@brakesitr
@brakesitr 7 жыл бұрын
Boom!!! Great video man and you help out a lot. Now, if we could watch that graph as we are flying. Sh%t will get real...
@aurelioramos8463
@aurelioramos8463 4 жыл бұрын
May I suggest something slightly different: Apply a transformation to the total PID output that attempts to "flatten" the rotational acceleration. In other words, work out a function that computes the static torque required to support the weight at each angle. Measure the function that maps throttle input to torque (maybe this is hard to do without complicated hardware, so a good proxy might be to measure current to the motor unloaded (or with any load that does not lock it up) for each throttle position and draw that plot). Then tune a PID algorithm that feeds the input to a control function that only requires normalized torque (and automatically remaps it to throttle based on current instantaneous angle) Once you flatten out the non-linearity of controlling the inverted pendulum, you can tune a PID (or any other linear controller of your choosing) on top of that and I believe you will have far smoother control.
@upgrdman
@upgrdman 4 жыл бұрын
You're right. I stopped when it got "good enough," but yes, there is plenty of room for improvement.
@Daviddarwich
@Daviddarwich 6 жыл бұрын
Very well done Thank you
@47lokeshkumar74
@47lokeshkumar74 Жыл бұрын
Nice video.
@montinhoman
@montinhoman 7 жыл бұрын
Hi, where did you get that joystick (the gimbal part)? Also, you might wanna try to control the cossine of the pitch instead of the pitch itself ( i.e. error = cos(pitch) - cos(set_point) ). The torque needed to counteract the falling of the robot should be proportional to the cossine of the pitch. I haven't tried that, but I think that it might help as it would make the system linear.
@upgrdman
@upgrdman 7 жыл бұрын
Thanks for the tip, I'll try that. The gimbal was pulled from a RC hobby radio. You can find used radios for cheap on eBay, and its often straightforward to remove their gimbals and reuse them. Or buy a cheap new radio from somewhere like Hobby King.
@montinhoman
@montinhoman 7 жыл бұрын
Thanks. Yeah, a full radio on hobby king is half the price of a single gimbal on digikey...But I thought there might be a cheap source for them on aliexpress or something, but could not find any.
@viniciusnoyoutube
@viniciusnoyoutube 5 жыл бұрын
Excellent!
@aidatifola
@aidatifola 6 жыл бұрын
hello and great work! -one question on the integral variable. how it gets accumulated if you assign it to 0 just before?
@upgrdman
@upgrdman 6 жыл бұрын
Thanks. It's a "static" variable, so the 0 is only assigned during start up, not during every function call.
@numberformat
@numberformat 6 жыл бұрын
True hero. Real life Tony Stark.
@inhwankim640
@inhwankim640 6 жыл бұрын
I have a question about those initial values of Kp, Ki, and Kd. How did the 12000 come out? In this video, you explained with the equation Max error * Kp = Max PWM. So Max error = 1000 (Max PWM) / 12000 (Kp) = 0.083 Radian = about 4.7 Degrees. I guess you set the max pitch angle to about 5 degrees, right? I am confused because you explained that you set max pitch angle to 30 degrees. Also, could you explain more specific about the initial values of Ki and Kd?
@upgrdman
@upgrdman 6 жыл бұрын
It's been a while and I don't remember exactly. I think I just held the robot at an angle that looked like it would require full throttle to recover from, and found that multiplying that pitch number by 12000 would result in a PWM setting of around 1000. So that would probably be around 4.7 degrees like you mentioned. The 30 degrees number is where my code says "we can't recover, turn off the motors, there's no point in even trying any more." This prevents the motors from staying on when the robot has fallen over. As for Ki and Kd, their initial values were 0 and I just tried increasing them until I got decent results. After finding a decent value, go back and tweak the other two, since there is some interaction between them.
@inhwankim640
@inhwankim640 6 жыл бұрын
Thanks for the reply. It clears my understanding. Btw, your telemetry viewer is awesome. Did you receive the telemetry data via RF module? I am trying to receive serial data in wireless with Bluetooth but having some issues in using BT.
@upgrdman
@upgrdman 6 жыл бұрын
Thanks. Yes, I'm using one of these Bluetooth UARTs: amzn.to/2jm1HIw
@alibasri6729
@alibasri6729 2 жыл бұрын
please. is the PID a software control system or hardware????????
@upgrdman
@upgrdman 2 жыл бұрын
I did it in firmware, but a PID control loop can be done either way.
@AbishaiSingh
@AbishaiSingh 6 жыл бұрын
Nice work there, just have a question. Why is the battery positioned at the top of the robot, isn't it harder for the controller to balance?
@upgrdman
@upgrdman 6 жыл бұрын
Having some weight up high actually makes it easier to balance.
@andreluizeng
@andreluizeng 4 жыл бұрын
Hi have you compensated the motor's deadzone ? how you did it? adding a constant value to the pwm ?
@upgrdman
@upgrdman 4 жыл бұрын
The motors don't have much of a deadzone. If you are referring to slop in the gears, the servos I modified have very little slop. I didn't need to compensate for it.
@andreluizeng
@andreluizeng 4 жыл бұрын
@@upgrdman thanks for your answer, what I actually meant with the dead zone is the the value your PWM in the motors starts making it run. For example, in my case, from 0 to 100, the robot start moving when PWM is around 30.
@johnnicinco
@johnnicinco 7 жыл бұрын
Very good. What is the minimum number of readings that you must have per second? In other words could it work with only one reading per second?
@upgrdman
@upgrdman 7 жыл бұрын
A PID control loop can be used with any sample rate, but for a balancing robot I wouldn't want to go much slower than 50 Hz.
@srikantjenakumar
@srikantjenakumar 6 жыл бұрын
Which software are you using to visualize the PID Data? Please share the name here.
@upgrdman
@upgrdman 6 жыл бұрын
It's a program I made, called "Telemetry Viewer." I cover it in depth in several of my other videos.
@jeffreymelanson9230
@jeffreymelanson9230 6 жыл бұрын
Brilliant.
@Artur960426
@Artur960426 5 жыл бұрын
How do you manage to avoid drifting to one side, accelerating and eventually falling to that side, while balancing without encoders? It looks like you have perfect mass distribution between front and back (which can't really be in real world). My robot keeps stabilized only on surfaces with high friction (like carpet), but on smooth floor it keeps drifting to one side and falls. I would really be grateful for any hint on that. BTW, great job with your robot.
@upgrdman
@upgrdman 5 жыл бұрын
Thanks. On very smooth surfaces, and sloped surfaces, it can drift like you describe. I was tempted to try using the accelerometer readings to compensate for that type of drift, but never got around to it. I suspect wheel encoders or some other means of velocity/position sensing would be required for best results.
@Artur960426
@Artur960426 5 жыл бұрын
@@upgrdman Hey, thanks for response. I just realized, that I control PWM (velocity) and not angle like in your case (I also do not have encoders - only angle position). Isn't that the case, why my robot keeps falling immediately to little bit heavier side? BTW, Merry Christmas ;)
@shawncrocker7037
@shawncrocker7037 6 жыл бұрын
I thought time between the previous error and current error was part of the derivitive equation?
@philsson
@philsson 6 жыл бұрын
It is. But if the loop always runs at the same interval it can be cancelled out as part of the derivative gain.
@merseyviking
@merseyviking 7 жыл бұрын
So if you did have rotary encoders, how would that affect the set point?
@upgrdman
@upgrdman 7 жыл бұрын
With rotary encoders the robot could know if it is actually stationary. Right now it can only know it's angle. For example, if my floor was slanted, the robot would just glide down the slant (but stay vertical) instead of coming to a stop. Also, if I use encoders I could keep track of distance traveled and position the robot accurately.
@miniwarrior7
@miniwarrior7 7 жыл бұрын
upgrdman but even if you know wheel position that wouldn't matter because you still need to monitor your angle to keep it upright. So even with a encoder it will still walk back and fourth?
@jamescullins2709
@jamescullins2709 3 жыл бұрын
what software is the graphs done on?
@upgrdman
@upgrdman 3 жыл бұрын
It's "Telemetry Viewer", a tool that I made: www.farrellf.com/TelemetryViewer/
@jamescullins2709
@jamescullins2709 3 жыл бұрын
@@upgrdman Thanks
@iOLlVER
@iOLlVER 6 жыл бұрын
Can you quickly tell some differences between Kalman filtering and Madgwicks Sensor Fusion?
@upgrdman
@upgrdman 6 жыл бұрын
The biggest difference is that Madgwick's filter is easier to use because it has just one coefficient that needs to be adjusted. A Kalman filter is the classic way of doing things, and it works well, but it requires a lot more tweaking to get things performing well.
@iOLlVER
@iOLlVER 6 жыл бұрын
great, thank you!
@mrkattm
@mrkattm 6 жыл бұрын
I would love to see your state space equations for this, any chance you can post them, how did you model the motors?
@upgrdman
@upgrdman 6 жыл бұрын
I intentionally did no math or engineering for this control loop. The goal was to show how to do it intuitively, to hopefully make it understandable for a wider audience.
@miniproject-isem5381
@miniproject-isem5381 7 жыл бұрын
My very first question is how you able to set those values of Kp,Ki and Kd ; please explain!?
@miniwarrior7
@miniwarrior7 7 жыл бұрын
Mini Project-I Sem 5 the entire video explains just that
@upgrdman
@upgrdman 7 жыл бұрын
Hi. They are set with the three potentiometers on the remote control.
@kanabalize
@kanabalize 7 жыл бұрын
wow this is great. may i know if the GUI is on windows or Linux?
@upgrdman
@upgrdman 7 жыл бұрын
Thanks. It's running on Windows in the video, but it should run on Linux and Mac OS as well. I wrote it in Java, and the serial port and OpenGL libraries I used are supposedly cross-platform. I've only run it on Windows 10 and 7 but I wouldn't expect any problems on other platforms. For more info on the program, see the "Part 6" link in the video description.
@abderrahmenbelounis7784
@abderrahmenbelounis7784 7 жыл бұрын
fantastic job (y)
@mrarmymanful
@mrarmymanful 7 жыл бұрын
Hi, what's your loop update rate?
@upgrdman
@upgrdman 7 жыл бұрын
I don't remember the exact rate, but it was around 70-100Hz.
@mrarmymanful
@mrarmymanful 7 жыл бұрын
Oh interesting. And how fast are those servos in terms of RPM? I have an issue where my bot is barely able to maintain vertical position. It may be because my bot is fairly short and does not have enough weight up top.
@guillermomejiacisneros4304
@guillermomejiacisneros4304 2 жыл бұрын
Hi, could you share your code?
@upgrdman
@upgrdman 2 жыл бұрын
There's a link in the video description.
@ammarmahmoud2224
@ammarmahmoud2224 7 жыл бұрын
try concentrating the center of mass on the wheels' axis to increase stability
@upgrdman
@upgrdman 7 жыл бұрын
That would actually make things more difficult. Think of balancing a pen on your finger. A longer pen (or whatever) is easier to balance. Having the CG higher up makes the system easier to work with.
@TutocarloCV
@TutocarloCV 6 жыл бұрын
nice
@mohamedkhaled-qc7kb
@mohamedkhaled-qc7kb 6 жыл бұрын
I want software that show in the monitor for PID control
@upgrdman
@upgrdman 6 жыл бұрын
Check out my other videos, I cover the software in my "telemetry" and "data visualization" videos.
@psanyi0042
@psanyi0042 7 жыл бұрын
Im not a java programmer, but i think you set the previous error to 0 every time you run the function.
@upgrdman
@upgrdman 7 жыл бұрын
The firmware is written in C, and that variable is static so it's only initialized to 0 at reset.
@psanyi0042
@psanyi0042 7 жыл бұрын
I see, C and C# is different in this.
@ustaoybek
@ustaoybek Жыл бұрын
Hello 👋
What is a PID Controller? | DigiKey
22:19
DigiKey
Рет қаралды 74 М.
Self Balancing Robot Tips that will Save your project
5:36
Mouad Boumediene - Hobby Coding
Рет қаралды 28 М.
What will he say ? 😱 #smarthome #cleaning #homecleaning #gadgets
01:00
Dad Makes Daughter Clean Up Spilled Chips #shorts
00:16
Fabiosa Stories
Рет қаралды 2,2 МЛН
Мы сделали гигантские сухарики!  #большаяеда
00:44
How to Tune a PID Controller
18:14
PID Explained
Рет қаралды 104 М.
Robotics Programming: PID Algorithm - Wall Following and Balancing
33:37
Advanced Arduino Telemetry and Data Visualization
55:24
upgrdman
Рет қаралды 25 М.
A Lesson in Failure: Reaction Wheel PID Tuning
14:02
Ian Carey
Рет қаралды 1,8 М.
PIDs Simplified
13:07
SiieeFPV
Рет қаралды 292 М.
PID Balance+Ball | full explanation & tuning
13:13
Electronoobs
Рет қаралды 739 М.
How to Tune a PID Controller
8:43
RealPars
Рет қаралды 781 М.
Tuning A Control Loop - The Knowledge Board
21:51
ABB Process Automation
Рет қаралды 439 М.
DC motor PID speed control
15:29
Curio Res
Рет қаралды 230 М.
What will he say ? 😱 #smarthome #cleaning #homecleaning #gadgets
01:00