Hi, I am not a PID specialist, but I suspect that gluing the sensor right on the electromagnet may be the source of some instability, because the sensor is exposed to two variable fields, as well as some interactions between the neodymium magnets and the coil of the electromagnet. This has all the features of a chaotic system, including non-linear feedback. You might want to place the sensor underneath the neodymium magnets, or use a photocell instead of a hall effect sensor. Good luck!
what photocell sensor can work variating the output?? i have searched a lot but just found on/off type... not ideal for these aplications of positioning.
Shielding the HALL sensor on the backside with mu metal can also help, as well as moving the HALL sensor off to the side of the metal core of the electromagnet where the field from the electromagnet is less concentrated. A bar electromagnet is also helpful and should give you more distance as some of your field lines are going to take the path of least resistance and go nearly straight across the gap between the elctromagnet north and south pole, although if the HALL effect sensor is placed in the right spot between the north and south pole you may get them to zero-out their effect on the HALL sensor, not sure on that one though.
You are correct, in those kind of systems where the feedback is non-linear (changed by multiple effects other than the levitating magnet) completely changes the dynamic model of the system, that will lead to unstability when the control signal aka the electromagnetic force applied by the electromagnet, will change the feedback dramatically, thus will lead to a situation that the controller thinks that the magnet position changed much. So it will try to compansate that big change which will result in a bigger control signal which causes a bigger feedback change even tough the magnet hasn't moved much. and this goes on and on... So the control signal will be affected by this problem more and more after a certain time system will go unstable. Instead of hall sensor, a distance sensor could be used. Anyway, Great work. !
I was also wondering if you could simply consider the contribution of the magnet as a function of the current supplied to it. And then you just subtract this value from the value given by the sensor. The function could be determined experimentally.
This kind of systems is nonlinear and the controller can really struggle to stabilize the system around an equilibrium point. However, Two nested (inner and outer) loops can improve the performance much more.
Walid Issa typically nested loops require another input. One slow and one fast input. It is non linear so I think he'd need to linearized the pv or cv before feeding it into the pid algorithm
In high performance applications, the way magnetic levitation is performed is by using two control loops. You have an inner control loop using typically a PI controller that regulates current (you need current sensors) into your RL load (electromagnet). You then have a an outter control loop that regulates position typically using a PID controller with a low pass filter on the derivative term. Your sensor reads in position which goes through your PID controller... the output of this motion controller is a force command. This force command is then inverted into the corresponding current needed to produce that force. This current command is then fed into your inner loop controller which regulates your current to the desired value. The desired current flows and produces the force commanded by your PID position controller and the overall loop is closed. Tuning the current regulator is pretty simple... using pole-zero cancellation, you set kp = L * w_b and ki = R * w_b where R and L are the resistance and inductance of your electromagnet respectively and w_b is the desired bandwidth of your current controller in rad/s. Tuning the position controller is a little more involved as you must move your unstable RHP pole into the LHP. Although tuning can be done manually, it is very difficult as you're trying to make an inherently unstable system stable. Frequency domain methods usually work really well for tuning it. Cheers!
From a mechatronics student- inertia, drag and friction all help stabilise the system which utilises a PID. The reason why a "bigger" magnet had more stability is that it had more mass, thus it was less prone to sudden position changes due to its greater inertia. This way you can slip out of complicated automatic control systems calculations and simplify experimental PID method. I think that (instead of adding additional magnets to the elongated structure which changes the field's geometry) you should try attaching non-magnetic material to the bottom of the magnet, as a weight. Lead is easy to melt/ shape, it has brutally high density and it is a diamagnetic. You could maybe try experimenting with small lead pellets, sticking them to the bottom of the elongated magnet until you hit the required weight for approximated parameters.
Greeting GreatScott!, I have seen a lot of giveaway events, but by asking participants to find and publicly expose own mistakes in a giveaway, this is my first time. Salute your humility and efforts in doing better in educating people. Below are the mistakes I have found: 1) You shouldn't be gluing your hall effect sensor to the electromagnet. The sensor should be 'focus' on detecting the magnetic field strength of the magnets without being affected by the electromagnet. In other words, during automatic control, you are changing the gain of the electromagnet, the distance you desired is no longer 700mV. The way you did causes the control system to be non-linear and time-varying. 2) SS49E, not SS49A 3) Hysteresis, not hysterisis 4) Derivative controller is actually based on the rate of change of ERROR to be precise, de(t)/dt, not rate of change of actual value (mentioned at 6:04). It sounds the same and intuitively no difference, but the rate of change of error and rate of change of actual value is totally two different things. 5) And of course, at 6:05, df(t) / dt, not df(x) / dt 6) At 6:10, Kd factor not Kp. I am not sure what type of mistakes you want (minor or major?). If I need to choose only two, I will choose (3) and (5) mistakes since they are obvious in your video. And I hope the following will be helpful to everyone who are interested in control system engineering: - Normally, people use displacement sensor to do positioning of magnetic levitation (maglev) system. - Maglev system is a highly non-linear system, using merely conventional PID controller is never sufficient to control. Classical control (PID controller is in this section) emphasizes on LTI system, which LTI stands for linear time-invarient. - I believe that the performance of the MOSFET is non-linear. In other words, the supply voltage and the lifting force is not directly proportional, thus non-linear. Two ways of solving this problem - first, identify the LTI range of the MOSFET and make sure your system works only within that range, second, accept the non-linearity and uses a controller that works with non-linear properties, for example, Fuzzy-Logic controller (FLC). - At 7:21, the tuning method is belongs to Ziegler-Nichols tuning method. Such tuning method is easy to be implemented, and unfortunately causes it to be 'exploited' and 'abused'. The tuning method by the original author/creator emphasizes that such tuning method is only applicable to first-order plus time-delay system (FOPDT). Maglev is indeed not one of them. But still, people are using it everywhere for all kind of system without actually understand the tuning method's requirement. - At 7:25, I have never seen such high Ki is required for a system. I think eventually, you are implementing I controller instead PID controller, which is why it still works (and even better) and you got it theoretically correct - it will never last forever. I am extremely welcome to any feedback regarding what I've posted here. Anyway, I am a control student who self-fund for my own study and researches (sadly no free education at all in my country). I only has a DSO138 oscilloscope on my workbench and wanted to upgrade since long time ago, so hopefully I get to win this giveaway.
Scope the magnet current vs. PWM. Your freewheeling diode will keep the current flowing for a while after voltage is removed, so you may need to subtract a time offset from your PWM setting to help stabilize response.
First of all you need to identify your system in order to know if it is a first order, a second order system or even higher, from that you will be able to get the correct values for the three parmeters using the appropriate methods. Mathematics are mandatory for the PID controller designing if you want to get better results. Please consider make more videos about this topic it is really interesting and helpful.
I Really enjoyed the idea of applying principles of PID to this project. You made the explanation of a PID controller very simple and easy without delving into mathematical jargon, the kind we used to endure in the old days. And .... thanks for the JLCPCB link.
I have been watching you videos for a while now and I find them really informative and intriguing. The fact that you also show things and projects that didn't work out as expected or didn't work out at all ( while many other channels just fake it for views) is what makes you stand out. It gives us insight for what to look out for and how to avoid them. Hope to see more great content from you. Kudos.
I made this project totally with an analog circuit. It was difficult but I managed to move the setpoint without shutting down the magnet. Is an amazing project.
The mistakes are : Hysterisis is actually hysteresis and you said Kp factor the Kp factor is used in the proportional term while you were talking about the Kd factor which is used in the derivative term :D Awesome video, I had to learn about this in Uni 2 years ago it would be easier if I had this video at that time :D
Hi, I tried your methods in my Lab. It is super unstable, you're right. But I fixed it. What I did was change the shape of the levitating body. I cut out a piece of circular light weight cardboard and attached it to the magnet. Like this: -----()------ Now the magnet rarely topples or falls down, because it is hard for the levitating body to topple side ways. Your idea works, it just needed a little mechanical touch to it.
Either a faster microcontroller or an analog op-amp PID controller would probably work out well. Tuning an analog PID controller would not be as easy as simply changing constants though. (Instead requiring changing component values, variable capacitors and pots would probably make this easy)
PID tuning is definitely an art that takes time to master. When you get comfortable try your hand at servo systems. While they are more expensive than steppers, they are far superior in some applications.
one fundamental issue with your setup (and in fact all electromagnet setups) is that the attractive force varies linearly with coil current, but is inversely proportional to the square of the separation distance between the coil and the target magnet! So, increasing coil current by say 1amp, might be enough when the magnet is close, but not nearly enough when it is far away! That square term means as the magnet approaches the coil, the current in the coil must fall with the square of the rate of change of distance! The two step (bang-bang) controller works better because the inductance of the coil effectively stores energy, and that energy is then set by the average duty cycle of the output. With its higher gain (max on, or max off) and faster loop (less time between changing the state) that system works better than a slow, poorly tuned PID. If you want to use a PID, then two options are possible, 1) non linear gains, or (easier) 2) a feed forward table of duty cycle values. Populate that table with the duty cycle that just balances the magnets mass at each distance away from the coil. That open loop feed forward table means the PID then just has to mop up the error (in fact, you'll find a simple P controller will work) as the intrinsic phase lag of the I term has been removed!
Hi, I study control systems for a living. The system you described can never be truly 'stable' from a single loop PID. What you need is a cascaded PID. The first loop should look at the derivative of position of the magnet, and the outer loop should look at the position of the magnet itself.
St0RM33 Well, correct in a way. A cascaded controller would mean you have one loop taking in magnet position and outputting velocity, which is fed into another loop that takes in velocity and outputs electromagnet output. :)
the problem of this sytem is that it's not a linear system, but a non-linear one, what means you can't use linear control techniques to control it. Also PID linear tuning method like ziegler-nichols won't work with a non-linear system (a PWM control, for instance).
I have seen several explanations of a PID controller, but this one is the best. It's even better than the one by @AndreasSpiess. And that is an achievement ! Another GreatScott moment !
I think a faster controller might help. And also, as someone has mentioned, position the setup in vacuum eliminate the uncontrollable air turbulence. Moreover, The initial condition of the system matters since it is a nonlinear system, so try to come up with a setup that put the magnet in the same position before every test will reduce the complexity as well.
Before digital became common, this was all analog. The whole thing is built on a quad op amp. 3 of the amps are PID portions and the 4th sums the currents. Each portion had more control. For example the P factor has gain and offset so the linear portion is balanced with high gain with an offset to target the setpoint. The integrator and diritive has gain as well as tuning for the time constants. The time constants are selected to be complimentary to the mechanical moment of inertia for critical damping. The analog systems when properly tuned perform very well without the lag of A/D and calculation cycles on a processor. This is important when the moment of inertia is low such as the single magnet in the video. Many of these systems are linear for a low noise figure in the system without PWM. Would you like to try to make a video of the analog version of this? I would recommend the Active Filter Cookbook by Don Lancaster for reference in design of the low and high pass filters for the time constants.
Ok, since you insist with the on/off hall sensor madness 😋 here another approach which works, too: switch the magnet on and off in a certain frequency and vary it based on the hall sensor values. The PID can be used to essentially control the duty cycle and fine tunes the attract and release periods. Please note that reliable systems use light though, because the reaction time is much faster and the proportional measurement more accurate. Another project could also include 2 electromagnets pulling on both ends. A practical application would be an accelerometer. Professional ones use 3 axis, 6 magnets and a steel ball, and some of those are filled with a liquid in order to throttle the movement.
Light, and for extreme precision, laser. Hall effect sensors within a dynamic magnetic field are not precise enough to capture only changes from a permanent magnet, when this measurement also depends on electromagnetic fields. This method could only work if the electromagnetic field (EMF) would be static, but it isn't. An EMF builds up over time, time passes when switching on and off. In order to keep on/off times short, no ferromagnetic core would be ideal, but event then there are slopes depending on the inductance. So if you forget about sensing magnetic fields and use other means, the suspension could be close to perfect and have no visible oscillation. Light is ideal because the technology available is really fast (see light cables) and even rudimental light traps are way faster and accurate compared to hall sensors. PS: I've been using magnetic elevation in industrial plants. However I am curious if Scott can manage to elevate magnets with an electromagnet using hall effect sensors ... it would prove me wrong, but it is worth to watch :-)
The hall effect sensor glued to the electromagnet might be the problem. I think something like an optical sensor would do the job well. Thanks! I really like your videos!
You can make a nice rail system for trains (or little toys) with this; the rail is made of steel and the electromagnet is on the train, the train hangs down but is attracted to the steel. you can make a propulsion system when you have multiple electromagnets. And when you place this in a vacuum you have a kind of hyperloop train
i really love your videos, always wanted to do more in eletronics and your way of explaning it with these nice colored schematics in action is far more better than just plain theory. i'd love to do a Moodle or Wiki of some sort of all your videos and tutorial (writing it would help me remenber more)
I would switch from digital write to port registers. Digital write is slow and can do strange things long enough for magnets to get out of place and mess up the pid loop as i have discovered in my project. Worked perfect with direct port.
The same could be true of using analogRead vs putting the ADC in free running and directly reading the ADC register. Of course it could also be true that the time to calculate the PID output is too long and a faster micro is required.
PID mainly help account for nonlinear systems. A magnet is non linear in its attraction. Same as inertia of a heavy object is. So just using a simple switch on/off isnt enough to accounnt correctly for error since its a nonlinear function. Thats why PID works for these problems
I think there is a problem with using just one linear Hall effect sensor. The sensor will naturally sense the electromagnet as it switches as well as the neodymium magnet as it changes its distance. If you install two hall effect sensors on each side of the electromagnet then you could use their difference to sense only the magnetic field from the neodymium magnet.
The patreon guided you to a simplified ziegler nichols method, basically, eliminate Ki and Kd, and set Kp to a value, and monitor the sensor with an oscilloscope, lf the wave form's amplitude rises, decrease Kp , if the amplitude decays, increase Kp, try as hard as you can to get a sin wave, that 1 second you reached was almost it, at this point the Kp value is Ku (ultimate gain), then you use Ku value in ziegler nichols equations to derive Kp, Ki and Kd. Fine tuning is another thing. Edit: the equations are really simple, one or two multiplication at most :p
Can this method be used for slow reacting outputs like temperature? Im trying to tune my PID for my temperature control system. Trial and error takes too long. TOO LONG!
@smeezekitty You toss Ki and Kd only at first, so you'd have only one variable to worry about(Kp), which after trial and error give me Ku, i then use Ku to get the exact Kp, Ki and Kd.
@Rodney Yruretai believe it does, trialing three variables could take alot of time and might never work, trialing only Kp at first and using the oscope as a reference can be done quickly
I think the reason a larger mass of magnets is more stable could be due to the fact that you increased your electromagnet capability. To see if that's true try decreasing the peak current to the coil while using smaller magnets. A larger mass dampens out the instability. Also try to remove the D (derivative) portion of your PID controller. I've experienced instability when adding this term when the value is not calibrated properly. Sometimes analog hardware is the right tool for the job.
What also could help is using a high voltage zenerdiode as flyback diode for the electromagnet. Higher voltage = faster discharge of the electromagnet. If you have a slow discharge the magnetic field will also slowly decrease when the elktromagnet is supposed to be off. Might make it more stable ;)
I think you will have better luck if you use a wider electromagnet. There's more "buffer" if you will and it will give you more of a cushion in your P values. When you look at most of the levetators out there the controller magnet is always wider than the floating magnet.
Maybe the problem is the lateral oscillations, vertically it work well but when it moves horizontally the sensor detect fakes measures because the moving magnetic field of the magnet is changing, and the fake measures take out of set point the system
I might have this wrong but that long ferromagnetic rod might have a higher moment of inertia than your other magnet configuration types thus it doesn’t want to oscillate as much. The magnetic field lines are also different (this case the poles have a smaller area) thus giving the circuit a more precise signal on the Hall effect sensor an easier job to do
If you add another e-magnet under the permanent magnet so that when the permanent magnet falls, the other magnet pushes it up, this will create an ocilation
i think this the community tab you mentoned about :--- 1.(6:05)Derivative controller is actually based on the rate of change of ERROR to be precise/correct (in control systems), de(t)/dt, not rate of change of actual value 2. Kd factor not Kp at 6:10 BTW a grt idea for giveaway and i ddint knew you had covered PID of control systems
Hi Scott, as mentionend to the last video I build such a system long time ago (without a Microcontroller). These days I just had 3 potis to adjust the K* values, which worked pretty good. So my hint would be to use 3 potis on ADC channels to adjust the values simply with a screedriver, not having to run though a build cycle. Hope this helps!
Hey Scott! The sensor in your setup is the weak spot - since it changes the output not only due to magnet movement, but also when you change the current in the coil. I have instructed a student project with the same topic, you can see how we solved this problem with 2x hall sensors: /watch?v=1JjDcn8fHO0 Hope you'll make your prototype work!
hah, here you are, I saw your another video before this one. i read also the comments with pid controller, but for magnetic levitation, it's better to use z-transform, or n-order discrete controller.
Hey, I'm not sure if anyone has mentioned this or if you knew this already but I noticed at 7:25 that the PID values had decimals. I was working on a PID project for one of my classes and one of the guys in my group recommended not using decimals due to something about the language that Arduino's are coded in. I'm still getting the hang of coding and I forget what his exact explanation was but when we changed the values, we got immediate results. Maybe you can try that if you haven't already.
Use MATLAB to tune ur pID controller... there u dont evn need the system characteristics you can jst enter ur response type and sampling time ... it will automatically give u values of Kp Kd and Ki automatically
@@rauankaldybaev4770 or you could actually study the PID controller and use a proper method(like nichols ziegler) and not a stupidly slow manual calibration/or an unnecessary complex method..
Nice project please let me know what did you use for feedback for the system.if you haven t use any thats the main reason for not levitating .you must have a sensor that determines the exact position of the magnet.(maybe a camera).plus if you use a camera you can change the magnet without changing the pid values.
You just need more electromagnets to create a magnet free core. The core's diameter should be larger than the to be levitated magnet. And use a h-bridge to create an alternating field. Like this : as the magnet flips you should also flip the polarity of the electromagnet. It should work.
Have you tried to use the Gyro mechanism and the high EM voltage generator, to forcefully spit electrons downward, with large caps? Some people on RUclips have done something similar and need improvement.
Hey Scott!! When you build your projects how do you plan it??? How do you know that this frame should be 10 in by 6 in or this piece should be this size so it all fits together, I struggle with that!!
One of the problems you are facing is that the system is non linear. The force weakens with 1/r^2. PID controllers can do a lot... but controlling more complex non linear systems sometimes requires a non linear controller. (I'm not saying, this system can't be controlled by a PID though)
You are right, lets not forget the dead time induced by the arduino and its calculation time. PID is very old and extreamly outdated. This system won't be robust at all too.
Matthew Maxwell-Burton I wouldn't go as far too say PIDs are outdated =D Depends on the field of work and what you are trying to do. But you are right, nowadays there are way more options that sometimes have quite good self tuning as well. But I agree with the dead time part! I imagine that's also why the longer magnet worked better. It made the system slower and thus the dead time of the arduino had less of an effect
Chiller3k I have gotten around similar non-linear issues in the past by applying an appropriate equation between the pid output and the actual control element and achieved reasonable results. I tend to agree though, the deadband will be a significant issue, maybe, just for fun, implement in analog form, it’s just a few opamps and a handful of components....
Haha i was joking a bit, but my prof at uni hates pid controllers. His phd was on control theory. Yes the deadtime does not suit a pid controller. You could always implement a smith predictor. Which would help a lot ! No point going analogue nowadays, control theory has gone a long way since. I which he'd brake out the simulink.
Just a completely random thought... Is the housing of the electromagnet steel? If so, then the magnet may reach a "point of no return" if it is pulled too high. This may also explain why a longer, thinner magnet is more stable as the mass is more but the top surface area is lower than that of a magnet of the same mass. ...I might be totally wrong, but this was just a thought that popped into my mind.
Scott, you should get into fpv quadcopters. Right up your alley. Especially when you smoke the flight controller, because you could actually fix it instead of just replacing it.
Had a similar set up. I found in some forum that the Hall effect needs to be positioned a few (1-2)mm away from the electromagnet to get it stable. Don’t know why it worked. It just did.
Another way to do this, is sensing the position with a light and a photoresistor or phototransistor. I get Much more control range and stability than with magnetic flux sensors.
Get a Bluebird pid controller and look at its software. It has an automatic K value determination algorithm. If you can add this to your ardruino, you should be able to have it automatically do this for you!
First of all, my advise: do not use side-code on such simple but sensitive stuff, like PID-controllers. This realization of PID have no winding compensation. I.e. when kP kD values are big enough it is happened magnet is fully on or fully off (PWM at it's max or low value), which means you cannot make it more "ON" or more "OFF" than it is. In this periods the load above is begins to move, until it reaches the point, where, according to kP and kD, the output power should return back to intermediate values. But at that period of time, where power was maxed out, the integral component continued to accumulate the error. So it's have a much bigger value that it should have, and magnet generates bigger and smaller force than it required. So, the solution is "unwinding" - i.e. stopping to calculate integral value, when control is maxed out. Brett Beauregard's PID realization does not do it.
I would really like to make my own 100N electromagnet . Can you please give an idea on how to make it (what wire? dimensions? wiring? material?) ? Please , help. Thanks
Hey Scott... again nice video. For a basic understanding I'm agree with you, but I hope there will come more videos about PIC. Like...scoping set and act values to improve pic values. Keep on going dude. Thumbs up
Why don't you add another hall effect sensor at the bottom and whenever the magnet comes near the bottom hall effect sensor it activates the external interrupt of the arduino to activate the electromagnet to pull the magnet towards itself.
Maybe include a smith predictor if you can describe your system precise enough. This would solve the issue of the dead time your system needs to react.
Pulling the mass against gravity is much difficult rather than pushing it upwards i think because there are two out of controls points,completely stuck and fall down.When pushing it there is no chance to go higher from a certain distance but it needs to maintain equal distance in the center so it needs multiple magnets.
There system on which you are trying to apply the PID isn't linear. Which is also why the PID doesn't work, since it is used only for linear ones. Try using a fuzzy controller.
Hi, I am not a PID specialist, but I suspect that gluing the sensor right on the electromagnet may be the source of some instability, because the sensor is exposed to two variable fields, as well as some interactions between the neodymium magnets and the coil of the electromagnet. This has all the features of a chaotic system, including non-linear feedback. You might want to place the sensor underneath the neodymium magnets, or use a photocell instead of a hall effect sensor.
Good luck!
You may not be a PID specialist but you are special because you know what you are talking about. Great points.
what photocell sensor can work variating the output?? i have searched a lot but just found on/off type... not ideal for these aplications of positioning.
Shielding the HALL sensor on the backside with mu metal can also help, as well as moving the HALL sensor off to the side of the metal core of the electromagnet where the field from the electromagnet is less concentrated. A bar electromagnet is also helpful and should give you more distance as some of your field lines are going to take the path of least resistance and go nearly straight across the gap between the elctromagnet north and south pole, although if the HALL effect sensor is placed in the right spot between the north and south pole you may get them to zero-out their effect on the HALL sensor, not sure on that one though.
You are correct, in those kind of systems where the feedback is non-linear (changed by multiple effects other than the levitating magnet) completely changes the dynamic model of the system, that will lead to unstability when the control signal aka the electromagnetic force applied by the electromagnet, will change the feedback dramatically, thus will lead to a situation that the controller thinks that the magnet position changed much. So it will try to compansate that big change which will result in a bigger control signal which causes a bigger feedback change even tough the magnet hasn't moved much. and this goes on and on... So the control signal will be affected by this problem more and more after a certain time system will go unstable. Instead of hall sensor, a distance sensor could be used. Anyway, Great work. !
I was also wondering if you could simply consider the contribution of the magnet as a function of the current supplied to it. And then you just subtract this value from the value given by the sensor. The function could be determined experimentally.
Lesson learned here: As long as you have enough power and the right components, it's all in the programming.
This kind of systems is nonlinear and the controller can really struggle to stabilize the system around an equilibrium point. However, Two nested (inner and outer) loops can improve the performance much more.
Walid Issa typically nested loops require another input. One slow and one fast input. It is non linear so I think he'd need to linearized the pv or cv before feeding it into the pid algorithm
Maybe a sensor which indicates the vertical distance of the magnet from a certain spot in the structure?
He should use a filter in the system so that unwanted frequencies can not get through.
@@Pablososki14...With as much resolution as possible.
You are wrong, a PID controller can be used to control a non linear- non stable transfer function.
In high performance applications, the way magnetic levitation is performed is by using two control loops. You have an inner control loop using typically a PI controller that regulates current (you need current sensors) into your RL load (electromagnet). You then have a an outter control loop that regulates position typically using a PID controller with a low pass filter on the derivative term. Your sensor reads in position which goes through your PID controller... the output of this motion controller is a force command. This force command is then inverted into the corresponding current needed to produce that force. This current command is then fed into your inner loop controller which regulates your current to the desired value. The desired current flows and produces the force commanded by your PID position controller and the overall loop is closed. Tuning the current regulator is pretty simple... using pole-zero cancellation, you set kp = L * w_b and ki = R * w_b where R and L are the resistance and inductance of your electromagnet respectively and w_b is the desired bandwidth of your current controller in rad/s. Tuning the position controller is a little more involved as you must move your unstable RHP pole into the LHP. Although tuning can be done manually, it is very difficult as you're trying to make an inherently unstable system stable. Frequency domain methods usually work really well for tuning it. Cheers!
From a mechatronics student- inertia, drag and friction all help stabilise the system which utilises a PID.
The reason why a "bigger" magnet had more stability is that it had more mass, thus it was less prone to sudden position changes due to its greater inertia. This way you can slip out of complicated automatic control systems calculations and simplify experimental PID method. I think that (instead of adding additional magnets to the elongated structure which changes the field's geometry) you should try attaching non-magnetic material to the bottom of the magnet, as a weight.
Lead is easy to melt/ shape, it has brutally high density and it is a diamagnetic. You could maybe try experimenting with small lead pellets, sticking them to the bottom of the elongated magnet until you hit the required weight for approximated parameters.
Interesting points on 1) and 2)
Greeting GreatScott!, I have seen a lot of giveaway events, but by asking participants to find and publicly expose own mistakes in a giveaway, this is my first time. Salute your humility and efforts in doing better in educating people.
Below are the mistakes I have found:
1) You shouldn't be gluing your hall effect sensor to the electromagnet. The sensor should be 'focus' on detecting the magnetic field strength of the magnets without being affected by the electromagnet. In other words, during automatic control, you are changing the gain of the electromagnet, the distance you desired is no longer 700mV. The way you did causes the control system to be non-linear and time-varying.
2) SS49E, not SS49A
3) Hysteresis, not hysterisis
4) Derivative controller is actually based on the rate of change of ERROR to be precise, de(t)/dt, not rate of change of actual value (mentioned at 6:04). It sounds the same and intuitively no difference, but the rate of change of error and rate of change of actual value is totally two different things.
5) And of course, at 6:05, df(t) / dt, not df(x) / dt
6) At 6:10, Kd factor not Kp.
I am not sure what type of mistakes you want (minor or major?). If I need to choose only two, I will choose (3) and (5) mistakes since they are obvious in your video.
And I hope the following will be helpful to everyone who are interested in control system engineering:
- Normally, people use displacement sensor to do positioning of magnetic levitation (maglev) system.
- Maglev system is a highly non-linear system, using merely conventional PID controller is never sufficient to control. Classical control (PID controller is in this section) emphasizes on LTI system, which LTI stands for linear time-invarient.
- I believe that the performance of the MOSFET is non-linear. In other words, the supply voltage and the lifting force is not directly proportional, thus non-linear. Two ways of solving this problem - first, identify the LTI range of the MOSFET and make sure your system works only within that range, second, accept the non-linearity and uses a controller that works with non-linear properties, for example, Fuzzy-Logic controller (FLC).
- At 7:21, the tuning method is belongs to Ziegler-Nichols tuning method. Such tuning method is easy to be implemented, and unfortunately causes it to be 'exploited' and 'abused'. The tuning method by the original author/creator emphasizes that such tuning method is only applicable to first-order plus time-delay system (FOPDT). Maglev is indeed not one of them. But still, people are using it everywhere for all kind of system without actually understand the tuning method's requirement.
- At 7:25, I have never seen such high Ki is required for a system. I think eventually, you are implementing I controller instead PID controller, which is why it still works (and even better) and you got it theoretically correct - it will never last forever.
I am extremely welcome to any feedback regarding what I've posted here. Anyway, I am a control student who self-fund for my own study and researches (sadly no free education at all in my country). I only has a DSO138 oscilloscope on my workbench and wanted to upgrade since long time ago, so hopefully I get to win this giveaway.
Awesome dude, mechatronic student here, we see some control engineering but what you said is awesome
Scope the magnet current vs. PWM. Your freewheeling diode will keep the current flowing for a while after voltage is removed, so you may need to subtract a time offset from your PWM setting to help stabilize response.
First of all you need to identify your system in order to know if it is a first order, a second order system or even higher, from that you will be able to get the correct values for the three parmeters using the appropriate methods. Mathematics are mandatory for the PID controller designing if you want to get better results. Please consider make more videos about this topic it is really interesting and helpful.
Or don't, since you obviously don't know how to use a PID..
I Really enjoyed the idea of applying principles of PID to this project. You made the explanation of a PID controller very simple and easy without delving into mathematical jargon, the kind we used to endure in the old days. And .... thanks for the JLCPCB link.
Ha ha, so right...."the kind we used to endure in the old days." Excellent
I have been watching you videos for a while now and I find them really informative and intriguing. The fact that you also show things and projects that didn't work out as expected or didn't work out at all ( while many other channels just fake it for views) is what makes you stand out. It gives us insight for what to look out for and how to avoid them. Hope to see more great content from you. Kudos.
I made this project totally with an analog circuit. It was difficult but I managed to move the setpoint without shutting down the magnet. Is an amazing project.
This is fantastic using the hall effect sensor. Excellent.
You should consider that switching on and off by itself changes readings from hall effect sensor
The mistakes are :
Hysterisis is actually hysteresis and you said Kp factor the Kp factor is used in the proportional term while you were talking about the Kd factor which is used in the derivative term :D Awesome video, I had to learn about this in Uni 2 years ago it would be easier if I had this video at that time :D
Hi, I tried your methods in my Lab. It is super unstable, you're right. But I fixed it. What I did was change the shape of the levitating body. I cut out a piece of circular light weight cardboard and attached it to the magnet. Like this:
-----()------
Now the magnet rarely topples or falls down, because it is hard for the levitating body to topple side ways.
Your idea works, it just needed a little mechanical touch to it.
Excuse me, do you have the arduino code for this levitator?
Automatic Control is tough stuff. Hats off, man.
incredibly interesting project. I barely understood any of it and was completely engrossed =)
Either a faster microcontroller or an analog op-amp PID controller would probably work out well. Tuning an analog PID controller would not be as easy as simply changing constants though. (Instead requiring changing component values, variable capacitors and pots would probably make this easy)
Even better: use a fast comparator like the lm319 (or a newer high speed comp)
PID tuning is definitely an art that takes time to master. When you get comfortable try your hand at servo systems. While they are more expensive than steppers, they are far superior in some applications.
6:02 df(x)/dt? Integrating a positional function with respect to time? I don't think your IV is x here. Shouldn't that be df(t)/dt?
Yes, mistake of mine. it is df(t)/dt. Sorry.
I give all of you a like as a support
one fundamental issue with your setup (and in fact all electromagnet setups) is that the attractive force varies linearly with coil current, but is inversely proportional to the square of the separation distance between the coil and the target magnet! So, increasing coil current by say 1amp, might be enough when the magnet is close, but not nearly enough when it is far away! That square term means as the magnet approaches the coil, the current in the coil must fall with the square of the rate of change of distance! The two step (bang-bang) controller works better because the inductance of the coil effectively stores energy, and that energy is then set by the average duty cycle of the output. With its higher gain (max on, or max off) and faster loop (less time between changing the state) that system works better than a slow, poorly tuned PID. If you want to use a PID, then two options are possible, 1) non linear gains, or (easier) 2) a feed forward table of duty cycle values. Populate that table with the duty cycle that just balances the magnets mass at each distance away from the coil. That open loop feed forward table means the PID then just has to mop up the error (in fact, you'll find a simple P controller will work) as the intrinsic phase lag of the I term has been removed!
Max Torque Thats right! Also because of the integral process you do better if you tune a PD controller. That means set the Ki to zero!
Hi, I study control systems for a living. The system you described can never be truly 'stable' from a single loop PID. What you need is a cascaded PID. The first loop should look at the derivative of position of the magnet, and the outer loop should look at the position of the magnet itself.
what you mean is control both the position and velocity of the magnet, correct?
St0RM33 Well, correct in a way. A cascaded controller would mean you have one loop taking in magnet position and outputting velocity, which is fed into another loop that takes in velocity and outputs electromagnet output. :)
Schön zu sehen, dass auch Andere damit Probleme haben .-)
I would like to be as smart at electronics as you are! I kind of understand just enough to watch and enjoy.
the problem of this sytem is that it's not a linear system, but a non-linear one, what means you can't use linear control techniques to control it. Also PID linear tuning method like ziegler-nichols won't work with a non-linear system (a PWM control, for instance).
I have seen several explanations of a PID controller, but this one is the best.
It's even better than the one by @AndreasSpiess.
And that is an achievement !
Another GreatScott moment !
This is was one of my favorite videos you've made. Good explanation of PID controllers. Thanks!
I think a faster controller might help. And also, as someone has mentioned, position the setup in vacuum eliminate the uncontrollable air turbulence. Moreover, The initial condition of the system matters since it is a nonlinear system, so try to come up with a setup that put the magnet in the same position before every test will reduce the complexity as well.
Before digital became common, this was all analog. The whole thing is built on a quad op amp. 3 of the amps are PID portions and the 4th sums the currents. Each portion had more control. For example the P factor has gain and offset so the linear portion is balanced with high gain with an offset to target the setpoint. The integrator and diritive has gain as well as tuning for the time constants. The time constants are selected to be complimentary to the mechanical moment of inertia for critical damping. The analog systems when properly tuned perform very well without the lag of A/D and calculation cycles on a processor. This is important when the moment of inertia is low such as the single magnet in the video. Many of these systems are linear for a low noise figure in the system without PWM.
Would you like to try to make a video of the analog version of this? I would recommend the Active Filter Cookbook by Don Lancaster for reference in design of the low and high pass filters for the time constants.
Ok, since you insist with the on/off hall sensor madness 😋 here another approach which works, too: switch the magnet on and off in a certain frequency and vary it based on the hall sensor values. The PID can be used to essentially control the duty cycle and fine tunes the attract and release periods.
Please note that reliable systems use light though, because the reaction time is much faster and the proportional measurement more accurate.
Another project could also include 2 electromagnets pulling on both ends. A practical application would be an accelerometer. Professional ones use 3 axis, 6 magnets and a steel ball, and some of those are filled with a liquid in order to throttle the movement.
What would be a better alternative to the hall effect on/off madness?
Light, and for extreme precision, laser. Hall effect sensors within a dynamic magnetic field are not precise enough to capture only changes from a permanent magnet, when this measurement also depends on electromagnetic fields. This method could only work if the electromagnetic field (EMF) would be static, but it isn't. An EMF builds up over time, time passes when switching on and off.
In order to keep on/off times short, no ferromagnetic core would be ideal, but event then there are slopes depending on the inductance.
So if you forget about sensing magnetic fields and use other means, the suspension could be close to perfect and have no visible oscillation. Light is ideal because the technology available is really fast (see light cables) and even rudimental light traps are way faster and accurate compared to hall sensors.
PS: I've been using magnetic elevation in industrial plants. However I am curious if Scott can manage to elevate magnets with an electromagnet using hall effect sensors ... it would prove me wrong, but it is worth to watch :-)
The hall effect sensor glued to the electromagnet might be the problem. I think something like an optical sensor would do the job well. Thanks! I really like your videos!
You can make a nice rail system for trains (or little toys) with this; the rail is made of steel and the electromagnet is on the train, the train hangs down but is attracted to the steel. you can make a propulsion system when you have multiple electromagnets. And when you place this in a vacuum you have a kind of hyperloop train
i really love your videos, always wanted to do more in eletronics and your way of explaning it with these nice colored schematics in action is far more better than just plain theory. i'd love to do a Moodle or Wiki of some sort of all your videos and tutorial (writing it would help me remenber more)
I would switch from digital write to port registers. Digital write is slow and can do strange things long enough for magnets to get out of place and mess up the pid loop as i have discovered in my project. Worked perfect with direct port.
+extraace I used the port registers. Look closely.
The same could be true of using analogRead vs putting the ADC in free running and directly reading the ADC register.
Of course it could also be true that the time to calculate the PID output is too long and a faster micro is required.
Oh yeah I see it now. Looked through it again. I missed that screen snapshot .
I must be learning, I was half way there with the PWM suggestion. I'm crediting your excellent teaching style :-)
PID mainly help account for nonlinear systems. A magnet is non linear in its attraction. Same as inertia of a heavy object is. So just using a simple switch on/off isnt enough to accounnt correctly for error since its a nonlinear function. Thats why PID works for these problems
I expect this time you make new project but you completed your previous project. that is awesome
I think there is a problem with using just one linear Hall effect sensor. The sensor will naturally sense the electromagnet as it switches as well as the neodymium magnet as it changes its distance. If you install two hall effect sensors on each side of the electromagnet then you could use their difference to sense only the magnetic field from the neodymium magnet.
The patreon guided you to a simplified ziegler nichols method, basically, eliminate Ki and Kd, and set Kp to a value, and monitor the sensor with an oscilloscope, lf the wave form's amplitude rises, decrease Kp , if the amplitude decays, increase Kp, try as hard as you can to get a sin wave, that 1 second you reached was almost it, at this point the Kp value is Ku (ultimate gain), then you use Ku value in ziegler nichols equations to derive Kp, Ki and Kd. Fine tuning is another thing.
Edit: the equations are really simple, one or two multiplication at most :p
Why toss out Ki though? Having a Ki means you have to worry about setting the center point precisely
Can this method be used for slow reacting outputs like temperature? Im trying to tune my PID for my temperature control system. Trial and error takes too long. TOO LONG!
@smeezekitty You toss Ki and Kd only at first, so you'd have only one variable to worry about(Kp), which after trial and error give me Ku, i then use Ku to get the exact Kp, Ki and Kd.
@Rodney Yruretai believe it does, trialing three variables could take alot of time and might never work, trialing only Kp at first and using the oscope as a reference can be done quickly
I'm using PID library by Brett Beauregard and It doesn't respond to just Kp with both Ki and Kd at 0. Any suggestions? Thanks for the help, brother.
I think you have to make part 3 to fix issues
You can try the Matlab PID Tuner. You give the Voltage and the Distance as a plot and it spits you the KKK factors
Awesome.. watching an object levitating is satisfying..
You are modulating the voltage, I think you should wire the the MOSFET to modulate current instead!
I think the reason a larger mass of magnets is more stable could be due to the fact that you increased your electromagnet capability. To see if that's true try decreasing the peak current to the coil while using smaller magnets. A larger mass dampens out the instability. Also try to remove the D (derivative) portion of your PID controller. I've experienced instability when adding this term when the value is not calibrated properly. Sometimes analog hardware is the right tool for the job.
Awesome
Great learning
Thanks for sharing
I wish I had teachers like you..
What also could help is using a high voltage zenerdiode as flyback diode for the electromagnet. Higher voltage = faster discharge of the electromagnet. If you have a slow discharge the magnetic field will also slowly decrease when the elktromagnet is supposed to be off. Might make it more stable ;)
I think you will have better luck if you use a wider electromagnet. There's more "buffer" if you will and it will give you more of a cushion in your P values. When you look at most of the levetators out there the controller magnet is always wider than the floating magnet.
i dont understand some times but i keep watching ur videos because they are intersting and i learn something new every video u release
Happy to hear that. That is what I am trying to achieve.
GreatScott! Well ur doing a great job well done
Maybe the problem is the lateral oscillations, vertically it work well but when it moves horizontally the sensor detect fakes measures because the moving magnetic field of the magnet is changing, and the fake measures take out of set point the system
I might have this wrong but that long ferromagnetic rod might have a higher moment of inertia than your other magnet configuration types thus it doesn’t want to oscillate as much. The magnetic field lines are also different (this case the poles have a smaller area) thus giving the circuit a more precise signal on the Hall effect sensor an easier job to do
If you add another e-magnet under the permanent magnet so that when the permanent magnet falls, the other magnet pushes it up, this will create an ocilation
i think this the community tab you mentoned about :---
1.(6:05)Derivative controller is actually based on the rate of change of ERROR to be precise/correct (in control systems), de(t)/dt, not rate of change of actual value
2. Kd factor not Kp at 6:10
BTW a grt idea for giveaway and i ddint knew you had covered PID of control systems
You got a good handwriting mate.
I am always wondering how many textmarkers you need per video. Since their tip gets dity by marking black liner
Finally, the basic electronic video has been release
Hi Scott, as mentionend to the last video I build such a system long time ago (without a Microcontroller). These days I just had 3 potis to adjust the K* values, which worked pretty good. So my hint would be to use 3 potis on ADC channels to adjust the values simply with a screedriver, not having to run though a build cycle. Hope this helps!
Hey Scott!
The sensor in your setup is the weak spot - since it changes the output not only due to magnet movement, but also when you change the current in the coil.
I have instructed a student project with the same topic, you can see how we solved this problem with 2x hall sensors: /watch?v=1JjDcn8fHO0
Hope you'll make your prototype work!
How do you just glue a hall effect sensor to a magnet? Shouldn't the magnet interfere with the sensor?
Georgi Chh It does. The magnets magnetic field interferes with the electromagnets field, depending on the distance.
I know the hall effect sensor has an orientation so it may not respond, but that is a good question..
hah, here you are, I saw your another video before this one. i read also the comments with pid controller, but for magnetic levitation, it's better to use z-transform, or n-order discrete controller.
Hey, I'm not sure if anyone has mentioned this or if you knew this already but I noticed at 7:25 that the PID values had decimals. I was working on a PID project for one of my classes and one of the guys in my group recommended not using decimals due to something about the language that Arduino's are coded in. I'm still getting the hang of coding and I forget what his exact explanation was but when we changed the values, we got immediate results. Maybe you can try that if you haven't already.
Use MATLAB to tune ur pID controller... there u dont evn need the system characteristics you can jst enter ur response type and sampling time ... it will automatically give u values of Kp Kd and Ki automatically
@@rauankaldybaev4770 or you could actually study the PID controller and use a proper method(like nichols ziegler) and not a stupidly slow manual calibration/or an unnecessary complex method..
Nice project please let me know what did you use for feedback for the system.if you haven t use any thats the main reason for not levitating .you must have a sensor that determines the exact position of the magnet.(maybe a camera).plus if you use a camera you can change the magnet without changing the pid values.
But the hall sensor also captures the magnetic field of your electromagnet, how do you cancel that out?
You don't
GreatScott! Thanks for that fast reply, why is it irrelevant?
You just need more electromagnets to create a magnet free core. The core's diameter should be larger than the to be levitated magnet. And use a h-bridge to create an alternating field. Like this : as the magnet flips you should also flip the polarity of the electromagnet. It should work.
Nothing beats PID CONTROLLER!! Nice to know you are still working on magnetic levitation. What's next ???
I don't want to spoil what comes next.
GreatScott! Understood!!!!
Have you got increased subs?? I told my friends to subscribe to your channel.
wait why didnt you try that arduino compatible board? the one with higher output bit rate , etc. ?
Can you re-upload the spreadsheet? I'm curious about the method used
I will admit I truly understood very little of this video. But I have found something interesting to investigate further. Thanks!
Great project! I'd like to build it but the link to the spreadsheet is broken. Could you upload it again please?
Have you tried to use the Gyro mechanism and the high EM voltage generator, to forcefully spit electrons downward, with large caps? Some people on RUclips have done something similar and need improvement.
Help me how to solve these PID equations easily
Thanks
Hey Scott!! When you build your projects how do you plan it??? How do you know that this frame should be 10 in by 6 in or this piece should be this size so it all fits together, I struggle with that!!
Arnav Marchareddy i use a cad i design the layout of the parts with a real world size and build a frame around it
One of the problems you are facing is that the system is non linear. The force weakens with 1/r^2. PID controllers can do a lot... but controlling more complex non linear systems sometimes requires a non linear controller. (I'm not saying, this system can't be controlled by a PID though)
You are right, lets not forget the dead time induced by the arduino and its calculation time. PID is very old and extreamly outdated. This system won't be robust at all too.
Matthew Maxwell-Burton I wouldn't go as far too say PIDs are outdated =D Depends on the field of work and what you are trying to do. But you are right, nowadays there are way more options that sometimes have quite good self tuning as well.
But I agree with the dead time part! I imagine that's also why the longer magnet worked better. It made the system slower and thus the dead time of the arduino had less of an effect
Chiller3k I have gotten around similar non-linear issues in the past by applying an appropriate equation between the pid output and the actual control element and achieved reasonable results. I tend to agree though, the deadband will be a significant issue, maybe, just for fun, implement in analog form, it’s just a few opamps and a handful of components....
Haha i was joking a bit, but my prof at uni hates pid controllers. His phd was on control theory.
Yes the deadtime does not suit a pid controller. You could always implement a smith predictor. Which would help a lot ! No point going analogue nowadays, control theory has gone a long way since. I which he'd brake out the simulink.
Curious. Can you please point to some of the other more robust alternatives?
Just a completely random thought...
Is the housing of the electromagnet steel? If so, then the magnet may reach a "point of no return" if it is pulled too high.
This may also explain why a longer, thinner magnet is more stable as the mass is more but the top surface area is lower than that of a magnet of the same mass.
...I might be totally wrong, but this was just a thought that popped into my mind.
Scott, you should get into fpv quadcopters. Right up your alley. Especially when you smoke the flight controller, because you could actually fix it instead of just replacing it.
I'd watch that.
Perhaps the EMF of wires near is a problem?
Had a similar set up. I found in some forum that the Hall effect needs to be positioned a few (1-2)mm away from the electromagnet to get it stable. Don’t know why it worked. It just did.
4:16 hysterisis -> hysteresis, 6:11 Kp->Kd factor
Another way to do this, is sensing the position with a light and a photoresistor or phototransistor. I get Much more control range and stability than with magnetic flux sensors.
Get a Bluebird pid controller and look at its software. It has an automatic K value determination algorithm.
If you can add this to your ardruino, you should be able to have it automatically do this for you!
First of all, my advise: do not use side-code on such simple but sensitive stuff, like PID-controllers.
This realization of PID have no winding compensation.
I.e. when kP kD values are big enough it is happened magnet is fully on or fully off (PWM at it's max or low value), which means you cannot make it more "ON" or more "OFF" than it is. In this periods the load above is begins to move, until it reaches the point, where, according to kP and kD, the output power should return back to intermediate values.
But at that period of time, where power was maxed out, the integral component continued to accumulate the error. So it's have a much bigger value that it should have, and magnet generates bigger and smaller force than it required.
So, the solution is "unwinding" - i.e. stopping to calculate integral value, when control is maxed out. Brett Beauregard's PID realization does not do it.
the derivative in 6:04 should be df(x)/dx or df(t)/dt
also,can you introduce the ziegler-nichols method?
Oh boy, you are right.
I can see this channel reaching 1m subs
I would really like to make my own 100N electromagnet . Can you please give an idea on how to make it (what wire? dimensions? wiring? material?) ? Please , help.
Thanks
Just one look at all you videos will make anyone an electronics expert.
You didn't add gravity in as a factor, or momentum?
Can you please give us the link for PID calculation again as the previous one is not working ? And also the coding.
Hey Scott... again nice video. For a basic understanding I'm agree with you, but I hope there will come more videos about PIC. Like...scoping set and act values to improve pic values. Keep on going dude. Thumbs up
Why don't you add another hall effect sensor at the bottom and whenever the magnet comes near the bottom hall effect sensor it activates the external interrupt of the arduino to activate the electromagnet to pull the magnet towards itself.
@06:04 should be df(t)/dt; @06:14 should be Kd (diagram is correct, voice-over refers to Kp the P constant)
Maybe include a smith predictor if you can describe your system precise enough. This would solve the issue of the dead time your system needs to react.
Pulling the mass against gravity is much difficult rather than pushing it upwards i think because there are two out of controls points,completely stuck and fall down.When pushing it there is no chance to go higher from a certain distance but it needs to maintain equal distance in the center so it needs multiple magnets.
If the magnet were to be kept rotating, would there be some kind of gyroscopic effect that could help increase stability?
The only thing you have after this, is to make a new DIY Or Buy episode, comparin' what worths for an electromagneticaly-elevated rotational display
at 0.54 diode leg is broken at 4:16 hysterisis hysteresis at 6:11 Kp Kd factor
You shouldn’t place the hall effect sensor anywhere near the solenoid! Place it below the magnet instead!
Hey! If you want to make this even better, you could use a phase-lead compensator!
There system on which you are trying to apply the PID isn't linear. Which is also why the PID doesn't work, since it is used only for linear ones. Try using a fuzzy controller.
I have many cameras which i extracted from old mobiles. So can i directly interface them with arduino and raspberry pi module?
Please reply or make a video on it.
How about using two or even four electro magnets? (Top,bot,right,left) creating a void in the middle...