PID Controller Implementation in Software - Phil's Lab #6

  Рет қаралды 203,696

Phil’s Lab

Phil’s Lab

Күн бұрын

⏵Hardware and PCB design course: www.phils-lab.net/courses
Source code available here: github.com/pms67/PID
How to implement a PID controller in software using C, discussing theory and practical considerations. Demonstration of PID controller code using a custom flight simulator.
If you're enjoying my content, please consider becoming a patron: / phils94
[NOTE] Something I forgot to mention in the video! Note on 'derivative-on-measurement': Since the 'error signal' effectively going into the differentiator does not depend on the setpoint: e[n] = 0 - measurement, and therefore (e[n] - e[n - 1]) = (0 - measurement) - (0 - prevMeasurement) = -Kd * (measurement - prevMeasurement). Note the minus sign compared to derivative-on-error!
I've made the change in the Git repo - before you would have had to use a negative Kd gain to get the same result. Now you can, as normal with derivative-on-error, use a positive Kd gain as usual.
Additional note: The derivative low-pass filter can be controlled by the constant 'tau', which is the time constant of the filter (-3dB frequency in Hz, fc = 1 / (2*pi*tau)). A larger value of tau means the signal is filtered more heavily. As tau approaches zero, the differentiator approaches a 'pure differentiator' with no filtering.
[TIMESTAMPS]
00:00 Introduction
00:39 Control system basics
02:40 PID representation in continuous domain
04:57 Converting from the continuous to the discrete domain
06:11 PID controller difference equation
07:35 Practical considerations
10:48 Basic software structure
11:53 Implementation in C
18:46 Example: Flight simulator using PID controller code
ID: QIBvbJtYjWuHiTG0uCoK

Пікірлер: 373
@PhilsLab
@PhilsLab 4 жыл бұрын
New hardware and PCB design course on mixed-signal embedded systems just released! ⏵Course content: www.phils-lab.net/courses ⏵Course sign-up: phils-lab-shop.fedevel.education Something I forgot to mention in the video! Note on 'derivative-on-measurement': Since the 'error signal' effectively going into the differentiator does not depend on the setpoint: e[n] = 0 - measurement, and therefore (e[n] - e[n - 1]) = (0 - measurement) - (0 - prevMeasurement) = -Kd * (measurement - prevMeasurement). Note the minus sign compared to derivative-on-error! I've made the change in the Git repo - before you would have had to use a negative Kd gain to get the same result. Now you can, as normal with derivative-on-error, use a positive Kd gain as usual.
@abdelhassibdad3413
@abdelhassibdad3413 4 жыл бұрын
Thanks for sharing i have a question how can we get tau and how we chose sampling time ?
@gerhardwiesinger
@gerhardwiesinger 4 жыл бұрын
Kd should always be positive, so please change it in git repo (and test code again). To avoid the confusion you could always use error to setpoint.But with a flag set the setpoint always to 0 but only for the derivative component. (hope the intention is clear). So one can choose if "kick in" is wanted or not. BTW: What's the practical impact of the kick in on the output response?
@PhilsLab
@PhilsLab 4 жыл бұрын
@@gerhardwiesinger Thanks, I've included the minus sign. Code has been checked and works as expected.
@gabiold
@gabiold 4 жыл бұрын
@@gerhardwiesinger You might make another derivative term for the setpoint, with a separate Kd(set), and this way you could control how to respond to setpoint change and how to measurement change.
@EinzigfreierName
@EinzigfreierName 4 жыл бұрын
Very good video and one of the best I saw on implementing PID so far. But I don't fully understand how the derivative of the measurement and the derivative of the error can give the same result. This seems to work only if you imply the setpoint is not changing between two measurements, right? I mean, if the setpoint is increasing at the same speed as the measurement, the error is constant and derivative of the error is 0. But the derivative of the measurement would be non-zero in this case. Or am I missing something.
@patrickhochleitner7754
@patrickhochleitner7754 4 жыл бұрын
This is the first time I find a direct C application from a theoretical control explanation. I've been searching for this for some time on my university's library and no luck at all. Thank you so much for this, you got a fan right here.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you! Yeah, I had the same problem, as it was quite hard to find complete and documented code online (and in books) that also covers practical issues in implementation - so very glad to hear this has helped.
@jasonbotzas4528
@jasonbotzas4528 Жыл бұрын
I’ve learned this in school only from a theoretical standpoint that glosses over the very important details of “how do we ACTUALLY make this work”. Thank you for increasing my knowledge!
@bastianacevedobustos3156
@bastianacevedobustos3156 4 жыл бұрын
This channel is slowly becoming one of my favorites, thank you so much!!
@PhilsLab
@PhilsLab 4 жыл бұрын
I'm very happy to hear that - thank you!
@kersgames6382
@kersgames6382 Жыл бұрын
You saved my day man! I finally understand how to implement basically any continuous time controller onto a arduino or something like that. One can have ALL the understanding of the theory, but if you cannot apply it, you are basically worth nothing for a company. Thank you so much!
@leecaraway706
@leecaraway706 4 жыл бұрын
Very well done! You are an excellent teacher. Concise and to the point, good flow with no fumbles. That is hard to do. I have been doing this for over 45 years and you are in the top five for good teachers.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you, Lee. That's very kind of you to say, very happy to hear that!
@bluehornet6752
@bluehornet6752 4 жыл бұрын
Brilliant video! I've forgotten some (most?) of my differential equations concepts, but you gave a very nice review--and I love your PID algorithm. The flight sim was most impressive as well. Thanks for making this video!
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you, Tom! Very glad to hear that - hope you can use the algorithm in one of your projects! :)
@martinestorninhoblocher1010
@martinestorninhoblocher1010 2 жыл бұрын
Hey Phil, Great video. Information is not to extent but the fundamental concepts are there, plus you actually give an example of a real world application, which at the end of the day is what really matters. Thank you.
@shaungovender7805
@shaungovender7805 2 жыл бұрын
As a fellow lover of microcontrollers and Signal Processing I absolutely love the content on this channel... I have to say that Phil does a great job of getting through the rather advanced mathematics and focuses on only the essentials. Great work.
@PhilsLab
@PhilsLab 2 жыл бұрын
Thank you very much, Shaun!
@georgetroulis
@georgetroulis 4 жыл бұрын
About time a video like this exists. I'm taking control systems right now as an undergrad and I've been waiting to use that theory in practice. Your videos have been perfect for that transition. Perfectly timed :)
@PhilsLab
@PhilsLab 4 жыл бұрын
Awesome, very glad to hear that - hope you can put the code here to use! :)
@DownTownDowns
@DownTownDowns 3 жыл бұрын
By far one of the best KZbinrs at explaining both hardware and software. Clearly very knowledgeable, I am currently consuming your content as fast as possible
@PhilsLab
@PhilsLab 3 жыл бұрын
Thank you very much for your kind comment! Definitely more videos to come as well :)
@hvinstrumentsandparts1907
@hvinstrumentsandparts1907 2 жыл бұрын
Nice Work, one of the best PID explanations because its not in Matlab or Simulink. You actually see the anti-windup code
@davebenemerito310
@davebenemerito310 4 жыл бұрын
Probably my new favorite channel! Thanks for this videos man!
@PhilsLab
@PhilsLab 4 жыл бұрын
Awesome - thank you!
@romualdyap4708
@romualdyap4708 2 жыл бұрын
Thank you for the really well explained tutorial especially the implementation in the code. I was searching for something like this. This is exactly what I was looking for! Many thanks on your really awesome video!
@NilsKullberg
@NilsKullberg 4 жыл бұрын
What a nice video! - Informative and straight to the point. No frills. Just results. Big thanks!
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you, very glad you liked it!
@ObsidianJunkie
@ObsidianJunkie 4 жыл бұрын
Just finished my ECE undergrad last month. Practical implementations of control systems in digital hardware is something that I never learned and wished was part of my curriculum. Excellent, thanks.
@PhilsLab
@PhilsLab 4 жыл бұрын
Very glad to hear you found it helpful. Same for me when I was at university, lots of theory but effectively no mention of how to use it in practice.
@pkilo2811
@pkilo2811 4 жыл бұрын
I agree with you perfectly. Most of the lecturers just teach what they read in a book and not implementers. As the author of AoE, Horowitz, said "Most Engineers of this age are rather applied Mathematicians always hiding behind equations"
@sergeyzolotykh9872
@sergeyzolotykh9872 5 ай бұрын
It is by far the best video about PID, specially about practical implementation of the controller.
@coorfang426
@coorfang426 4 жыл бұрын
I've learned this PID knowledge in the university ~ 6 years ago. But it was definitely not as clear as your illustration and demonstration. Bravo.
@PhilsLab
@PhilsLab 4 жыл бұрын
Very happy to hear that, thank you very much!
@theman3282
@theman3282 4 жыл бұрын
same, i got c+ on control and system..
@osahonojo1897
@osahonojo1897 2 жыл бұрын
Thank you for this video! The explanation and example code were exactly what I was looking for.
@GiancarloAllasia
@GiancarloAllasia 4 жыл бұрын
I'm a mechatronics engineering student, I've covered a lot of theory about advanced control stategies, but we always skipped PID control and, most of all, its implementation in code. This video is fantastic, you have a very good skill in explaining clearly concepts and this is exactly what I was looking for to have a more practical grasp about such theoretical concepts. Well done!
@PhilsLab
@PhilsLab 4 жыл бұрын
Really glad to hear that, thank you!
@chuxu1647
@chuxu1647 4 жыл бұрын
Very impressed! The best I ever saw, clearly explained it in less than 20 minutes!
@PhilsLab
@PhilsLab 4 жыл бұрын
That's very kind of you to say - thank you!
@TonySingh7
@TonySingh7 4 жыл бұрын
Absolutely brilliant video! Many thanks for making this and showing the unity simulation as well, that was a new thing to see.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you very much! My pleasure, I'm glad you liked it!
@tornadoflore
@tornadoflore 4 жыл бұрын
Excellent video. Exactly what I was searching for.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you!
@bouipozz
@bouipozz 2 ай бұрын
Great video thanks! Helped enormously with my 3rd year project. Nice to see the theory and practical being connected as this is often neglected and causes much difficulty
@Adrixcorp
@Adrixcorp 4 жыл бұрын
really useful man, you took me back in time to review system control concepts
@PhilsLab
@PhilsLab 4 жыл бұрын
Very glad to hear that, thank you!
@kylemilner
@kylemilner 4 жыл бұрын
Fantastic video Phil! Suggestion: Increase font size so we can see your code a bit easier. Keep the great content coming!
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you, Kyle! That's a very good suggestion, I'll keep that in mind for future videos.
@akaHarvesteR
@akaHarvesteR 4 жыл бұрын
Immediately subbed. This is probably one of the best videos on PID control out there, and AFAIK, the only one that does a good job of explaining how to implement one in real life, where computation is discrete and numerical noise is inescapable. Loved the idea of dt-on-measurement. Had never seen that before, and now I wish I had thought of that.... time to update my PID code!
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you man, really glad to hear that. Yeah, I wish more people would actually show how to implement things in real-life, far too much time spent on theoretical learnings that don't translate 1-to-1.
@akaHarvesteR
@akaHarvesteR 4 жыл бұрын
@@PhilsLab Very true. Oh, and I implemented a new PID controller based on yours just now, and it's a significant improvement over my old one! Many thanks! One thing I was still curious about, if I could ask for an elaboration, was on how you worked out the resulting expressions, especially for D. You mentioned using a bilinear transformation to transform values to discrete space, but your expressions have the transformation already folded in with the integration and diff. That was the one part where I had to just take your word for it, because algebra is really not my thing. In any case, most excellent video! Thanks again!
@alexbenitic
@alexbenitic 4 жыл бұрын
You are the best Philip, this is by far the best PID video I've ever seen. Please make more such videos. Thanks a lot .!
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you very much! Yes, got a larger control theory one lined up - going from theory through to practical implementation.
@michaelwirtzfeld7847
@michaelwirtzfeld7847 3 жыл бұрын
Clear and concise. Love the use of engineering paper!
@PhilsLab
@PhilsLab 3 жыл бұрын
Thank you, Michael!
@felipegutierrez7856
@felipegutierrez7856 4 жыл бұрын
Very good explanation. I would add that the tracking error states the direction that the gain of the PID control will take. If the error is positive the gain will be positive, and vice versa.
@zyghom
@zyghom 2 жыл бұрын
UNBELIEVABLE GOOD! thx mate
@thuctranminh2170
@thuctranminh2170 4 жыл бұрын
I'm really grateful for this video Phil!. It help me a lot. Thank you!!
@PhilsLab
@PhilsLab 4 жыл бұрын
Really glad to hear that, thank you!
@Gengh13
@Gengh13 4 жыл бұрын
Thanks for the video, it's well organized and really easy to follow, you are a great teacher. Subscribed.
@PhilsLab
@PhilsLab 4 жыл бұрын
That's great to hear - thank you!
@avejst
@avejst 2 жыл бұрын
Great walkthrough of the problems with PID's Great walkthrough of the implementation in C Thanks for sharing :-)
@nanajerry824
@nanajerry824 2 жыл бұрын
DR RORPOPOR HERBAL on KZbin changed my entire life with his herbal medicine. I appreciate you sir, for taken away my PID 🌿🌿🌿🌿
@ecarvalho17
@ecarvalho17 4 жыл бұрын
A video about tunning those parameters would be cool either. Nice content!
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you! Yes, will be doing an extensive video on that in an upcoming video series on controller design!
@ravimannanikkad884
@ravimannanikkad884 4 жыл бұрын
First Time I am commenting on a video because you blew away me with your explanation/implementation skills. Thank you so much for the explanation
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you very much, Ravi!
@alexeyveseliev106
@alexeyveseliev106 4 жыл бұрын
Especial thanks for the filter in derivative channel!
@PhilsLab
@PhilsLab 4 жыл бұрын
My pleasure, thank you!
@kubsztal
@kubsztal 4 жыл бұрын
This is pure gold, subscribed :)
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you!
@mrechbreger
@mrechbreger 3 жыл бұрын
Thank you for explaining that topic!
@PawlTV
@PawlTV 3 жыл бұрын
Awesome tutorial! Everything I needed! :)
@PhilsLab
@PhilsLab 3 жыл бұрын
Thanks for watching, Paul!
@CarlosDelcristo
@CarlosDelcristo 3 жыл бұрын
Great video, thank you very much for sharing... looking forward to the next one
@PhilsLab
@PhilsLab 3 жыл бұрын
Thank you, Carlos - more videos to come soon!
@ayoublasbate
@ayoublasbate 3 жыл бұрын
You did an amazing Job...Thank you sooo much...it really helped me out with my project about underwater drone!! Hope we'll see more content from you...peaaace!!!
@PhilsLab
@PhilsLab 3 жыл бұрын
Awesome, thank you - very glad to hear that!
@doco6186
@doco6186 4 жыл бұрын
Very informative and well presented
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you!
@thinkingthing4851
@thinkingthing4851 5 ай бұрын
Thank you!!!!!🎉 Needed this
@superflanker07
@superflanker07 4 жыл бұрын
just a great explanation! Thanks for share these videos!
@PhilsLab
@PhilsLab 4 жыл бұрын
My pleasure, thank you for watching!
@quahntasy
@quahntasy 4 жыл бұрын
*Thanks for such a great explanation and that too on my birthday*
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you - happy birthday!
@bonafontciel
@bonafontciel 22 күн бұрын
that's cool. I made one 2 years ago in C for a coolling system(control Fan via PWM) sold by a famous PC part vendor.
@thorntontarr2894
@thorntontarr2894 2 жыл бұрын
Phil, an amazing morning watch and followup; excellent use of references to read. I am invested in Arduino IDE now on VSC & PlatformIO so making your code compile directly may be a task but not impossible. So, just what hill am I climbing to get VSC & PlatformIO to be happy. However steep and tall that hill is, what you have theoretically discussed and digitally implemented is understood quite well thanks to your presentation style and knowledge. I will checkout the 6 part video series to learn more.
@nanajerry824
@nanajerry824 2 жыл бұрын
DR RORPOPOR HERBAL on KZbin changed my entire life with his herbal medicine. I appreciate you sir, for taken away my PID 🌿🌿🌿🌿
@kunalsalvi8382
@kunalsalvi8382 4 жыл бұрын
Another great video. Cheers, mate !!!!!
@PhilsLab
@PhilsLab 4 жыл бұрын
My pleasure, thank you!
@jasonkocher3513
@jasonkocher3513 Жыл бұрын
Well done!!
@kenwallace6493
@kenwallace6493 4 жыл бұрын
Well done and very applicable to digital power conversion. Modeling PID systems in a simulator like LTspice would be very useful.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you, Ken! I'll see if I can make a video on (PID) control in circuit simulators.
@SuburbanDon
@SuburbanDon 5 ай бұрын
This is great Thanks ! You've made life a bit easier for many of us semi-boneheads.
@PhilsLab
@PhilsLab 5 ай бұрын
Thanks, Don!
@aashishranjan8951
@aashishranjan8951 3 жыл бұрын
awesome explanation
@emregozkaya2630
@emregozkaya2630 4 жыл бұрын
Thank you, nice presentation, good job 👍
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you!
@schultzbach5287
@schultzbach5287 4 жыл бұрын
Wow this is really awesome! Thank you!!
@PhilsLab
@PhilsLab 4 жыл бұрын
My pleasure, thank you!
@Giblet535
@Giblet535 4 жыл бұрын
Friday evening, and an implementation of PID controllers. Perfect! I wish mathematicians wrote out their formulas in C. Translating from meat puppet is tedious.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you! Yeah, I wish more control theory books would have more snippets of actual code..
@steefant
@steefant 4 жыл бұрын
@@PhilsLab when looking at actual code written by control theorists i am not so sure that would be a good thing... ;)
@DeejayGrafixx
@DeejayGrafixx 4 жыл бұрын
just stumbled upon this today subed and liked before watching
@PhilsLab
@PhilsLab 4 жыл бұрын
Haha that's great, thank you!
@AdoobII25
@AdoobII25 4 жыл бұрын
you are the best! I really love your channel!
@PhilsLab
@PhilsLab 3 жыл бұрын
Thank you, Mohammed!
@diggleboy
@diggleboy 4 жыл бұрын
This lecture takes me back to classical control systems and their design. Great presentation with the math and examples. Very important when it comes to controls systems in vehicles of all kinds, especially high speed, high performance and high agility systems: Fighter aircraft, Formula 1 race cars, guided rocket systems and so much more.
@PhilsLab
@PhilsLab 3 жыл бұрын
Thank you! Yeah, control systems are absolutely everywhere. Incredibly important in almost all areas of engineering.
@vencibushy
@vencibushy 3 жыл бұрын
This is a very nice information. I believe that the design can be further improved with a better anti-windup mechanism. Integrator clamping is a rather crude way to prevent the saturation of the control signal. A much better and elegant solution is the back-calculation algorithm which dynamically modifies the integrator. It's a simple yet very efficient solution. You need to impose a software saturation borders of your controller's output. Then you calculate the difference across this saturation. The resulting signal is now a second error in the system which is fed back via a negative feedback loop to the integrator's input. The signal can be further amplified(or attenuated) with it's own coefficient. For example - a microcontroller can be an effective linear controller when the output is PWM. If we assume a control signal implemented over 10-bit PWM the software saturation is 0 to 1023.
@BrianTCarcich
@BrianTCarcich 3 жыл бұрын
[update: whoops, this may already be implemented in the updated anti-wind-up] /* or, more simply: */ p = ...; i = ...; d = ...; /* P, I, D terms */ out = p + i + d; /* sum to output */ out = (out>limMax) ? limMax : ((out
@darkstar2111
@darkstar2111 4 жыл бұрын
14:48 - As the guy who reviews the other people code for living I do really appreciate making the code easier to read rather than super fancy, short and 'sophisticated'. Especially in C# or JavaScript where you have at least 40 ways to achieve same thing and new syntactic sugars every two years.
@PhilsLab
@PhilsLab 4 жыл бұрын
I'm glad to hear that! Although not primarily a software guy myself, I try my best to make my code as easy-to-read as possible. I've been meaning to read 'Clean Code' for a while but still hasn't happened yet - one day...
@tttuberc
@tttuberc Жыл бұрын
Great video and easy to understand. Also I'm so glad to have found your channel which has lots of great contents.
@ruythermaximo4169
@ruythermaximo4169 3 жыл бұрын
Amazing video!
@PhilsLab
@PhilsLab 3 жыл бұрын
Thank you very much!
@10e999
@10e999 4 жыл бұрын
Great video. I'd like to see a software-focused follow up from your "Flight Control System Design: Hardware" video.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you! Yes, I'll be doing a video series on control system design, which includes software implementation, and also hope to make a video on the extended Kalman filter which runs on the FCS.
@nuwana2208
@nuwana2208 4 жыл бұрын
Excellent video.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you!
@baskarv7975
@baskarv7975 Жыл бұрын
Dear Friend , I have no words to Thank You ,, I watched lot of Videos to Understand the PID but its really very hard to understand ,, Your video really makes me to understand the PID Very Clean and Nice Explanation Thanks a lottt ..... Very Very Helpful .. God bless you my dear friend. all other your videos are very very nice :) :)
@PhilsLab
@PhilsLab Жыл бұрын
Thank you, Baskar!
@NicozStrat
@NicozStrat 3 жыл бұрын
OMG this channel is so much interesting
@PhilsLab
@PhilsLab 3 жыл бұрын
Thank you!
@diocorissosa4448
@diocorissosa4448 3 жыл бұрын
Thank you for sharing. I do have a question. In the code, I see that actually coded the tick time "Tau". I've read in a microcontroller forum that Tau is not needed to be coded because it is taken care of every time the new sensor value is obtained in a tick fashion. It is confusing, since I see some code include the time variable and some code don't. Can you please explain?
@benjaminpaik
@benjaminpaik 2 жыл бұрын
It might be worth considering adding a separate variable to integrate the errors before multiplying the integral gain. The float (essentially being scientific notation in base 2) will stop integrating if the value you are adding (0.5 * Ki * (error + prevError)) drops below the LSB of the fractional portion of the float for a given exponent of the integrator. In other words, you can introduce a steady-state error that won't be resolved for sufficiently small errors. The effect is exacerbated for low values of Ki and T.
@nanajerry824
@nanajerry824 2 жыл бұрын
DR RORPOPOR HERBAL on KZbin changed my entire life with his herbal medicine. I appreciate you sir, for taken away my PID 🌿🌿🌿🌿
@lucasbertolossi1598
@lucasbertolossi1598 2 жыл бұрын
Hey Phil. Thank you for the video! I just have a question, isn't the term 1/(2tau +T) missing on the first derivative term? I know the minus sign has been fixed, but i think this is another mistake, or am I missing something? I implemented a PID controller without that term, and it worked after I tweaked the parameters, but just in case...
@ahsdjasashdahs9940
@ahsdjasashdahs9940 Жыл бұрын
Thank you very much mate this is a life saver !
@PhilsLab
@PhilsLab Жыл бұрын
Glad to hear that - thanks for watching!
@Orion2223dz
@Orion2223dz 4 жыл бұрын
It's really amazing
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you!
@jugnu361
@jugnu361 3 жыл бұрын
VERY HELPFUL...................THANK YOU !!
@PhilsLab
@PhilsLab 3 жыл бұрын
Awesome, thank you!
@StMartin81
@StMartin81 6 ай бұрын
Great video! What I would be interested in is how to derive the derivative part of the controller with the integrated low-pass filter. It looks like this is a very common problem but I haven't found a good video which describes the transformation of the transfer funtion from the laplace domain to the actual implementation in the discrete time domain.
@eduardoc1252
@eduardoc1252 5 ай бұрын
Great video Phil! What is the alpha in TestSystem_Update function used to calculate the output?
@HelmutTschemernjak
@HelmutTschemernjak 4 жыл бұрын
Interesting topic, I did’t know about a PID controller until now. From a programming topic, I would create this PID controller in C++ which encapsulates it more like a re-useable PID block. For the float data types I would may use a template type to be flexible for different use cases with uint8_t, uint16_t, etc. as some MCU’s don’t offer float support and the software float simulation eats a lot flash memory. Great video, thanks.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you, Helmut. I like your ideas! Yes, C++ would offer a nicer way to make a class out of the PID controller. I tend to go with C these days, as I'm mainly programming for STM32s and C - to me - is just much better integrated than C++. And yeah, MCUs without a floating point unit will have a bit more work to do running this code. Then again, most PID scenarios will commonly only run at a few hundred Hz or kHz, and the update routine is not particularly math-heavy so I've been able to run this on things like Arduino Nanos. Even though these days all I work on is STM32s with floating point units haha. Thanks again for your comment!
@HelmutTschemernjak
@HelmutTschemernjak 4 жыл бұрын
​@@PhilsLab today MCUs have sufficient flash and memory resources that C++ works great with them. I work with STM32L0, L4, D21 and ESP32, the entire code written in C++. At present for embedded projects with Mbed-os and Arduino OS. Simple data structures like a dynamic list of objects, a hash map etc. all this is available in C++ with good documentation without re-inventing algorithm in C where basic little support is given by the C library, with C++ all this is included. I started some time ago with Silicon Labs MCUs doing basic low level stuff like an async serial. When I moved to STM, all this was different and it was needed to start over again for basic stuff like a async serial or a simple timers. Basically wasting my engineering efforts without being able to bring my work to a new platform like Atmet D21. With Mbed-os all this is much better because Mbed OS has identical C++ APIs for all major ARM based MCUs, there are about 150 development boards available from different vendors all Mbed-os compatible. For ArduinoI wrote on top of Arduino Mbed-OS compatible IO and timer libraries. This means for larger projects my C++ code is 98% identically for different MCUs even across OS’s like Mbed and Arduino. For a software engineer re-purposing code boosts productivity brings more stable and maintainable code. Focusing on the solution and being flexible to support entirely new MCU vendors is something where clean C++ Code blocks can help. Regards from Hannover, Germany. Helmut
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 4 жыл бұрын
Hi Phil, maybe a follow up on tuning the PID, how to get to the set point in the quickest time but limiting over and undershoot. tuning and stability are often just off as I think they are harder than getting the loop running. great video and I will be looking at this for my next soldering iron software update.
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you! I've actually got a video planned going from mathematical modelling, to controller design, to simulation, and finally through to real-world implementation. As you say, showing how to actually tune a control system and how theory compares with practice.
@gean7917
@gean7917 8 ай бұрын
Nice!
@interestingengineering291
@interestingengineering291 3 жыл бұрын
Thanks for making this nightmare to become interesting for me
@PhilsLab
@PhilsLab 3 жыл бұрын
Haha glad it got better!
@davoodseify3624
@davoodseify3624 4 жыл бұрын
very informative thank you so much
@PhilsLab
@PhilsLab 4 жыл бұрын
My pleasure, thank you!
@pbs570
@pbs570 8 ай бұрын
Thanks a lot.
@smoua4588
@smoua4588 Жыл бұрын
Thank you!
@brunogbitencourt
@brunogbitencourt 3 жыл бұрын
Excelent!
@klave8511
@klave8511 4 жыл бұрын
One important attribute for controlling mechanical actuators is to avoid constant tiny adjustments. If the measurement is noisy and that translates to continuously changing an actuator, the increased wear from the jitter type adjustments leads to premature failure. This can be mitigated right at the controlled device by, for example, using a slotted coupling so that there is a bit of hysteresis. It should really be part of the control system, be it PID or any other.
@PhilsLab
@PhilsLab 4 жыл бұрын
Yes, that's a great point and something I only broadly hinted at with the 'derivative amplifies HF noise' part, but should have explicitly mentioned that this over-actuation due to noise in a control system will cause actuator wear.
@miladchalipa2002
@miladchalipa2002 3 жыл бұрын
Thanks for the useful Video, I decided to implement your PID algorithm to Temperature control of 1000 degrees furnace and wondering how to determine TAU and sample time. Note that my microcontroller will generate 2 seconds PWM (slow PWM) and I will control the temperature through Duty Cycle. regards
@smith1401
@smith1401 4 жыл бұрын
Very detailed and clear explanation! Great video 👍 One thing though. Maybe you can increase the font size or the zoom level in you IDE for other videos for those of us watching on mobile phone screens :)
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you! Yes, I unfortunately forgot about people watching this on phone screens - will definitely make the font size larger in upcoming videos. Sorry about that!
@smith1401
@smith1401 4 жыл бұрын
Phil S no worries! You have really great content (I would also watch it if the font stays tiny) :D
@KJ7NLL
@KJ7NLL 3 жыл бұрын
Thank you, I am going to use this for my antenna rotor controller that has phi and theta to track satellites. Me and my dad are currently trying to contact the International Space Station using the rotor controller!
@PhilsLab
@PhilsLab 3 жыл бұрын
Awesome, hope your antenna tracker works out!
@KJ7NLL
@KJ7NLL Жыл бұрын
@@PhilsLab The antenna tracker works, here it is! kzbin.info/www/bejne/rKPPqGeHhbCAiLs
@nightrook5732
@nightrook5732 4 жыл бұрын
Our college is all about theory and no shit given about practical side. I always wanted to know the implementation. Thanks for sharing this!!!!
@PhilsLab
@PhilsLab 4 жыл бұрын
Was the same for me at uni.. :( Glad you found the video helpful!
@David_94
@David_94 4 жыл бұрын
Nice video, the next one could be something like "PID Controller Implementation on microcontroller" explaining the interruptions
@PhilsLab
@PhilsLab 4 жыл бұрын
Thanks, David - yes, in the latest video series (Control System Design) I show an actual implementation on a microcontroller.
@mfercan
@mfercan 4 жыл бұрын
Excellent 🙏
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you!
@nafisahmed6247
@nafisahmed6247 5 ай бұрын
a brief explanation of the choice of tau and T would be very much appreciated.
@usmanhaider4653
@usmanhaider4653 Жыл бұрын
Great work thanks. Question. What is difference between tau and sampling Time?
@WetTheSystem
@WetTheSystem 2 жыл бұрын
Where would you suggest putting functionality for limiting the change limit of the output (i.e. no more than 1% per period) without causing max wind-up in the integrator?
@icnmamun
@icnmamun Жыл бұрын
Hi Phil it is a very helpful tutorial. Wondering how would you select the tau. thanks
@anandpatel986
@anandpatel986 3 жыл бұрын
Is there any guidance of the integrator limits in relation to the output limits ? I want to use this in a motor control application, where my rotation sensors report between 0-200, and can control rpm of motor between 0-100. Btw, this channel is awesome. I've built a number of PCBs based on the guidance you've provided - all worked first time :)
@samibahlous979
@samibahlous979 9 ай бұрын
Nice work ! I just want to ask you how can we determine the value of Tau that we will use it in the filter part . Thank you .
@RaoulRacingRC
@RaoulRacingRC 4 жыл бұрын
Nice video! Could you also explain how a PID controller works for positioning a DC-motor with an encoder for example? Would love to see how to implement such a PID controller in C
@PhilsLab
@PhilsLab 4 жыл бұрын
Thanks! In an upcoming series I'll go more into detail on how to tune/design a control system. Not quite a DC-motor example, but definitely very applicable to that as well. Hope that will help!
@chenhaoting235
@chenhaoting235 Жыл бұрын
thanks for your detailed tutal. Two question, in your github code: pid->differentiator = -(2.0f * pid->Kd * (measurement - pid->prevMeasurement) /* Note: derivative on measurement, therefore minus sign in front of equation! */ + (2.0f * pid->tau - pid->T) * pid->differentiator) / (2.0f * pid->tau + pid->T); 1.Kd use positive value? 2. why not caculate differentiator part int the way below? pid->differentiator = -(2.0f * pid->Kd * (measurement - pid->prevMeasurement) /* Note: derivative on measurement, therefore minus sign in front of equation! */ - (2.0f * pid->tau - pid->T) * pid->differentiator) / (2.0f * pid->tau + pid->T); thanks very much.
@rjgonzalez8108
@rjgonzalez8108 4 жыл бұрын
Great content! What textbooks have you found helpful in understanding control theory? Preferably, optimal control and it's practical considerations?
@PhilsLab
@PhilsLab 4 жыл бұрын
Thank you! In general, I personally really like 'Modern Control Systems' by Dorf and Bishop. Covers everything from basic to intermediate control theory with many examples along the way. If you're only after something on digital control systems, I'd recommend 'Digital Control of Dynamic Systems' by Franklin. Regarding optimal control, I must say I haven't come across particularly 'practical' textbooks. If you've heard of H-Infinity control, that is something I used for my final year project at university (self-balancing bicycle): philsal.co.uk/wp-content/uploads/2019/08/FinalReport.pdf
@rjgonzalez8108
@rjgonzalez8108 4 жыл бұрын
@@PhilsLab thanks!
@SrikanthChilivery
@SrikanthChilivery 3 жыл бұрын
Thank you very much. I am planning to use your algorithm for industrial control (add few features). Being control engineer I really don't understand Control Modelling. Can u share reference study material you suggest for understanding and design of PID controller?
What is a PID Controller? | DigiKey
22:19
DigiKey
Рет қаралды 64 М.
FIR Filter Design and Software Implementation - Phil's Lab #17
30:35
Luck Decides My Future Again 🍀🍀🍀 #katebrush #shorts
00:19
Kate Brush
Рет қаралды 7 МЛН
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 66 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 23 МЛН
computers suck at division (a painful discovery)
5:09
Low Level Learning
Рет қаралды 1,6 МЛН
PID Math Demystified
14:38
Scott Hayes
Рет қаралды 459 М.
Making Simple Windows Driver in C
7:26
Nir Lichtman
Рет қаралды 326 М.
A real control system - how to start designing
26:58
Brian Douglas
Рет қаралды 261 М.
PID vs. Other Control Methods: What's the Best Choice
10:33
RealPars
Рет қаралды 109 М.
EEVacademy #6 - PID Controllers Explained
27:11
EEVblog
Рет қаралды 204 М.
Electronic Basics #34: Two-Position Controller & PID Controller
8:10
Controlling Self Driving Cars
4:41
AerospaceControlsLab
Рет қаралды 496 М.
Hardware Demo of a Digital PID Controller
2:58
Gregory L. Holst
Рет қаралды 975 М.
PID Balance+Ball | full explanation & tuning
13:13
Electronoobs
Рет қаралды 729 М.
Samsung S24 Ultra professional shooting kit #shorts
0:12
Photographer Army
Рет қаралды 30 МЛН
Игровой Комп с Авито за 4500р
1:00
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 205 М.
сюрприз
1:00
Capex0
Рет қаралды 1,7 МЛН
💅🏻Айфон vs Андроид🤮
0:20
Бутылочка
Рет қаралды 714 М.
Iphone or nokia
0:15
rishton vines😇
Рет қаралды 1,9 МЛН