COMPREHENSIVE: PID CONTROLLER for DC MOTOR with Timer Interrupts and Anti-windup

  Рет қаралды 96,318

GeeKee CeeBee

GeeKee CeeBee

Күн бұрын

Пікірлер: 75
@GeeKeeCeeBee
@GeeKeeCeeBee 4 жыл бұрын
IMPORTANT: If you find this video helpful then please leave a LIKE, SHARE and SUBSCRIBE to support me in making more videos like this. 👍 CODE and SCHEMATICS ARE AVAILABLE HERE geekeeceebee.com/PID%20Controller.html More videos: DC Motor Position Control: kzbin.info/www/bejne/Y4GQZ5WDl7abZ6c
@adrianrawlings2470
@adrianrawlings2470 3 жыл бұрын
Best explanation and demonstration of PID I've seen to date. Thank you.
@GeeKeeCeeBee
@GeeKeeCeeBee 4 жыл бұрын
Code and Schematic are available here geekeeceebee.com/PID%20Controller.html
@user-to9pf7ec7s
@user-to9pf7ec7s 3 жыл бұрын
Great vid, thanks! However the Interrupt service routine for the encoder could be much more simple: use this on one Hall sensor's pin: attachInterrupt(digitalPinToInterrupt(pin), ISR, mode), and the 'mode' should be 'RISING' And to get the direction in the 'interrupt service routine', you only have to check whether the other Hall sensor's pin is HIGH or LOW at that moment.
@boostedbuiltgarage
@boostedbuiltgarage 3 жыл бұрын
Thanks for taking the time to put this together, nice work. (I'll have to watch this a few times to get up to speed haha)
@sanjelly8
@sanjelly8 2 жыл бұрын
This is one of the best explanation for PID, I wish in the future that you add explanations comments to your code, this will be very helpful for Arduino bigenners like me, thanks allot
@GeeKeeCeeBee
@GeeKeeCeeBee 2 жыл бұрын
Thank you. Im glad my videos are helping.
@VPannagS
@VPannagS 4 жыл бұрын
That helps alot... PINS/PID/Time Interrupts/some basic rotational mechanics stuff...
@hamedshamsikhani3345
@hamedshamsikhani3345 Жыл бұрын
Hello sir. Thank you for sharing this really helpful. I test my motor and the results are different. But very unclear result I have.
@supersuperintendant
@supersuperintendant 3 жыл бұрын
Thanks for sharing your considerable skill with the world.
@GregerOlofsson
@GregerOlofsson 3 жыл бұрын
Thanks, this is a great base for my lathe motor controller I've had on the back burner for quite some time.
@forgedabstract7288
@forgedabstract7288 4 жыл бұрын
OMG this LIFESAVER video! I have literally the same components as you
@juanramirezjardua2082
@juanramirezjardua2082 4 жыл бұрын
Thanks, great video, clear explanation. I'll use your code in my project for a ros driver for controlling 4 dc motors that received the cmd_vel command.
@HaiderAli-xr9nm
@HaiderAli-xr9nm 3 жыл бұрын
The video was really helpful. I have one query: I want to track Theta, how can I put the values of the desired theta in code, I mean in formula or in array form please describe with a short overview example?
@sebaschtl9710
@sebaschtl9710 3 жыл бұрын
Thank you for your very good explanation. And thank you for not using a librarys : ) use ≠ understand
@nissan2060
@nissan2060 4 жыл бұрын
@GeeKee Ceebee first off great informative video overall; thank you! I am uncertain about some things you explained though...at 10:45 when you're checking the status of the encoder pins to determine clockwise or counterclockwise direction, you're saying check if pinB is high and pinA is low to constitute an upcount and every other case is downcount...it makes sense for the portions of the signals that are clearly pinB high and pinA low...but what about right after that condition when the controller sees pinB high and pinA high - it would downcount (undo the upcount it just did)? What if the motor is idle or stalling with either conditions of pinA, pinB both low or one being high the other being low or both being high?
@classtimeoff
@classtimeoff 4 жыл бұрын
you got my like and subscribe. thank you for the project.
@jaisanrj
@jaisanrj 3 жыл бұрын
Thanks for the explanation and demonstration
@hashirwaqar6892
@hashirwaqar6892 Жыл бұрын
at 14:32 u said that 900 is the count/revolution, right? How did u get that value I'm a bit confused? Amazing video btw, thanks a lot!!
@Happymacer_P
@Happymacer_P 8 ай бұрын
Hiya I believe he is using a 900 counts per evolution encoder - ie it is made to cause 900 pulses on its output in one revolution. Number is supplied by the manufacturer.
@davidforrest937
@davidforrest937 4 ай бұрын
I think he's using an "Encoder Metal Gearmotor 12V DC 80 RPM Gear Motor with Encoder for Arduino and 3D Printers" motor specified with 900PPR, but is counting 4 edges/pulse so is actually getting 3600 counts/rev.
@yu-chiwu484
@yu-chiwu484 3 жыл бұрын
what is the ppr for the encoder. Here rising and falling conditions for pinA and pinB are considered. Therefore, is EncoderCount counted 4 times per pulse of pinA and pinB? Does that mean 4*ppr=900?
@lindsaydempsey5683
@lindsaydempsey5683 3 жыл бұрын
Excellent video thank you. I have an application where I'm trying to on control a bypass around a supercharger using a drive by wire throttle body. The controlled parameter is supercharger discharge pressure, which is limited by bypassing an increasing amount of air around the supercharger as engine speed increases. I presume that I can have one PID loop for the pressure control, and a second PID loop that positions the throttle plate to the commanded position via PWM (throttle plate position feedback is via a potentiometer). I presume that is easily accomplished in the Arduino environment. Do you have any comments or helpful hints on that approach?
@gul156
@gul156 4 жыл бұрын
Can you explain the RPM_d formula @ 26:00? Why are you using 5ms (0.005) and 50ms (0.05)? For sure I'm missing something.
@seanmcdonald656
@seanmcdonald656 3 жыл бұрын
Thanks for the great video
@foltranm
@foltranm 4 жыл бұрын
great video, man! thanks!
@praveendhiman16
@praveendhiman16 2 жыл бұрын
Hi Can you please make video for torque and position control of dc motor
@GeeKeeCeeBee
@GeeKeeCeeBee 2 жыл бұрын
There's a position control video on my channel. Im planning on making a video on cascading loop controller for Torque, speed and position in the future
@itsJeewantha
@itsJeewantha 3 жыл бұрын
Hi GeeKee, I'm going to use this with BLDC motor, Can I use the same or What I need to change? Great video btw.
@br2245
@br2245 3 жыл бұрын
Thanks , great lecture🙏🙏🙏
@chickenz4604
@chickenz4604 4 жыл бұрын
Very good
@cheredha
@cheredha 3 жыл бұрын
Thank you
@user-to9pf7ec7s
@user-to9pf7ec7s 3 жыл бұрын
Great vid, I've a question: Whati is the benefit of usint the "time interrupt" instead of telling the program to enter into the PID loop when >50ms elpased from previous entry??? Thanks!
@GeeKeeCeeBee
@GeeKeeCeeBee 3 жыл бұрын
Advantage of timer interrupt is that Arduino is free to do other things while waiting for 50ms. Unlike in delay(50) command, arduino is stuck for 50ms
@user-to9pf7ec7s
@user-to9pf7ec7s 3 жыл бұрын
@@GeeKeeCeeBee I'm not talking about delay(50). But sg like this: if millis() > (PreviousLoopEntryTime + 50){ PreviousLoopEntryTime = millis() Preform the remaining of the loop }
@GeeKeeCeeBee
@GeeKeeCeeBee 3 жыл бұрын
I have not tried that logic but I don't see issues with your code. Also, millis() is based on Timer0 which is pre-configured to count clock pulses every 1ms. Either approach is fine imo.
@kifahzaidan4505
@kifahzaidan4505 2 жыл бұрын
THANKS A LOT CAN YOU PLEASE POST VIDEO FOR THE (CONTROLLING OF DC MOTOR 'ACTUATOR ' PROGRAMABLE POSITION WITH MEMORY BUTTONS USING ARDUINO. BEST WISHES
@davidforrest937
@davidforrest937 4 ай бұрын
@29:53 Why do you advise serial printing inside an interrupt? And @13:57 Why do you use 900 if you are counting the 4 edges of the two pulse trains A & B Most encoder PPR specifications are as the pulses on one channel, to be read as a clock+dir pair on one edge of a clock signal. Counting on all 4 edges is more complicated, but quadruples the resolution. If you're using the 80RPM motor with spec'd at 900PPR and reading all 4 edges, the divisor should be 3600 counts/rev. Using 900 instead of 3600, you are probably getting only 25RPM when you call for 100RPM. At 100RPM it should take 0.6 sec to do a revolution or 1.6 rev/sec, not 2.4sec/rev or 0.4rev/sec like at 31:26.
@jorgeroa6591
@jorgeroa6591 4 жыл бұрын
Thank you brother, good shit
@IchrisiI
@IchrisiI 3 жыл бұрын
awesome !!
@marcelodossantoscoutinho4955
@marcelodossantoscoutinho4955 3 жыл бұрын
Do you think is it possible to model the motor mathematically? I mean, doing a open loop test for example? Then , it is possible to design the PID controller accordingly to the system control theory.
@GeeKeeCeeBee
@GeeKeeCeeBee 3 жыл бұрын
Absolutely! However, you would need several motor parameters such as Torque constant, inductance of the winding, friction, torque speed curve, etc to model the motor. I believe these can be obtain experimentally aswell. Using the state space representation, modelling the whole system with PID is fairly easy.
@chaitanyapatil7513
@chaitanyapatil7513 2 ай бұрын
hey did you make a hardware model of this?
@abhishekbedake2669
@abhishekbedake2669 3 жыл бұрын
Where ur testing the pulse, which software...?
@fatimakaimous4926
@fatimakaimous4926 3 жыл бұрын
hi sir i want to ask u , how u found kp , ki and kd ? can u give me just the idea and thank u for the project
@jaimemartinezdiaz1004
@jaimemartinezdiaz1004 4 жыл бұрын
Cool vid
@thaitoaninh1430
@thaitoaninh1430 3 жыл бұрын
great work thank u so much
@bluebrim127
@bluebrim127 3 жыл бұрын
How can I choose an RPM - say I want to run my motor anywhere from 0-10 RPM and I'd like to choose a single RPM or vary that RPM over time. Where in the code can I adjust that
@sergeihanna8383
@sergeihanna8383 4 жыл бұрын
can I control both velocity and angle in the same time?
@FilmRiggers
@FilmRiggers 4 жыл бұрын
You briefly touched on controlling position instead of speed at 33min. Please can you elaborate a bit more, I didn't quite understand
@GeeKeeCeeBee
@GeeKeeCeeBee 4 жыл бұрын
You would need to create a desired Theta ( desired angular position) trajectory. And the motor will basically track this desired trajectory. So the error becomes Theta desired minus Theta actual( motor angular position). Note that angular position could be in deg or radians, so proceed accordingly. Error = Theta_d - Theta After that tweak the gain values as needed. PI controller should be sufficient. Hope this is helpful :)
@GennaroScarati
@GennaroScarati 4 жыл бұрын
My RPMs are wrong! Where does that 900 come from? How can I fix this problem? On my encoder I can read it gives 11 signals when rotating one circle. Thanks so much for helping me!
@GeeKeeCeeBee
@GeeKeeCeeBee 4 жыл бұрын
Mybad, I missed this topic in the video. Theta = EncoderCount/ CountPerRevolution. In my case, 900 comes from the combination of Encoder's count per revolution (CPR) and motor gear ratio. CPR may be different depending on your motor and encoder specifications. Check your gear ratio, if any, and Encoder CPR. Hope this helps.
@usmanriasat9834
@usmanriasat9834 3 жыл бұрын
@@GeeKeeCeeBee hi if my motor has 11 pulse per revolution (ppr) and gear reduction ratio is 1:34.02 how many counts per revolution (cpr) do i have?
@davidforrest937
@davidforrest937 4 ай бұрын
@@usmanriasat9834 11 * 34.02 = 374 pulse per revolution, but since he's counting 4 edges per pulse, it is 11*34.02*4 = 1496 counts/rev.
@gabrielcucu9361
@gabrielcucu9361 2 жыл бұрын
what the pins would be for arduino nano ?
@marcelodossantoscoutinho4955
@marcelodossantoscoutinho4955 3 жыл бұрын
Where did you buy the motor and motor driver? Thanks
@GeeKeeCeeBee
@GeeKeeCeeBee 3 жыл бұрын
Everything was purchased from Amazon.com
@MasonJarBoy
@MasonJarBoy 4 жыл бұрын
I am trying to control a DC motor using the writeMicroseconds as opposed to having a straight voltage put into like your motor driver function. Do you think this is viable?
@GeeKeeCeeBee
@GeeKeeCeeBee 4 жыл бұрын
I dont see an issue if you're simply trying to run the DC motor, however, if you're trying to implement tracking control on DC motor then it'll probably wont work. Reason is that the encoder and DC motor have to run on the same Timer clock. I believe writemicroseconds use a different clock which wont allow event synchronization. Hope that helps.
@marcelodossantoscoutinho4955
@marcelodossantoscoutinho4955 3 жыл бұрын
Hey sorry for asking, but are you sure the schematic is correct? After I removed the enable jump, the motor doesnt even start.
@GeeKeeCeeBee
@GeeKeeCeeBee 3 жыл бұрын
I pretty sure the schematic is correct. If you leave jumper in then motor should run at full speed (at max supply voltage). In your case, as jumper is removed I would suggest to check your PWM pin and value that your sending. If PWM value is zero then there's no voltage going to the motor.
@pulimisaireddy
@pulimisaireddy 4 жыл бұрын
can please help me to run the motor linearly not in the sine wave.
@David_94
@David_94 4 жыл бұрын
the timer interrupt is used to control the sampling interval?
@GeeKeeCeeBee
@GeeKeeCeeBee 4 жыл бұрын
Yes, that's correct
@ashkanrezaveisi4600
@ashkanrezaveisi4600 4 жыл бұрын
Could you please put the circle photo in your channle Thankyou very much
@sweetali4578
@sweetali4578 3 жыл бұрын
how to contact you
@kionmahuermicio9860
@kionmahuermicio9860 3 жыл бұрын
Like por no usar la librería PID que te hace toda la chamba.
@AhmedTarek-si9hy
@AhmedTarek-si9hy 4 жыл бұрын
can you send me the code
@GeeKeeCeeBee
@GeeKeeCeeBee 4 жыл бұрын
Just added. See description
@ahmedgamal-uh6ik
@ahmedgamal-uh6ik 4 жыл бұрын
source code plz
@GeeKeeCeeBee
@GeeKeeCeeBee 4 жыл бұрын
Just added. See description
@NedSar85
@NedSar85 3 жыл бұрын
Hi, does anyone have a compilation error in the cli() function? it says to me that TCCR1A was not declared...
@NedSar85
@NedSar85 3 жыл бұрын
solved! was using another type or arduino... this works in arduino uno
@vilsondasrapadura7342
@vilsondasrapadura7342 27 күн бұрын
@@NedSar85 oh them im screwed, what type of arduino where you using? im using a esp 12e and i have the same error
DC motor PID speed control
15:29
Curio Res
Рет қаралды 245 М.
I Turned My Mom into Anxiety Mode! 😆💥 #prank #familyfun #funny
00:32
Это было очень близко...
00:10
Аришнев
Рет қаралды 7 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 11 МЛН
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 72 МЛН
Stepper motor PID control using a TMC2209 and AS5600
45:25
Curious Scientist
Рет қаралды 14 М.
PID Balance+Ball | full explanation & tuning
13:13
Electronoobs
Рет қаралды 756 М.
STM32 motor control: PID theory and implementation
10:52
Steppe School
Рет қаралды 17 М.
Hardware Demo of a Digital PID Controller
2:58
Gregory L. Holst
Рет қаралды 997 М.
What Is PID Control? | Understanding PID Control, Part 1
11:42
MATLAB
Рет қаралды 1,8 МЛН
PID brushless motor control tutorial
16:25
Electronoobs
Рет қаралды 474 М.
Encoder con Simulink (MATLAB SIMULINK - ARDUINO)
31:11
Jesus Correa - PLC
Рет қаралды 51 М.
DC motor position control using PID
43:23
Curious Scientist
Рет қаралды 81 М.
PIDs Simplified
13:07
SiieeFPV
Рет қаралды 303 М.
I Turned My Mom into Anxiety Mode! 😆💥 #prank #familyfun #funny
00:32