I am a control and automation engineer, who just finished a master in mechatronics. I am a true passionate to control engineering, and since 2013 when I was first introduced to control systems,i have NEVER EVER seen such a good simple explanation to a PID, specially regarding the derivative part. Actually, I only could reason about it by thinking about poles or spectral analysis. But your simple yet extremely clever explanation and demonstration gave me a new light on this subject and gave me a more 'physical' feeling about it, which IMO is essential to an engineeer. I also want to build a drone from scratch a a hobby, and your YMFC serie is simply tailormade to my needs. I am infinetely grateful for your contribution, and hope you keep posting such good videos and projects. Keep on the AWESOME work, you are an inspiration !!! Best regards !!
Having never flown a quad or any other RC model before I have watched these videos over and over again then took the plunge. I purchased some secondhand 2830 motors from ebay, made up a 450(ish) frame from upvc pipe fitted it with 30A esc's one of which was Faulty ! I used a "Beestore" pro mini which is fitted with an AMS1117 voltage regulator supporting up to 800mA for the controler. I loaded and ran the setup and calibration sketches and all worked fine. This evening I loaded the controller sketch and she flew straight out of the box even with an "odd esc". My activity's were cut Short by the weather but with a bit of tinkering (and four matching esc's) I'm going to have hours of fun. Thanks Joop for all your hard work and the many hours you have put into these videos, your explanations and demonstrations of how it all works are second to none. I just wish I were better at the coding side but I fear age is not on my side. LoL
Hands down, the best PID explanation I've seen so far, and being a quad/fpv pilot, I've seen many, . Joop, you're an ace, thanks for taking the time to do this. It's on the shoulders of "giants" like you that we build. Keep up the excellent work.
I was lookign for someone who could teach every bit of coding that was necessary for building the drone . And I am very happy with the content you have posted. Thank you so much.
Hi, I am a CNC hobbyist. I am absolutely a novice to Audrino. Your video series is an inspiration for me to explore the audrino world. I have already place an order for UNO after seeing your video. I may not understand everything right away. But your explanation breaks down everything and logical to understand. Thank you so much for putting together this wonderful video series. I am excited as hell to start with this Quadcopter project. Thank you, Nave
Hello, thanks a lot for this much needed video series! Just want to point out a slight error in one of the equations at 3:36. It should be, D-output = (gyro - receiver - gyroprev + receiverprev)*Dgain and not, D-output = (gyro - receiver - gyroprev - receiverprev)*Dgain
Karnik Ram Hi, gyro - receiver is the error and represents the 'e' in the equation at 1:51. The error is always calculated the same. In your line the previous error is calculated different than the actual error.
Your explanation and test models are awesome. The best explanation of what P & I & D actually are as demonstrated with physical models. Keep up the good work
thank you. I just wanted to thank you for the enormous professional work you have done. My drone flies wonderfully thanks to you. I congratulate you immensely.
This is an amazing series! I started to create my own drone, with some knowledge which I never use before. This series helps to the whole knowledge in context and make my understanding deeper.
Thank you for the build tutorial, after a couple months this semester research project for me just flew a few minutes ago, after some pid tuning frustrations!!!
I've been watching with interest. Thank you so much, for a well annotated sketch, as I will be doing this project with my son and it is a great help, to see each line described so well. When I saw your excel spreadsheet for PID, I decided to duplicate it, so I could play with the values myself. What I found very interesting, was to calculate and graph the PID Output, as well. I found this very useful, to show how changing the gains from 'neutral' (all = 1), to your actual flight values, dramatically changes the PID Output, from something that is dominated by I, to a shape that looks much more like D, with a trendline influenced by I. I also found that the graphing the effects of over and under tuning each value in turn, allows you to see how that behavior exhibits itself in the reaction. There were a few 'aha' moments, as I began to visualize how a large change in value for a certain gain, changes the response profile. Combining this with the airframe behavior (from watching your's and other's tuning videos) is pretty powerful. You might consider a supplemental video, exploring this in more detail.
I'm really out of compliments this time because every compliment is less worthy than your work. Brilliant work I've ever seen. Thank you so much. Your videos helps me a lot in my final year project of electrical and control engineering. bundle of thanks and salutes for you. regards.
Excellent tutorial, and the best explanation what (the hell*) is PID or PI on my KK2 board (there is no derivative, or D setting). At first it looks incredible complicated, but in your series of videos - if explainded as you just did - now it look much more clear and easy to understand. Thank you very much.
I'm confused why you've used gyro deg/s as your set point. Surely it would make sense to use the actual deg value otherwise the quadcopter could stabilise its gyro angle rates without actually being level itself?
Yes, these angel mode flight controllers perform better but I guess the reason of using a rate mode flight controller is that the calculations are simpler. So the required time for one cycle is low. Note The flight controller needs to run at least at 250 hz.
Please ,enable subtitle option in all your videos to make more people who aren’t fluent in English,understand what you talk about. Thanks for efforts. Follower from Egypt.
Hey Joop, superb video! I wanted to bring something to your attention about the Arduino servo library. In your videos you went to a great trouble in order to make the refresh rates of the Arduino faster for the ESCs, hence better PID control, but I found that with one single change to the Servo header file, you can have the Arduino servo library refreshing at the interval you want. You may do this by changing the #REFRESH_INTERVAL value. Simply copy the file to the desktop, change the value, and copy the file back to the servo folder. I am going to check this out with an oscilloscope tomorrow. Just wanted to let you know for less headache in the future :D
DUDE THANKS@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! AWESOME!!! I remember your 1st soundless videos, and my wish to hear your explanations! AND NOW YOU KEEP MaKING US ENJOYING YOUR VIDEOS!!!!!!!!!!!!!!
First of all, Great Video Tutorial Series Joop, Hats Off!!!!! What I noticed is, you have mounted the gyro underneath the right arm [During PID demo 5:24...], will correction be much more accurate if gyro has been mounted towards or at the center.
Thanks for the compliment! The gyro only detects angular motion. Perpendicular motion will not affect the gyro's output. The best location for mounting the gyro is away from vibrations. This usually means in the center of the frame.
I've watched this video many times now (which is great by the way), but there's one fundamental thing that I'm not understanding in regards to the rate mode. If the error is the difference between the gyro reading and the user's input (in deg/s), then when the quad starts rotating and approaches the desired rate won't the error decrease to 0, meaning there is no correction factor and just the throttle value is written to the motors? Perhaps I'm missing something?
+Joe Prince Yes, the error will decrease to zero. But the pid-controller will work on it to keep the desired rate. So my input is 20deg/s and the quad rotates 20deg/s. The error is zero and only the throttle will drive the motors. But when the quad rotates 19deg/s the error is 1deg/s and the motors are corrected. In practice the error is never zero. The controller is constantly correcting the multicopter. It goes so fast that it looks steady. But in fact the multicopter is very unstable.
+Joop Brokking I appreciate the insight and information. I have a question in regards to this line: "The error is zero and only the throttle will drive the motors." If the error is zero and only the throttle is driving the motors (let's say 50% throttle or 1500µs), then how is the quad rotating? Don't we need a difference in motor speeds in order to obtain rotation? That's kind of what my first question was referencing, the fact that if our error is zero then we're writing the same value to the motors (in this case the throttle) which in my mind means the quad is not rotating. Am I completely misinterpreting this?
Joe Prince As I wrote, in practice the error is never zero. And if it becomes zero during rotations the I-controller is 'loaded' and will make the quad rotate. But you are right about the fact that the multicopter does not rotate that well with all the 4 motors spinning at the same speed.
Only a p-controller will not work. You need at least p and d to make it fly. If you look @14:00 in the video you see that I fly the multicopter with only the p and d controller. It fly's but does not feel locked in. The i-controller makes the multicopter locked in.
as you may know that the maximum output is 400 pid? float pid_p_gain_yaw = 4.0; //Gain setting for the pitch P-controller. //4.0 float pid_i_gain_yaw = 0.02; //Gain setting for the pitch I-controller. //0.02 float pid_d_gain_yaw = 0.0; //Gain setting for the pitch D-controller. int pid_max_yaw = 400; //Maximum output of the PID-controller (+/-)
Thanks Joop, for this amazing video series. I have a question regarding the base throttle signal for quad-copter hovering. How do make sure that when throttle stick is in the middle, i.e. transmitting 1500us pulse the drone hovers?
Hi Joop, Thanks a lot for this video, you have made this very clear for me. Your explanation and major part of your code has allowed me to build my own UAV (Unmanned Aerial Vehicle), one problem i am facing is that the structure of my drone is a Hexacopter (runs with 6 motors). For a Quadcopter, the ESC equations are as follows: pulse_length_esc1 = instruction[THROTTLE] + roll_pid + pitch_pid - yaw_pid; pulse_length_esc2 = instruction[THROTTLE] - roll_pid + pitch_pid + yaw_pid; pulse_length_esc3 = instruction[THROTTLE] + roll_pid - pitch_pid + yaw_pid; pulse_length_esc4 = instruction[THROTTLE] - roll_pid - pitch_pid - yaw_pid; what will these equations be if i have 6 ESCs instead of 4, your assistance would be greatly appriciated
Hello Joop, your videos are great, I am wondering about one thing though. What do you need total angles from gyro+acc if you only use the gyro angular rate for your PID control? Is using angles and assumming the transmitter stick position inputs desired angle of the quad is a wrong approach?
Great Job excellent video! but there is some think i don't understands here you choose de maximum command to 164dps (setpoint) how do you know that's not too high and the drone isn't going to fall ? thanks in advance for your answer ^^
ok thanks but can we consider that the max 164dps command is like we ask the drone to have a 45° angle on the considered axe. Sorry to bother but i'm doing a drone for a study project only using a gyrocope as a capteur and i don't know how to explain how i choose this part of the code (164dps max setpoint) thanks in advance for your answer
The 164dps tells the drone that it must rotate 164dps. It's not a fixed angle. In this video I explain the auto level function and the angle calculation: ua-cam.com/video/DYpHB-LfloI/v-deo.html
yes i saw this video but you are using an accelerometre. the thing is i don't understand how to think with speed and not position. Because when you put de joystick to 2000 us (convert in 164dps in the code) if it's the roll you ask the drone to rotate at 164dps to the right, like that it goes to the right. But i don't understand if i keep the joystick to 2000us why the drone just goes to the right and don't rotate on the roll axe indefinitely ? ( i know what i say is stupid because the pid is correcting the thing but that's my problem )
The confusion is probably the difference between rate and auto level. The video that I linked is the auto level that uses an accelerometer and angles. When you release the sticks the quadcopter levels itself. If you use only a gyro the quadcopter is flying in rate mode. This means that when you release the sticks the quadcopter will keep it's current position. Then you move the stick full right the PID input is 164 degrees per second. The PID controller will change the motor speed until the gyro detects 164 degrees per second. And it will keep rotating at 164 dps as long as the stick is full right. Meaning that the quadcopter flips upside down proximately 2 times per second.
Joop, great video. I've noticed in some of your other videos that you have very good altitude hold. I was wondering what your process is for tuning the PIDs for altitude hold? Thanks.
@Joop Brokking , first of all: great content! this is very informative! The generic PID definition uses DeltaTime as a multiplier for the I and D terms, but you seem to not use it... Is this because your feedback variables are in º/s. ? In my case I´m trying to simply control the Pitch/yaw/roll (so plain º). Thanks.
Hi Joop! Amazing videos! So helpful! I have one problem though... I am trying to adapt your YMFC-AL code for autonomous flight, so no radio input! I have built a test stand like yours in this video to demonstrate the auto-level. I can't under stand how to adapt the setpoint for the PIDs to keep the quadcopter level in hover, as my PID input is angular motion, not angular position. When I try to implement my code on my test stand, the PID stabilizes the axis to the point where I push it, but doesn't auto-level! How do I covert the angular motion data to an angular position so I can auto level? Sorry if this doesn't make sense! Thanks
Hello Joop, been following for over a year. Very thankful for such an elaborate guide. My query is are we using position/angle data in the PID controller or is it just the angular speed as the set point. I mean are we controlling roll/pitch speed or the roll/tilt angle. Using speed as the set point my P control behaves a like a D control (just damps motion)
hello again joop. first of all i'd like to thank you for this amazing video series and your active responses. you have inspired me to build my own flight controller and i am almost done, but stuck at setting the pid. setting the d gain first, didn't work for me as i have a 360mm frame and being a novice it's difficult for me to obtain the point of vibrations. if i try to set the p gain first the quad starts to oscillate and overshoot at a low frequency with the amplitude becoming higher every time. i am guessing this could be a result of the pid_output_pitch =400 being high as my escs are 50hz as compared to your 250hz escs. so do u think the pid_output_pitch should be 400/80 in this case because of a lower refresh rate in order to prevent overshooting? thank you
Are you running a 50Hz refresh rate from your flight controller program? Most ESC's that are designed for multicopters will work fine with a 250Hz refresh rate. If you use ESC's designed for planes it will not work because they are to slow.
+Joop Brokking i am running a 50hz from the flight controller. as per my understanding many escs flashed with blheli or simpnl firmware run at 250hz. however many escs still work on 50hz. i'll have to buy new escs for 250hz ...but that wont be feasible for me now.
Hello sir , I'm tanmay and I'm a engineering student . I am working on the Arduino based drone with the help of your video . I facing many challange to setup best PID values . Sometimes those values works correctly then i take the flight of the drone but unfortunately drone flip on the specific height, like 9 feet . I have been facing this problem currently . Could you help me to solve this problem . When i press the reset button on the Arduino . drone gives the stable flite but suddenly drone flip into the sky and it stops working . From this problem i have losted one Arduino uno board . You are my last hope. What did i do to solve this problem . All parts are working properly buy unfortunately i don't know what's the problem . I have been trying to solve this problem for 3 months . I started to make the drone 3 months ago . But this problem didn't solve . I'm waiting for your reply . I am making this drone for my college project So please help me . I will appreciate your help . Please reply me sir . I will tell you my all problems in the drone . thank you , please reply me ❤️
Great video Sir Joop. please I wish to know ,Where is the receiver signal from ?? I'm currently working on a wind pendulum project and I hope to adopt your PID lesson to balance the pendulum at center within the shortest time given , the pendulum has 4dc fans attached to its 4sides .how can I apply your lesson? Thanks for your help in advance
Hey Joop, my quad is yawing violently when I use the pid-i as in your code -> pid_i_mem_pitch += pid_i_gain_pitch * pid_error_temp; The i - gain seems to happen even when the quad is stationary and there is no change in angle! But when I changed it to -> pid_i_mem_pitch = pid_i_gain_pitch * (pid_i_mem_pitch + pid_error_temp); It worked fine. Have I made an error elsewhere in the code which could have led to this? Thank you for the amazing videos! I have learnt so much from them.
Your videos are awesome! I myself built the YMFC-AL quadcopter and it works well. The only problem I am facing is that when I change the value of I, the quad tilt in one direction and I have to use subtrims to level it. It works perfectly fine with I=0;P=1.5 and D=15. Can you guide me how can I tune the value of I to make it more stable. Even at I= 0.01 , the quad tilt in one direction. Waiting for your reply.
The same thing happens to me ... always when starting starts to the side, and it is difficult to stabilize it, since the position to self-level will always be to one side
awesome project. but i have question. I would like to see the error value, PID values, as well as its PID chart. how do I get to see its. as in this video, at minute 4:50. thanks Joop Brokking.
thanks joop brokking. in the code your upload, where I use serial.print if I want to see the final value of the PID, time (us), receiver (dps), gyro (dps), the value of P, the I and D? because I want to see a graph of PID to determine its stability.
I see joop brokking. Thanks. How about. in the code your upload, where I use serial.print if I want to see the final value of the PID, time (us), receiver (dps), gyro (dps), the value of P, the I and D? because I want to see a graph of PID to determine its stability.
Hi Joop, I am doing a similar project, and your work is proving invaluable, so thank you! Just a quick question- why is it you use the EEPROM library for your YMFC-AL program? I am fairly new to Arduino, and have not experienced this library before. Could I not convert the receiver channel just using a simple 'map' to an integer for example, instead of an allocated register within the UNO's EEPROM? Thanks again, and keep up the good work!
Thanks for the reply, that's fine as I am writing my own code anyway, I was just wondering what the benefit of using the EEPROM library is? Many thanks
Been learning a lot from your videos, what modifications should i make if i want to adapt the code for a tricopter project? thanks! Also, are you releasing a tutorial for the telemetry module you made? thanks!
If you want to make a tricopter you need to send the PID output of the yaw to the servo. The motors are mixed with the roll and pitch PID as a triangle, not a square.
Joop Brokking, thanks for your interesting presentation. Due you think that the Arduino Due with a higher clock frequency could run your code without to much adaptations?
Hi I am working on my own flight controller I almost finished it. Currently I am working on stabilization. I saw your code and I don't know how you can use deg/sec as input for PID. Let's say that your quad isn't moving and it is tilted 45 deg, your program wouldn't see that. In my program I use degrees as input for PID but I have some problems with tunning. You can see my quadcopter at my chanel. I want to ask how big should gains be for degrees input. Thanks!
This is the 3D version. So the PID will try to match the gyro and receiver input. The YMFC-AL however has an auto level feature. It's explained in this video: ua-cam.com/video/DYpHB-LfloI/v-deo.html
Thanks for quick answer. I know but I can't understand how you can use deg/sec for PID input in auto level version, how is it possible. And can I use degrees instead of deg/sec?
Hello Joop, can you share the code for this balance stand project, i also made one to test PID, im confused to how i control the PWM of two ESC to balance the the Rod.
QUESTION: Dear Joop Brokking for the PID part, (pid_error_temp = gyro_roll_input - pid_roll_setpoint;) why are you subtracting a mixed (accelerator and gyro) value with a purely Gyro value to find the error. As you have stated that the Gyro value on its own is not accurate hence we must use a mixed (accelerator and gyro) value as it is accurate. I thought you would have used a mixed (accelerator and gyro) value and subtracted it from another mixed (accelerator and gyro) value. hence giving us a accurate pid_error_temp value. I am really confused about this matter please can you help. thank you
+Joop Brokking first off i would like to say i love your videos. and i would like to ask about the excel chart you had in this video. is there anyway you could put a link for a download. i am on a highschool robotics team and we use PID a lot but tuning is always a problem and this would help us so much. thank you and keep doing what your doing
Don't know if this has been pointed out yet, but at 3:32 there is a typo in the Derivative term, it should be: D-output = (gyro - receiver - gyro_prev *+* receiver_prev) x D-gain Great video, anyway!
It depends on you transmitter and receiver. With cheaper transmitters it keeps flying. The more expensive transmitters and receivers have a so called fail save function.
in the code for the flight controller, i still dont get how you figured out how to send the calculated pulses to the esc's based on the pid corrections and the reciever inputs. esc_1 = throttle - pid_output_pitch + pid_output_roll - pid_output_yaw; //Calculate the pulse for esc 1 (front-right - CCW) esc_2 = throttle + pid_output_pitch + pid_output_roll + pid_output_yaw; //Calculate the pulse for esc 2 (rear-right - CW) esc_3 = throttle + pid_output_pitch - pid_output_roll - pid_output_yaw; //Calculate the pulse for esc 3 (rear-left - CCW) esc_4 = throttle - pid_output_pitch - pid_output_roll + pid_output_yaw;
Hey Joop, I really appreciate this video. I've built my quadcopter and would like to use your formula for tuning my PIDs, however, I'm using Cleanflight as my program. I'm wondering if you or someone could offer ideas of the equivalent rates to use on Cleanflight to start the tune as you did in this tutorial? Thanks
Sir.. I'm a kid currently studying in class 10th ,,,, watched your video to complete my drone.. as I use some different hardware there is a problem in PID tuning.. just need your help how can I do this to make my drone fly
I am a control and automation engineer, who just finished a master in mechatronics. I am a true passionate to control engineering, and since 2013 when I was first introduced to control systems,i have NEVER EVER seen such a good simple explanation to a PID, specially regarding the derivative part. Actually, I only could reason about it by thinking about poles or spectral analysis. But your simple yet extremely clever explanation and demonstration gave me a new light on this subject and gave me a more 'physical' feeling about it, which IMO is essential to an engineeer.
I also want to build a drone from scratch a a hobby, and your YMFC serie is simply tailormade to my needs. I am infinetely grateful for your contribution, and hope you keep posting such good videos and projects. Keep on the AWESOME work, you are an inspiration !!!
Best regards !!
Having never flown a quad or any other RC model before I have watched these videos over and over again then took the plunge. I purchased some secondhand 2830 motors from ebay, made up a 450(ish) frame from upvc pipe fitted it with 30A esc's one of which was Faulty ! I used a "Beestore" pro mini which is fitted with an AMS1117 voltage regulator supporting up to 800mA for the controler. I loaded and ran the setup and calibration sketches and all worked fine. This evening I loaded the controller sketch and she flew straight out of the box even with an "odd esc". My activity's were cut Short by the weather but with a bit of tinkering (and four matching esc's) I'm going to have hours of fun. Thanks Joop for all your hard work and the many hours you have put into these videos, your explanations and demonstrations of how it all works are second to none. I just wish I were better at the coding side but I fear age is not on my side. LoL
You're the inspiration of millions of future engineers..... Respect
Hands down, the best PID explanation I've seen so far, and being a quad/fpv pilot, I've seen many, . Joop, you're an ace, thanks for taking the time to do this. It's on the shoulders of "giants" like you that we build. Keep up the excellent work.
I find this is the first video that actually explains in detail what PID settings do. Thank you very much!
I was lookign for someone who could teach every bit of coding that was necessary for building the drone . And I am very happy with the content you have posted. Thank you so much.
Hi, I am a CNC hobbyist. I am absolutely a novice to Audrino. Your video series is an inspiration for me to explore the audrino world. I have already place an order for UNO after seeing your video. I may not understand everything right away. But your explanation breaks down everything and logical to understand. Thank you so much for putting together this wonderful video series. I am excited as hell to start with this Quadcopter project.
Thank you,
Nave
Thank you for taking the time to write this positive comment.
Hello, thanks a lot for this much needed video series!
Just want to point out a slight error in one of the equations at 3:36.
It should be,
D-output = (gyro - receiver - gyroprev + receiverprev)*Dgain
and not,
D-output = (gyro - receiver - gyroprev - receiverprev)*Dgain
Karnik Ram Hi, gyro - receiver is the error and represents the 'e' in the equation at 1:51. The error is always calculated the same. In your line the previous error is calculated different than the actual error.
Previous error = gyroprev - receiverprev
Current error = gyro - receiver
Current error - previous error = (gyro - receiver) - (gyroprev - receiverprev) = gyro - receiver - gyroprev + receiverprev
Negative sign negates the negative sign.
Karnik Ram Yes, you are right! I should have added brackets in the presentation sheet. +1 for you sir!
thank you sirs to both of you for pointing out a bracket error... and at the same time confirming there was an error
Your explanation and test models are awesome. The best explanation of what P & I & D actually are as demonstrated with physical models.
Keep up the good work
I'm new to the multirotor business and this must be one of the BEST and clear PID explanation!!!! Bedankt Joop!!!
thank you. I just wanted to thank you for the enormous professional work you have done. My drone flies wonderfully thanks to you. I congratulate you immensely.
This is an amazing series! I started to create my own drone, with some knowledge which I never use before. This series helps to the whole knowledge in context and make my understanding deeper.
This video is Excellent! I found it very easy to pick up this complex topic with very little background in the area. Thank you for your efforts!
The best tutorial about PID that I have ever seen.
Thanks!
Agree, best ever. Goed werk!
Very good job. The best tutorial about PID that I have ever seen. Thank you so much.
Thanks, Joop, you have done the best drone tutorials I've ever seen.
Thank you for the build tutorial, after a couple months this semester research project for me just flew a few minutes ago, after some pid tuning frustrations!!!
Excellent explanation. Very good introduction for newbies (and probably more advanced users). Thanks a lot!
Hello, thanks a lot for this much needed video series!
The best tutorial about PID that I have ever seen!
Excellent! PID, make more sense to me. Besides that I admire your teaching/coaching talent.
Freddie Snijman Thanks for the compliments!
You are a brilliant person, your videos really help me out in my computer programming class and our arduino projects
Thank you for showing the code AND the resultant behavior on the quad. Big help!!!
I've been watching with interest. Thank you so much, for a well annotated sketch, as I will be doing this project with my son and it is a great help, to see each line described so well. When I saw your excel spreadsheet for PID, I decided to duplicate it, so I could play with the values myself. What I found very interesting, was to calculate and graph the PID Output, as well. I found this very useful, to show how changing the gains from 'neutral' (all = 1), to your actual flight values, dramatically changes the PID Output, from something that is dominated by I, to a shape that looks much more like D, with a trendline influenced by I. I also found that the graphing the effects of over and under tuning each value in turn, allows you to see how that behavior exhibits itself in the reaction. There were a few 'aha' moments, as I began to visualize how a large change in value for a certain gain, changes the response profile. Combining this with the airframe behavior (from watching your's and other's tuning videos) is pretty powerful. You might consider a supplemental video, exploring this in more detail.
Thank you for your reply and that this video was educational.
Excellent video , going into the practical approach to designing PID loop into mcu ..
I'm really out of compliments this time because every compliment is less worthy than your work. Brilliant work I've ever seen. Thank you so much. Your videos helps me a lot in my final year project of electrical and control engineering.
bundle of thanks and salutes for you.
regards.
Thank you for taking the time to write me this message. Really appreciate it!
Very useful videos for those who are building their own flight controller. Special thanks to mention that D gain should be fixed first.
Excellent tutorial, and the best explanation what (the hell*) is PID or PI on my KK2 board (there is no derivative, or D setting). At first it looks incredible complicated, but in your series of videos - if explainded as you just did - now it look much more clear and easy to understand.
Thank you very much.
PID is now much cleaner for me. Thanks
I'm the eight viewer. I must call that a victory and take this opportunity to congratulate you on your wonderful project.
Insta Awesome Thanks!
I'm confused why you've used gyro deg/s as your set point. Surely it would make sense to use the actual deg value otherwise the quadcopter could stabilise its gyro angle rates without actually being level itself?
Yes, these angel mode flight controllers perform better but I guess the reason of using a rate mode flight controller is that the calculations are simpler. So the required time for one cycle is low. Note The flight controller needs to run at least at 250 hz.
You have done fabulous work here and really simple
and it helped me a lot in my FYP. so hat's off for you thanx.
Great video. I thought it was gonna be super hard to understand but you explained it soo well :)
Finally a best video for understanding multirotor pid :)
Amazing piece of work, excellent control and response. Well done mate keep it up. ^_^
Le devo mucho a esta serie de videos. Muchas gracias.
Please ,enable subtitle option in all your videos to make more people who aren’t fluent in English,understand what you talk about.
Thanks for efforts.
Follower from Egypt.
I have learned many many things from you...Thank you.
D output = ((Gyro - Receiver) - (Gyro Prev- Receiver Prev) ) * D gain
+Brian Boozebacon Not many people have seen / noticed this typo in the presentation ;-) +1 for you!
+Brian Boozebacon just noticed the same error.
Thanks for clarifying!
Hey Joop, superb video! I wanted to bring something to your attention about the Arduino servo library. In your videos you went to a great trouble in order to make the refresh rates of the Arduino faster for the ESCs, hence better PID control, but I found that
with one single change to the Servo header file, you can have the Arduino servo library refreshing at the interval you want. You
may do this by changing the #REFRESH_INTERVAL value. Simply copy the file to the desktop, change the value, and copy the file back to the servo folder. I am going to check this out with an oscilloscope tomorrow.
Just wanted to let you know for less headache in the future :D
DUDE THANKS@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! AWESOME!!!
I remember your 1st soundless videos, and my wish to hear your explanations! AND NOW YOU KEEP MaKING US ENJOYING YOUR VIDEOS!!!!!!!!!!!!!!
First of all, Great Video Tutorial Series Joop, Hats Off!!!!!
What I noticed is, you have mounted the gyro underneath the right arm [During PID demo 5:24...], will correction be much more accurate if gyro has been mounted towards or at the center.
Thanks for the compliment! The gyro only detects angular motion. Perpendicular motion will not affect the gyro's output. The best location for mounting the gyro is away from vibrations. This usually means in the center of the frame.
Thanks for everything. You are brilliant at teaching.
Very nice tutorial !!! Looking forward for the next video !!!
Very Helpfull and cool practical examples!
Fantastic work. PID explained so even I can understand it. Genius!
Great video! Can I ask why the roll limit is set to 400? Is this an arbitrary number?
when will the 6th part will come ,anxiously waiting 4 it ??
I've watched this video many times now (which is great by the way), but there's one fundamental thing that I'm not understanding in regards to the rate mode.
If the error is the difference between the gyro reading and the user's input (in deg/s), then when the quad starts rotating and approaches the desired rate won't the error decrease to 0, meaning there is no correction factor and just the throttle value is written to the motors? Perhaps I'm missing something?
+Joe Prince Yes, the error will decrease to zero. But the pid-controller will work on it to keep the desired rate.
So my input is 20deg/s and the quad rotates 20deg/s. The error is zero and only the throttle will drive the motors.
But when the quad rotates 19deg/s the error is 1deg/s and the motors are corrected.
In practice the error is never zero. The controller is constantly correcting the multicopter. It goes so fast that it looks steady. But in fact the multicopter is very unstable.
+Joop Brokking I appreciate the insight and information. I have a question in regards to this line: "The error is zero and only the throttle will drive the motors."
If the error is zero and only the throttle is driving the motors (let's say 50% throttle or 1500µs), then how is the quad rotating? Don't we need a difference in motor speeds in order to obtain rotation? That's kind of what my first question was referencing, the fact that if our error is zero then we're writing the same value to the motors (in this case the throttle) which in my mind means the quad is not rotating. Am I completely misinterpreting this?
Joe Prince
As I wrote, in practice the error is never zero. And if it becomes zero during rotations the I-controller is 'loaded' and will make the quad rotate.
But you are right about the fact that the multicopter does not rotate that well with all the 4 motors spinning at the same speed.
+Joop Brokking Does that mean it wouldn't be possible to write a "P" only controller for rate mode, since there is no "I" term to build up?
Only a p-controller will not work. You need at least p and d to make it fly. If you look @14:00 in the video you see that I fly the multicopter with only the p and d controller. It fly's but does not feel locked in. The i-controller makes the multicopter locked in.
Hey! Great tutorial series, thanks. I wondered something, what is the working principle of your test setup at 1:00 ?
AWESOME ! It helps a lot for my project thanks Joop Brokking
as you may know that the maximum output is 400 pid?
float pid_p_gain_yaw = 4.0; //Gain setting for the pitch P-controller. //4.0
float pid_i_gain_yaw = 0.02; //Gain setting for the pitch I-controller. //0.02
float pid_d_gain_yaw = 0.0; //Gain setting for the pitch D-controller.
int pid_max_yaw = 400; //Maximum output of the PID-controller (+/-)
Thanks Joop, for this amazing video series. I have a question regarding the base throttle signal for quad-copter hovering. How do make sure that when throttle stick is in the middle, i.e. transmitting 1500us pulse the drone hovers?
Great video my friend I have a question, how you find the bests values to kp, ki and kd constants?
Brilliant tutorial once again. Thank you very much.
Hi Joop, Thanks a lot for this video, you have made this very clear for me. Your explanation and major part of your code has allowed me to build my own UAV (Unmanned Aerial Vehicle), one problem i am facing is that the structure of my drone is a Hexacopter (runs with 6 motors). For a Quadcopter, the ESC equations are as follows:
pulse_length_esc1 = instruction[THROTTLE] + roll_pid + pitch_pid - yaw_pid;
pulse_length_esc2 = instruction[THROTTLE] - roll_pid + pitch_pid + yaw_pid;
pulse_length_esc3 = instruction[THROTTLE] + roll_pid - pitch_pid + yaw_pid;
pulse_length_esc4 = instruction[THROTTLE] - roll_pid - pitch_pid - yaw_pid;
what will these equations be if i have 6 ESCs instead of 4, your assistance would be greatly appriciated
Hello Joop, your videos are great, I am wondering about one thing though. What do you need total angles from gyro+acc if you only use the gyro angular rate for your PID control? Is using angles and assumming the transmitter stick position inputs desired angle of the quad is a wrong approach?
you are genius man. great work. thank you so much for sharing your knowledge.
Thank You for sharing this valuable knowledge.
Great Job excellent video! but there is some think i don't understands here you choose de maximum command to 164dps (setpoint) how do you know that's not too high and the drone isn't going to fall ? thanks in advance for your answer ^^
It's just a trail and error value that works fine for most pilots.
ok thanks but can we consider that the max 164dps command is like we ask the drone to have a 45° angle on the considered axe. Sorry to bother but i'm doing a drone for a study project only using a gyrocope as a capteur and i don't know how to explain how i choose this part of the code (164dps max setpoint) thanks in advance for your answer
The 164dps tells the drone that it must rotate 164dps. It's not a fixed angle.
In this video I explain the auto level function and the angle calculation: ua-cam.com/video/DYpHB-LfloI/v-deo.html
yes i saw this video but you are using an accelerometre. the thing is i don't understand how to think with speed and not position. Because when you put de joystick to 2000 us (convert in 164dps in the code) if it's the roll you ask the drone to rotate at 164dps to the right, like that it goes to the right. But i don't understand if i keep the joystick to 2000us why the drone just goes to the right and don't rotate on the roll axe indefinitely ? ( i know what i say is stupid because the pid is correcting the thing but that's my problem )
The confusion is probably the difference between rate and auto level. The video that I linked is the auto level that uses an accelerometer and angles. When you release the sticks the quadcopter levels itself.
If you use only a gyro the quadcopter is flying in rate mode. This means that when you release the sticks the quadcopter will keep it's current position. Then you move the stick full right the PID input is 164 degrees per second. The PID controller will change the motor speed until the gyro detects 164 degrees per second. And it will keep rotating at 164 dps as long as the stick is full right. Meaning that the quadcopter flips upside down proximately 2 times per second.
Joop, great video. I've noticed in some of your other videos that you have very good altitude hold. I was wondering what your process is for tuning the PIDs for altitude hold? Thanks.
The altitude hold test is form this video: ua-cam.com/video/oc8Gv61bfvU/v-deo.html
I'm using my own algorithms to get is stable like that.
@Joop Brokking , first of all: great content! this is very informative!
The generic PID definition uses DeltaTime as a multiplier for the I and D terms, but you seem to not use it... Is this because your feedback variables are in º/s. ? In my case I´m trying to simply control the Pitch/yaw/roll (so plain º).
Thanks.
The delta-t is fixed in the loop time of the main program loop. For the YMFC it's 4ms. This way I don't have to take the delta-t into account.
@@Joop_Brokking Ah yes, I was looking through your code and makes sense! Thanks.
@@nachocortizo3321 had u finished your Quadcopter project did it ran well?
Excellent job done!!
Keep it up man!
tHANLS A LOT FOR SHARING YOUR KNOWLEDGE !! COULD YOU PLEASE SHARE WITH ME , THE EXCEL SHEET ? THANKS
Hi Joop! Amazing videos! So helpful! I have one problem though...
I am trying to adapt your YMFC-AL code for autonomous flight, so no radio input! I have built a test stand like yours in this video to demonstrate the auto-level.
I can't under stand how to adapt the setpoint for the PIDs to keep the quadcopter level in hover, as my PID input is angular motion, not angular position. When I try to implement my code on my test stand, the PID stabilizes the axis to the point where I push it, but doesn't auto-level! How do I covert the angular motion data to an angular position so I can auto level?
Sorry if this doesn't make sense!
Thanks
Watch this video: ua-cam.com/video/DYpHB-LfloI/v-deo.html
It explains how to get a simple auto level feature.
Hello Joop, been following for over a year. Very thankful for such an elaborate guide. My query is are we using position/angle data in the PID controller or is it just the angular speed as the set point. I mean are we controlling roll/pitch speed or the roll/tilt angle. Using speed as the set point my P control behaves a like a D control (just damps motion)
hello again joop. first of all i'd like to thank you for this amazing video series and your active responses.
you have inspired me to build my own flight controller and i am almost done, but stuck at setting the pid.
setting the d gain first, didn't work for me as i have a 360mm frame and being a novice it's difficult for me to obtain the point of vibrations.
if i try to set the p gain first the quad starts to oscillate and overshoot at a low frequency with the amplitude becoming higher every time.
i am guessing this could be a result of the pid_output_pitch =400 being high as my escs are 50hz as compared to your 250hz escs.
so do u think the pid_output_pitch should be 400/80 in this case because of a lower refresh rate in order to prevent overshooting?
thank you
Are you running a 50Hz refresh rate from your flight controller program? Most ESC's that are designed for multicopters will work fine with a 250Hz refresh rate. If you use ESC's designed for planes it will not work because they are to slow.
+Joop Brokking i am running a 50hz from the flight controller. as per my understanding many escs flashed with blheli or simpnl firmware run at 250hz. however many escs still work on 50hz. i'll have to buy new escs for 250hz ...but that wont be feasible for me now.
+Joop Brokking blheli or simonk firmware*
Do you have an internet link of the ESC's you are using?
Hello sir , I'm tanmay and I'm a engineering student . I am working on the Arduino based drone with the help of your video . I facing many challange to setup best PID values . Sometimes those values works correctly then i take the flight of the drone but unfortunately drone flip on the specific height, like 9 feet . I have been facing this problem currently . Could you help me to solve this problem . When i press the reset button on the Arduino . drone gives the stable flite but suddenly drone flip into the sky and it stops working . From this problem i have losted one Arduino uno board . You are my last hope. What did i do to solve this problem . All parts are working properly buy unfortunately i don't know what's the problem . I have been trying to solve this problem for 3 months . I started to make the drone 3 months ago . But this problem didn't solve . I'm waiting for your reply . I am making this drone for my college project
So please help me . I will appreciate your help .
Please reply me sir . I will tell you my all problems in the drone .
thank you , please reply me ❤️
icant find the arduino code related to this video in your website
Great video Sir Joop. please I wish to know ,Where is the receiver signal from ?? I'm currently working on a wind pendulum project and I hope to adopt your PID lesson to balance the pendulum at center within the shortest time given , the pendulum has 4dc fans attached to its 4sides .how can I apply your lesson? Thanks for your help in advance
Thank you very much for this wonderful video.
There will be precedence issue in the calculation of Derivative out put i think. The video is very informative. Thanks for sharing.
Hey Joop, my quad is yawing violently when I use the pid-i as in your code
-> pid_i_mem_pitch += pid_i_gain_pitch * pid_error_temp;
The i - gain seems to happen even when the quad is stationary and there is no change in angle!
But when I changed it to -> pid_i_mem_pitch = pid_i_gain_pitch * (pid_i_mem_pitch + pid_error_temp);
It worked fine. Have I made an error elsewhere in the code which could have led to this?
Thank you for the amazing videos! I have learnt so much from them.
We have to do the same for the yaw values?
Your videos are awesome! I myself built the YMFC-AL quadcopter and it works well.
The only problem I am facing is that when I change the value of I, the quad tilt in one direction and I have to use subtrims to level it. It works perfectly fine with I=0;P=1.5 and D=15. Can you guide me how can I tune the value of I to make it more stable. Even at I= 0.01 , the quad tilt in one direction. Waiting for your reply.
You can use the sliders on the transmitter to level the quadcopter. Make sure that you don't move the quadcopter at startup.
The same thing happens to me ... always when starting starts to the side, and it is difficult to stabilize it, since the position to self-level will always be to one side
Excellently explained but where do those 'dt' terms go? (as in pid formula) Don't you need to multiply with the time step in case of integral......?
The program loop is fixed to 4ms. That is why you don't include time as it will not change.
awesome project.
but i have question.
I would like to see the error value, PID values, as well as its PID chart. how do I get to see its. as in this video, at minute 4:50. thanks Joop Brokking.
You have to use Serial.print to output the values.
thanks joop brokking.
in the code your upload,
where I use serial.print if I want to see the final value of the PID, time (us), receiver (dps), gyro (dps), the value of P, the I and D?
because I want to see a graph of PID to determine its stability.
and if i starting the motor, value of throttle not on 0%. it abuout 10%. whats happen?
It's normal that the motors start spinning when you start the quadcopter. You can see the same here: ua-cam.com/video/gz-Mywo7bGc/v-deo.html
I see joop brokking. Thanks.
How about.
in the code your upload,
where I use serial.print if I want to see the final value of the PID, time (us), receiver (dps), gyro (dps), the value of P, the I and D?
because I want to see a graph of PID to determine its stability.
Hi Joop, I am doing a similar project, and your work is proving invaluable, so thank you!
Just a quick question- why is it you use the EEPROM library for your YMFC-AL program? I am fairly new to Arduino, and have not experienced this library before. Could I not convert the receiver channel just using a simple 'map' to an integer for example, instead of an allocated register within the UNO's EEPROM?
Thanks again, and keep up the good work!
Yes that is possible. But you need to modify the code yourself.
Thanks for the reply, that's fine as I am writing my own code anyway, I was just wondering what the benefit of using the EEPROM library is?
Many thanks
Been learning a lot from your videos, what modifications should i make if i want to adapt the code for a tricopter project? thanks! Also, are you releasing a tutorial for the telemetry module you made? thanks!
If you want to make a tricopter you need to send the PID output of the yaw to the servo. The motors are mixed with the roll and pitch PID as a triangle, not a square.
Beautiful! Thank you so much!
Very nicely explained!! Thanks!!
is it without flight controller?
Can you make a video on concept of choosing pitch and diameter of propeller of drone
VERRY VERRY AWESOME EXPLANATION WOOOOOW
Joop Brokking, thanks for your interesting presentation. Due you think that the Arduino Due with a higher clock frequency could run your code without to much adaptations?
+Jack Bosshard I have no idea. I never used a Arduino Due myself so I can't give you any useful advise.
Is there a sketch that goes along with this video?
R Praver There is no sketch for this video. I hope to post the last video within a week so you can download the complete Arduino sketch that I used.
Hi
I am working on my own flight controller I almost finished it. Currently I am working on stabilization. I saw your code and I don't know how you can use deg/sec as input for PID. Let's say that your quad isn't moving and it is tilted 45 deg, your program wouldn't see that. In my program I use degrees as input for PID but I have some problems with tunning. You can see my quadcopter at my chanel. I want to ask how big should gains be for degrees input. Thanks!
This is the 3D version. So the PID will try to match the gyro and receiver input.
The YMFC-AL however has an auto level feature. It's explained in this video:
ua-cam.com/video/DYpHB-LfloI/v-deo.html
Thanks for quick answer. I know but I can't understand how you can use deg/sec for PID input in auto level version, how is it possible. And can I use degrees instead of deg/sec?
Hello Joop, can you share the code for this balance stand project, i also made one to test PID, im confused to how i control the PWM of two ESC to balance the the Rod.
sir i still dont understand why you are dividing it by 57. bcz its already has 17.mdps
then your equation should ne x. * 57 =1
QUESTION:
Dear Joop Brokking
for the PID part,
(pid_error_temp = gyro_roll_input - pid_roll_setpoint;)
why are you subtracting a mixed (accelerator and gyro) value with a purely Gyro value to find the error.
As you have stated that the Gyro value on its own is not accurate hence we must use a mixed (accelerator and gyro) value as it is accurate.
I thought you would have used a mixed (accelerator and gyro) value and subtracted it from another mixed (accelerator and gyro) value.
hence giving us a accurate pid_error_temp value.
I am really confused about this matter please can you help. thank you
poor child, it has been 3 yrs, Mr. Joop still didn't answer u
@@donyip9674 One day my brother, one day he will.
Does this tuning need some other input besides the throttle?
+Joop Brokking first off i would like to say i love your videos. and i would like to ask about the excel chart you had in this video. is there anyway you could put a link for a download. i am on a highschool robotics team and we use PID a lot but tuning is always a problem and this would help us so much. thank you and keep doing what your doing
I don't have the Excel sheet anymore because I just made it for the video.
Joop Brokking ok that's fine I understand
Hi,I have some questions,how can i ask them to you?
Don't know if this has been pointed out yet, but at 3:32 there is a typo in the Derivative term, it should be:
D-output = (gyro - receiver - gyro_prev *+* receiver_prev) x D-gain
Great video, anyway!
Great spotting :-) It should actually be:
D output = ((Gyro - Receiver) - (Gyro Prev- Receiver Prev) ) * D gain
both are the same
Hi Joop, what happens when the quadcopter goes out of range?
It depends on you transmitter and receiver. With cheaper transmitters it keeps flying. The more expensive transmitters and receivers have a so called fail save function.
i tried your code but my drone is not flying. it's flipping. can you please help me?
in the code for the flight controller, i still dont get how you figured out how to send the calculated pulses to the esc's based on the pid corrections and the reciever inputs. esc_1 = throttle - pid_output_pitch + pid_output_roll - pid_output_yaw; //Calculate the pulse for esc 1 (front-right - CCW)
esc_2 = throttle + pid_output_pitch + pid_output_roll + pid_output_yaw; //Calculate the pulse for esc 2 (rear-right - CW)
esc_3 = throttle + pid_output_pitch - pid_output_roll - pid_output_yaw; //Calculate the pulse for esc 3 (rear-left - CCW)
esc_4 = throttle - pid_output_pitch - pid_output_roll + pid_output_yaw;
Hey Joop, I really appreciate this video. I've built my quadcopter and would like to use your formula for tuning my PIDs, however, I'm using Cleanflight as my program. I'm wondering if you or someone could offer ideas of the equivalent rates to use on Cleanflight to start the tune as you did in this tutorial? Thanks
Sir.. I'm a kid currently studying in class 10th ,,,, watched your video to complete my drone.. as I use some different hardware there is a problem in PID tuning.. just need your help how can I do this to make my drone fly
How you choose the PID values of yaw to get the PID values of roll?
How to get the remote control to operate the quad-copter. I watched a remote control and you controlled the copter by the the joysticks.
+Mohammed Nurullah The receiver inputs are explained in part two of this YMFC-3D series.
when i start the motors, the quadcopter tends drifts to one side and is not stable. plz help
Hi Joop Brokking,what your code balance test in your video????