PID Balance+Ball | full explanation & tuning

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up my friends welcome back so I still have a lot of requests to show you how Bailey works but we have already seen a lot of videos about that we have seen how to control some brushless motors and control the anger of a bar using PID we also seen a PD control for temperatures and to control DC voltages and also seen another PD control for temperature but for AC voltages and also all the drawers project that I made our control with PID and the small portable soldering iron is also controlled with PID but if PID still seems very difficult for you here I have the most basic and simple example that will show you how the PDI and the Devere balls will affect the system so this example will be better because it is a little bit more graphic you can see the variables in any given moment you can see the distance to the ball how the motor is moving and so on and also the speed of reaction is a little bit slower letting the case of the brushless motors so we can see all the details this is called a PID control for a balanced with a ping-pong ball so the basic principle of this will go like this we have an infrared sensor that would measure the distance from the sensor to the ping-pong ball and at the same time we have a servo motor that will move the bar up and down and by that control the position of the ball so all we have to do is to fly the PID control and react to the speed and to the position of the ball and keep this ping-pong ball always in the middle everything is controlled with an Arduino that will measure the distance to the ball and also control the servo motor so it is pretty obvious that if the ball is a little bit more to the right the ball will move and push the ball to the left and if the ball is a little bit more to the left it will do just the opposite okay just let me show you a quick example I'm powering the power supply and as you can see the ball should stop exactly in the middle pretty much in the middle and this will oscillate a little bit because the sensor that I'm using is not very precise and will have a little bit of error so let me just stop this because it makes a lot of noise the idea goes like this we have to use PID control to keep the ball exactly in the middle so in this video I'll show you how the system works how to build it and we will also make a lot of tests and try different values for the PID constants and finally we will merge everything together into a PID control I'll try to explain the best that I can how to turn the pay the constant and once you know how to setup this example you could apply the same theory to any kind of PID control but before you start make sure that you hit the subscribe button also that notification bell because otherwise you might miss my future videos the notifications distance for the YouTube videos change a little bit in the last few months so make sure that you activate the notification Bell but also that you enable notifications in your device and in that way you'll be able to see my videos when I post them and as always a huge tank at all my patterns for supporting my work so let's get started GLC PCB is sponsoring this video they provide fast and best-value prototyping services with their online and instant code fast allocation and competitive prices you can save a lot of time and money so quote now upload the Gerber files of your PCB and for only two dollars plus shipping you can order PCBs in less than five minutes what's up my friends welcome back let's start by building the balance first this will be very easy and very fast if you want to make the same experiment and learn how this work you'll have the 3d files for the balance below this video print the parts with PLA material zero point four millimeter nozzle and 0.2 millimeter layer height we have this main support then we have some small parts that will create some sort of hinge that could move left and right we have this support for the Futaba servo motor and we also have a disc that will be connected to the shaft of this motor then we have these small parts that will be used to transfer the movement from the servo motor to the balance we also have these plastic end stops that will be used later for the moving rail I will be used some plywood parts because printing parts this big it will take a lot of time I will glue these two parts one to each other with a 90 degrees in between and then the ping-pong ball will be able to roll on this groove I will screw the entire balance to another piece of plywood and that's it for the body of this project so once the glue for the long plywood part is dry I glue that to this plastic part and make sure that the part is exactly in the middle so the balance will rotate with the same force to each side then I screw the main base to the other plywood part using some entry screws now I add a short 8 millimeter screw to this other part now on top of this support I add the balance and I place a three millimeter screw and they make sure it could rotate with low friction right and left so now the main body of the balance is ready to control the movement I used the s 3003 Futaba servo motor and to measure the distance I first wanted to use the VL 53 else your X laser distance sensor but that wasn't precise enough for distances above 20 centimeters that's why abuse another infrared sensor the sharp 2 y 0 821 so I glue the other small parts to one side of the balance now I make this other part with a wood barbecue stick in between I measure more or less were to place the servo support now I add the servo motor to that support and I screw that in place now I put a servo in the zero degrees position and I add the disk using the given star-shaped part from the servo and I tied the screw now I screw the support in place and connect that to the balance and now it will move up and down and by that it will change the angle of the balance below you'll find some different sizes for the disc in case that you need faster or slower movement and for the infrared sensor again I'll finally use the sharp 2y 0 8 21 because the other sensor lost the good resolution over 20 centimeters this one has a lower resolution but is kind of the same over the entire range from 0 to around 40 centimeters so I go the sensor to one end of the balance I also add a 10 micro farad capacitor at the filter at the sensor output so Citiz Kemetic for more I place another and stop to the other side now I pass all the wires and connect those to the Arduino that will be placed here and the setup is ready for tests so check the schematic for this below and also the final code and download that code and upload it to the Arduino and let's start with the tests in the code on this part you will see the KP the ki and the KP and you could change this pay the constants if you want and try some different values any PID system will need three main parts first we need a feedback which in this case is given by the distance sensor then we need an actuator that will change the system output and in this case that will be the servo motor and finally we will need a PD code in between with a set point and that set point in this case will be the middle position of the balance so when we measure the distance it will be half of the balanced length okay so first we have to see the proportional action that will have this equation so for that I put the KP equal to a value and I will leave the ki in KB equal to zero so now only the KP will affect the output the sensor will measure the distance to the ball if the distance is not zero it will move the servo proportionally till the distance gets closer to the center so look what happens with a KP equal to 20 the system oscillates too much and also too fast so we have to put a lower value I now make the same test but a lower KP equal to 8 so now we have a pretty decent oscillation but the ping-pong ball won't stay in the middle and that's pretty obvious if the distance is too high the balance will rotate clockwise and if the distance is too low it will rotate counter clockwise and that will always end up in an oscillation but don't worry that is good for us all have to do now is to rapidly stop the ball when it's in the desired position in order to make some fast changes we have to react to the speed of the ball not to the distance anymore but speed is equal to the distance divided by the time and that's Delta X divided by delta T where the X is the distance and the T is the time so we need the derivative part of the PID control that will have this equation now I put all the constants to 0 but I set the derivative part to 5000 now look what happens the reaction to the speed of the ball is too strong so we have to lower the value so now I set the KD to three thousand and five hundred now as you can see the system reacts very fast to the speed not to the distance anymore and by that it will stop the movement but now we have a different problem now the ball will stop in any position and we don't want that we want it to stop exactly in the middle so for that before as you remember with the peak control the ball passed in the middle each oscillation and now with the D control we could stop the ball so if we combine these two together we could boost up the ball and also exactly in the middle I now make some more tests but I make the sum of the P and the D constant and this is called a PD control and this is the equation as you can see now I stop the ball and it is also close to the center so my system works quite well for now but what will the I variable add to the setup well for example in this scenario the ball stopped at around 1 or 2 centimeters so that's not exactly in the middle the balance isn't moving anymore because the error is too small so the proportional part won't affect also the ball is not moving so the speed is 0 so the derivative part won't affect neither that's why we need to add the integral this part will sum up each loop in the code and by that we'll get bigger and bigger to understand better I set all the constants to 0 but I put the integral to 1 so now I've got the ball and let's see the effect as you can see the more time passes the bigger the integral part will get and the more the balance will rotate so if the ball gets started for example 2 centimeters the integral part will slowly increase till the ball is exactly in the middle so that is done very fast in the code and we will get the good PID control so now I make the sum of all three variables with this equation the output of my PD control will be a PWM signal that will be applied to the servo motor and that will move from 0 to 180 degrees now I have a pretty decent control and the ball is stopped in the middle no matter how fast I move it or from where I move it so I hope this simple example explained how basic PD control works and why we need each of the P the I ended the variables if you know these basics you could apply the same algorithm to any other system and control speed control the angle the temperature and so on in any case you will need a feedback which in this example was given by the distance sensor in the brushless motor balance the feedback was given by the MU module that measured the inclination angle and in the temperature PD control example the feedback was given by a temperature sensor that was placed over the heating element you always need a feedback an actuator and the PD code in between the feedback and the actuator in my case the ball is not that stable because the sensor has some small error readings between 1 and minus 1 centimeters but it will stop the ball pretty decent with better sensors better filter and better PD values you could get way better results than I have so guys I hope that you like this experiment and that you have learned something new if so consider subscribing and please make sure that you activate a notification bell because otherwise you want to receive my notifications when I upload a new video also consider supporting my work on patreon so thanks again and see you later guys [Music]
Info
Channel: Electronoobs
Views: 466,724
Rating: undefined out of 5
Keywords: PID, balance, ping pong, ball, distance, sharp, IR, sensor, 2YA021, servo, Arduino, variables, temperature, angle, DC, motor, speed
Id: JFTJ2SS4xyA
Channel Id: undefined
Length: 13min 12sec (792 seconds)
Published: Sun Jul 14 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.