How to Tune a PID Controller for an Inverted Pendulum | DigiKey

  Рет қаралды 61,084

DigiKey

DigiKey

Күн бұрын

This tutorial demonstrates how to manually tune a PID controller to operate an inverted pendulum. Shawn uses the STEVAL-EDUKIT01 kit from STMicroelectronics, which includes an Arduino, encoder, and stepper motor connected together to create a feedback loop. The stepper motor rotates the encoder back and forth, and the encoder allows a bent rod to rotate freely around its axis. The intent is to design a controller in code that can make the rod (“pendulum”) stand upright with no human intervention.
You can learn more about PID controller theory in the previous video:
• What is a PID Controll...
Shawn uses a single PID controller in the video to maintain the rod in a vertical position. You can read about manual PID controller tuning here:
www.digikey.com/en/maker/proj...
The Arduino reads encoder values, which are sent to a Python program on a computer. The Python program acts as the PID controller in order to compute the stepper motor angle that is then sent back to the Arduino. The Arduino drives the stepper motor as requested by the Python PID controller.
Sending and receiving commands over a USB serial port is much slower than running the PID controller program directly on the Arduino. However, it allows us to construct pretty graphs and tune the PID controller much more easily. In other words, it’s great for teaching and demonstration but bad for production.
Manually tuning a PID controller consists of setting Ki and Kd to zero and slowly increasing Kp to find a point where the output almost (but not quite) reaches the setpoint without oscillating. From there, Ki is increased to remove the remaining steady-state error between output and setpoint. Ideally, the system should overshoot slightly but not oscillate around the setpoint.
In many cases, a PI controller is all that is needed. If overshoot is unacceptable, you can increase Kd so that the response approaches the setpoint quickly without overshooting. If Kp, Ki, or Kd are too high, you will find that your system begins oscillating (often uncontrollably). With properly tuned constants, you have a “critically damped” system.
PID controllers are widely popular in control theory and can be found in many places, especially in automotive and industrial applications.
Product Links:
STEVAL-EDUKIT01 - www.digikey.com/en/products/d...
Related Videos:
How to Control Output Voltage using a PID - • How to Control Output ...
Related Project Links:
Introduction to PID Controllers - www.digikey.com/en/maker/proj...
How to Tune a PID Controller - www.digikey.com/en/maker/proj...
Related Articles:
STMicroelectronics Inverted Pendulum Kit Documentation - www.st.com/en/evaluation-tool...
STMicroelectronics Inverted Pendulum Kit Curriculum - www.st.com/content/st_com/en/...
Learn more:
Maker.io - www.digikey.com/en/maker
DigiKey’s Blog - TheCircuit www.digikey.com/en/blog
Connect with DigiKey on Facebook / digikey.electronics
And follow us on X (formerly Twitter) / digikey
00:00 - Introduction to the Inverted Pendulum
01:09 - What is a PID Controller
02:17 - How to Tune a PID Controller
03:30 - Arduino Code to Measure Encoder and Drive Stepper Motor
05:19 - Python Code on PC Used to Communicate with Arduino
09:06 - Python Code Used as PID Controller
13:37 - Where to Find Code
14:02 - Tune Kd in the PID Controller
16:39 - Tune Ki in the PID Controller
19:33 - Tune Kd in the PID Controller
23:02 - Tune Bias Term in the PID Controller
24:03 - Conclusion

Пікірлер: 34
@gamerscomplete
@gamerscomplete 10 ай бұрын
I really appreciate that DigiKey is paying for videos like this to be made, it doesnt directly support sales of a particular product or even a direct tie in with DigiKey themselves. Just informative videos to garnish good will and brand recognition. This sorta stuff makes me want to purchase from DigiKey and/or refer to colleagues more than any product/brand specific videos would. As usual, another great video from Shawn Hymel
@mjolnirforsworn
@mjolnirforsworn 9 ай бұрын
Honestly some of the best ads I've ran across. I appreciate them too!
@1082511
@1082511 10 ай бұрын
Thank you, Digikey team and Shawn Hymel for this nice introductory instruction guide for PID controllers tuning.
@danhtrinh1769
@danhtrinh1769 9 ай бұрын
Thanks Digikey for these educational videos! This tips the balance of why I will buy parts for work from Digikey as opposed to the competitors.
@philipershler420
@philipershler420 9 ай бұрын
What a complete introduction to PID control. Thanks!
@ident1ty
@ident1ty 9 ай бұрын
this is such a great video! you explained the concepts so well! great effort :D
@michaelnilan7413
@michaelnilan7413 10 ай бұрын
Thank you for the great content ❣
@mekkarmikke
@mekkarmikke 4 ай бұрын
Thanks so much for this great video! Top quality!
@JaenEngineering
@JaenEngineering 10 ай бұрын
Nice little "Great Scott" shout-out at the beginning 🙂
@MohamadSayadiFars
@MohamadSayadiFars 9 күн бұрын
I love you. I like to watch all your videos
@originalmianos
@originalmianos 10 ай бұрын
I have been doing a PID controller for a reflux system for the last year. This is a great intro. There is only one more item I would add, being 'windup' handling. It can be the difference between controllable and not at all. I have never used a derivative but it is meant to be handy for speeding the approach to setpoint. For my use, a slow and steady approach with a well tuned integral wins by a long way.
@sneaky_krait7271
@sneaky_krait7271 8 ай бұрын
While derivative can speed up reaction time, it is not well suited with high frequent errors going up and down. It needs a clean signal to work well.
@Baker_FPV
@Baker_FPV 6 ай бұрын
This is so good
@wethumour
@wethumour 7 ай бұрын
Pretty cool. You should have out the encoder graph as the first one so you needn’t have had to keep scrolling up and down. And yes, I am going to dive into PIDs thanks to this video. Only been several decades of weak excuses aka lethargy.
@BerndFelsche
@BerndFelsche 10 ай бұрын
A usefully instructive video for getting from theory to practice. As an aside... Float variables are quite slow on AVR Arduino. Scaled integers are much faster, which can be significant in reducing controller loop delays. Such delays can wreak havoc in real world systems as they are significantly variable, depending on the values of variables and therefore difficult to tune out.
@jacksonsee2746
@jacksonsee2746 10 ай бұрын
Cool!!!
@lesvh740
@lesvh740 8 ай бұрын
It would be fun to replace the rotary encoder with imaging. Great video!
@verdw6587
@verdw6587 6 ай бұрын
Well presented tutorial Shawn, very informative. Question, what if Kp was a negative number, what would be the effect of the PID?
@pacocubi2845
@pacocubi2845 10 ай бұрын
So cool! Will we ever see a micropython version?
@ShawnHymel
@ShawnHymel 10 ай бұрын
Good to know there's interest. It should be fairly straightforward to implement in micropython--the Python code for the PID controller should be the exact same. The only think you need to change is the encoder reading and stepper motor control.
@paulp1204
@paulp1204 10 ай бұрын
Would you mind sharing the python code?
@eddyfontaineyoutu100
@eddyfontaineyoutu100 10 ай бұрын
👍👍👍
@rasimbot
@rasimbot 10 ай бұрын
Is integral just another proportional if intervals are equal?
@danhtrinh1769
@danhtrinh1769 9 ай бұрын
Integral sums the errors as a term. Proportional is error times a constant as a term. Sampling interval being equal make it easy to calculate integral with just a summation.
@rasimbot
@rasimbot 9 ай бұрын
@@danhtrinh1769 | Is it possible integral is drifting away due to floating point error?
@danhtrinh1769
@danhtrinh1769 9 ай бұрын
@@rasimbot Someone else in the comments mentioned integral windup. If your system never reaches your target value the integral term just keeps getting larger and larger and this is know as windup.
@rasimbot
@rasimbot 9 ай бұрын
@@danhtrinh1769 | What if you stored a certain number of recent errors in a buffer and calculated the integral over only the most recent data?
@danhtrinh1769
@danhtrinh1769 9 ай бұрын
@@rasimbot That is one possibility. I don't know how well it would work. Worst case your buffer contains a bunch of huge error values. Looks like there are many ways to handle integral windup based on Google searches. In some cases, the techniques are proprietary and not published. Ultimately, you could try a bunch of different techniques and plot your system response to see how quickly it settles.
@happyday.mjohnson
@happyday.mjohnson 10 ай бұрын
Thank you Shawn and Digikey. The two part series was very good. Question: what if the PID controller is to operate the supply of CO2 within a Grow Tent (CO2 can help plants grow 30% more)? Here we deal with not only fans blowing around, but the distribution of CO2 through a cylinder within a room distributed with plants ?
@ShawnHymel
@ShawnHymel 9 ай бұрын
If the CO2 and fans operate together, you can use a single PID controller that has one output. If they need to operate separately, then you likely need two different controllers or look for a more advanced Single Input Multiple Output (SIMO) or Multiple Input Mulitple Output (MIMO) control scheme.
@jimomertz
@jimomertz 10 ай бұрын
This was great, but I would have expected you to disturb the pendulum while it was stable, by giving it little bumps, and see how it reacted. Also would have been nice for a bigger screen to see the pendulum better.
@xephael3485
@xephael3485 9 ай бұрын
Does anybody just want to get out there bat 🏏and pretend this guy is the printer in office space? I've received this advertisement on my KZfaq feeds at least 100 times..
@mikekiel605
@mikekiel605 7 ай бұрын
I am so so sick of your stupid inverted pendulum ad make a new one
What is a PID Controller? | DigiKey
22:19
DigiKey
Рет қаралды 68 М.
How to Tune a PID Controller
8:43
RealPars
Рет қаралды 772 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 1,9 МЛН
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 39 МЛН
100❤️
00:19
MY💝No War🤝
Рет қаралды 23 МЛН
Lego, Raspberry and Python Project - Reaction Wheel Inverted Pendulum
21:14
Brick Experiment Channel
Рет қаралды 4,1 МЛН
Inverted Pendulum on a Cart [Control Bootcamp]
15:08
Steve Brunton
Рет қаралды 240 М.
How to Tune a PID Controller
18:14
PID Explained
Рет қаралды 100 М.
A real control system - how to start designing
26:58
Brian Douglas
Рет қаралды 262 М.
How to control a DC motor with an encoder
9:30
Curio Res
Рет қаралды 427 М.
I Built a Ball Balancing Robot
8:55
Aaed Musa
Рет қаралды 1 МЛН
PID Balance+Ball | full explanation & tuning
13:13
Electronoobs
Рет қаралды 734 М.
Open Source Motion Capture for Autonomous Drones
10:34
Joshua Bird
Рет қаралды 578 М.
PID Controller Implementation in Software - Phil's Lab #6
20:06
Phil’s Lab
Рет қаралды 205 М.
Creating and Tuning a PID controller with Python Simulation
40:25
Orion Aerospace
Рет қаралды 60 М.
Rate This Smartphone Cooler Set-up ⭐
0:10
Shakeuptech
Рет қаралды 2,2 МЛН
EXEED VX 2024: Не өзгерді?
9:06
Oljas Oqas
Рет қаралды 49 М.