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

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 มิ.ย. 2024
  • 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 8 หลายเดือนก่อน +30

    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 8 หลายเดือนก่อน +2

      Honestly some of the best ads I've ran across. I appreciate them too!

  • @1082511
    @1082511 8 หลายเดือนก่อน +5

    Thank you, Digikey team and Shawn Hymel for this nice introductory instruction guide for PID controllers tuning.

  • @danhtrinh1769
    @danhtrinh1769 8 หลายเดือนก่อน +2

    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.

  • @JaenEngineering
    @JaenEngineering 8 หลายเดือนก่อน +1

    Nice little "Great Scott" shout-out at the beginning 🙂

  • @originalmianos
    @originalmianos 8 หลายเดือนก่อน +4

    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 6 หลายเดือนก่อน

      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.

  • @philipershler420
    @philipershler420 8 หลายเดือนก่อน

    What a complete introduction to PID control. Thanks!

  • @BerndFelsche
    @BerndFelsche 8 หลายเดือนก่อน +2

    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.

  • @ident1ty
    @ident1ty 7 หลายเดือนก่อน +1

    this is such a great video! you explained the concepts so well! great effort :D

  • @wethumour
    @wethumour 5 หลายเดือนก่อน +1

    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.

  • @mekkarmikke
    @mekkarmikke 3 หลายเดือนก่อน

    Thanks so much for this great video! Top quality!

  • @michaelnilan7413
    @michaelnilan7413 8 หลายเดือนก่อน +2

    Thank you for the great content ❣

  • @lesvh740
    @lesvh740 6 หลายเดือนก่อน

    It would be fun to replace the rotary encoder with imaging. Great video!

  • @Baker_FPV
    @Baker_FPV 4 หลายเดือนก่อน

    This is so good

  • @pacocubi2845
    @pacocubi2845 8 หลายเดือนก่อน +3

    So cool! Will we ever see a micropython version?

    • @ShawnHymel
      @ShawnHymel 8 หลายเดือนก่อน +3

      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.

  • @verdw6587
    @verdw6587 4 หลายเดือนก่อน

    Well presented tutorial Shawn, very informative. Question, what if Kp was a negative number, what would be the effect of the PID?

  • @geekzombie8795
    @geekzombie8795 8 หลายเดือนก่อน

    Thank you for the advertisement, DigiKey.

  • @jacksonsee2746
    @jacksonsee2746 8 หลายเดือนก่อน +3

    Cool!!!

  • @paulp1204
    @paulp1204 8 หลายเดือนก่อน +2

    Would you mind sharing the python code?

  • @rasimbot
    @rasimbot 8 หลายเดือนก่อน

    Is integral just another proportional if intervals are equal?

    • @danhtrinh1769
      @danhtrinh1769 8 หลายเดือนก่อน

      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 8 หลายเดือนก่อน

      @@danhtrinh1769 | Is it possible integral is drifting away due to floating point error?

    • @danhtrinh1769
      @danhtrinh1769 8 หลายเดือนก่อน

      @@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 8 หลายเดือนก่อน

      @@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 8 หลายเดือนก่อน

      @@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.

  • @eddyfontaineyoutu100
    @eddyfontaineyoutu100 8 หลายเดือนก่อน +2

    👍👍👍

  • @happyday.mjohnson
    @happyday.mjohnson 8 หลายเดือนก่อน

    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 7 หลายเดือนก่อน +1

      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 8 หลายเดือนก่อน +3

    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 7 หลายเดือนก่อน

    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 TH-cam feeds at least 100 times..

  • @mikekiel605
    @mikekiel605 5 หลายเดือนก่อน

    I am so so sick of your stupid inverted pendulum ad make a new one