I looked into it a bit more, the disadvantage of this method is that it is only looking for encoder A pin rising. This means that wiggling the motor back and forth a little looks like the motor is moving continuously forwards. It also counts more than one step if the input bounces. Instead: checking for all four quadrature transitions fixes these problems and means 4x as many pulses per rotation which means you can be more precise. I added these lines at the beginning: #define readA bitRead(PIND,2)//faster than digitalRead() #define readB bitRead(PIND,3)//faster than digitalRead() I changed the attachInterrupt line so that it triggered on CHANGE rather than rising, and added another line for the B encoder pin: attachInterrupt(digitalPinToInterrupt(ENCA),readEncoderA,CHANGE); attachInterrupt(digitalPinToInterrupt(ENCB),readEncoderB,CHANGE); And I changed the functions triggered by the interrupt to this: void readEncoderA(){ if(readB != readA) { posi ++; } else { posi --; } }
void readEncoderB(){ if (readA == readB) { posi ++; } else { posi --; } } This eliminates bouncing (posi will just count forwards and then backwards with each bounce), increases precision as you get 4x as many interrupts triggered per rotation, and prevents you from 'tricking' the encoder by moving the motor back and forth by a small amount. Credit to Cattledog on the Arduino forums in 2017.
One of the best videos I have come across. The combination of the hardware setup and linking this to the block diagram and finally linking block diagram to code is an inspiring idea.
Thank you Rokonuddin. I'm very pleased that the format resonated with you. When I finished the video I was sure that I had covered too much. But I think that it can be worth the effort when you actually want to understand the details of how a system works.
Hi @@curiores111 , the scope of this video is perfect. If you had a feeling that it was too much, perhaps for a beginner it may be too much. For someone that already has a basic understanding and some experience coding it's absolutely perfect!! So well done!! Thank you so much.
I have to commend you on the best tutorial I have seen on motor control using PID! As others have mentioned you are clear concise and to the point. Your animations and diagrams support your lecture perfectly. Your progressive coding makes it easy to understand your logic flow....given the real world, converted to math, and then to software. Kudos!
at 2:26 trajectories are wrong. When she said clockwise, it meant counter-clockwise. When she told counter-clockwise, it meant clockwise. We can see the results at 2:47. When she turns the arrow clockwise, the number goes to negative and vice versa. I'm fan of your channel by the way :)
Good observation. The gearbox actually reverses the direction of travel, so it's true that it triggers in the opposite order compared to the encoder by itself.
The video is very well produced, the code explanation is amazing and made me (as a mechanical engineer with rudimentary understanding of motor control) feel capable of implementing this, well done!
Thanks Lucas! I'm glad you feel that the level is right. It is hard to justify putting all that code in from a youtube video perspective, but when it actually comes down to implementing it yourself, it's probably the most important part.
@@curiores111 You managed to keep the (usually boring) code exposure very well connected with the practical application so it wans't boring anymore hehe
Nice combination of electronics, maths and programming. I'd come across those PID values in my Sitech motor controller and now I know what they are ! Thanks for clear presentation and explanation.
When my professor told me he can´t tell me how to implement pid into a microcontroller I thought it must be a very hard thing. Finally I came across your video and this was poor luck because my search on youtube gave nothing like yours. So thank you very much for taking your time to explain all of this. I like control theory because it´s hard to understand but If you understand it makes you proud.
Sounds like my profs. :D Thank you so much for your comment. Your comment is literally the reason I make videos. I agree. Control theory is challenging, rewarding, and exciting.
Theory is dry but what you show makes more fun at least :D Hey I have an idea do you think an encoder attached to a bldc motor would allow me to set the motor speed perfectly with your pid method ? I have such a motor left from an old hdd and I would play around with your code. I only knew how to do it with op amps but changing code is faster than changing capacitors and resistors.
As a hobbyist I was struggling to get position control working on diy toy robot build, and this video has cleared a lot of questions for me. Thank you for the share!
I just discovered your channel -- it's fantastic! I appreciate your clarity, pace, and your choice of what to focus on in each video. I hope there will be more videos in the future!
Yeah, that's "math talk". More specifically numerical methods. It's kind of funny how educational discipline vernacular tends to have a divergent evolution. Makes vertical disciplines like control theory even more difficult for a beginner (as if they weren't hard enough already).
Extremely well done. Have been utilizing an adaption of this PID control loop for leveling. Instead of using an encoder I pull data from a MPU6050 using the MPU6050_light library usually included in the Arduino IDE. Then Set the target to 0. It works really well!
My encoder is not giving values or giving unexpected and illogical values but when I build circuit which also includes the output Z wire and use a library Buttonfever then it gives appropriate values. Whats the reason?
Sounds like your encoder probably has a different interface than the one I used. Certainly, there's no compatibility guarantee with electrical devices -- always consult your datasheets (-- or, a dedicated tutorial, if available, is always useful).
There's an update to the tutorial to include the volatile directive and the ATOMIC_BLOCK macro. These prevent potential issues with the interrupt. See this page for an example: www.arduino.cc/reference/en/language/variables/variable-scope-qualifiers/volatile/
I so appreciate that you wrote the code out rather than called library functions - I've been working to control a motor with encoder via an MCU that doesn't work with Arduino IDE so seeing the code written out really helps.
Thanks for mentioning this Darren. Originally I thought I would be criticized for not using the library. Surprisingly, I haven't seen that yet. I'm pleased that the presentation I chose was suitable for your work. Good luck with your project.
You got the same voice tone of a lady on "Element 14" . Although it's a VERY PRECISE tutorial thank you and keep going , I'll test this with a infrared encoder
For single motor operation, HBRIDGE should be pulled high, then the single motor + should be connected to both A+ and A-, and - should be connected to both B+ and B-
Thanks so much Luis. I am planning to do more videos. Feel free to make a request if you come a cross a topic that you feel needs a better explanation than what is currently available.
Good catch Ducksaws! I can barely even see that The reason is that I've jumped the A and B outs. Putting the driver in this parallel configuration allows the driver to handle twice the current. You can see the connections on the Pololu page: www.pololu.com/product/2999 www.pololu.com/product/2999#lightbox-picture0J8698
@@ImminentDingo Well, when they're jumped you're actually applying the same signal to both pins. So in a sense you can ignore them, but in another sense you're not ignoring them, simply simultaneously activating them. Note that you don't have to set things up this way, I just happened to do this because it's an option for the motor driver I was using that worked well for my application.
When I try to measure position, turning the magnet gives me negative values of position no matter which way I turn the magnet. I spin it CW and itll be like -20 and then spin it CCW and itd go down to -40
The positions refer to how many steps the encoder has taken. How that actually translates into the angular position of the motor shaft is determined by (1) how many encoder steps per unit of angle measurement there are and (2) what the gear ratio of the motor is. You can find that information on the spec sheet for the motor.
Speaking of it, there is a little 'mistake' in your integrator. There is a 'wind up' effect because it keeps integrating, even if the actuator is already at max power. If you 'clamp' the integrator, when u is 255, there will be significantly less overshooting :)
I am trying to figure out how DJI control its gimbals because it doen't look like it uses servos to move the motors. Are they using a micro controller like an aurdiuno to control the gimbal motor?
that was amazingly informative thank you very much for this magnificent work, and the way the overshoot was eliminated was surprisingly accurate, I'll make sure to subscribe.
7:50-7:55 e(t) has dimension V, integral e(t)dt has dimension V*sec, derivative de/dt has dimension V/sec. Is it correct to add values with different dimensions ?
There's nothing "wrong" with adding two signals with different dimensions. On the other hand, when you add two signals with different dimensions, a question arises: what does the result "mean"? Also, it creates a possible issue: if you rescale either, the sum is no longer the same. So it generates a potential inconsistency, and certainly a likely source of confusion. It's certainly a nice discussion topic. As far as this video is concerned, those questions are a non-issue, because e(t) and de/dt, and integral of e(t) dt are *not* added to each other. Instead, they are linearly combined with coefficients kp, ki, and kd. Since those coefficients are arbitrary, they would naturally encode the units required to make the dimensions consistent. Assuming a dimensionless u(t), that implies kp has units of 1/[e(t)], the integral has units of 1/([t][e(t)]), and kd has units of [t]/[e(t)], where [t] represents the units of t and [e(t)] represents the units of e. So, they do exist, although admittedly typically ignored and potentially generation a source of confusion at some point for someone trying to re-use coefficients.
I used a PID controller to make a self-balancing robot but the motors I used were stepper motors, though I achieved the most precise positioning yet the implementation was very complex. The stepper motors puls timing is exponential where the PID was failing
oh yeah sounds difficult. I think usually people do the balance bot with DC motors. If you use steppers probably have to tweak the control algorithm a bit.
wow, what a magnificent combination of hardware and software to explain the PID control. It's was a dream to understand it, and I got it now. How CAN THANK YOU💞
hi I see that the encoder is connected to 5V of the Arduino why the motor driver is not connected to 5V of Arduino?! i used to do that with normal DC motor
Friend , arduino can not provide I current for components like motors , servo motors (high Torque) , and some components. The here is connected to a motor drive and motor driver is connected to external power supply . U can only power only low power consuming sensors . What will happen if u connect motor drive to 5v pin of arduino??? Answer: here the pulse coming out of the motor will be disturbed . U can not accurately measure the position of the Shaft. Why the pulse coming out from motor is disturbed ?? Because the motor drive is connected to arduino the motor will take the current from arduino due to high consumation of current the voltage get disturbed there will be fluctuations in voltage , so the pulse is also noised out . That's why using external power supply
Great video, but im kinda stugling at position measuring maybe because im using diferent wiring ? Ii dont knom, but there is only 0 at the serial monitor. could someone help me ?
Wouldn't motor power ground lead be connected to second pin A- rather than B-? Also, don't you need VCC +5VDC out from Arduino to VCC pin on motor controller to power controller?
pwmVal sets the "speed" (really, it sets the duty cycle of the PWM signal). You can control the RPM well with position control by writing some wrapper code around the PID control. I did this in another video: ruclips.net/video/3ozgxPi_tl0/видео.html
Excuse me, so in clockwise direction, Is output A before output B or output B before output A ? I got confused in Part 1 and Part 2, they seems not the same
Very nice video, and close to what I'm looking at doing. My plans so far will be with any Arduino board, I'm wanting to have a AS5600 read a direction/step every second and write/save that info, so an average can be calculated for later use. Then once a minute or so read another AS5600 with a Stepper motor and have the stepper match the average direction/steps of the other one.
The first thing I'd try is simply implementing the same feedback loop in terms of velocity and see if that's good enough for your application (this might not work - could be a lot of jitter. There are other more advanced methods that you could try - but it's a good/easy place to start). You can estimate the velocity, the derivative of the velocity, and the integral of the velocity using methods similar to the ones shown here. For example, you could compute the velocity as: velocity = (position - previousPosition)/deltaT where "previousPosition" is the position stored in the previous iteration of the loop.
Excellent, I just finished following your tutorial and everything worked out great. Still playing with the PID values to get the sinus as close as possible to the target but I think the motor just isn't precise enough.
Good work! Using a motor with a higher gear ratio will help with precision. (of course, if you need much better precision a stepper is often a better choice) Adjusting the PID parameters can help, but won't be able to overcome some of the limitations of the motor, as you're finding.
Hello, I have one little problem. Once my motor reaches the target in the serial plotter, the shaft stops rotating. Any idea of why this could be happening? Thank you
This is awesome, and you are a good instructor and a good presenter. Very good content flow esp with lots of diagram & graphics to add with the presentation flow 👍..love it. Thanks for making this tutorial ❤
My dear Curio Res! I don't know how to send the commands to Arduino? Use a potentiometer or other encoder to command the direction and speed of the DC Motor? How do you do it in the movie???
I just assigned a target inside the code. If you want to use a pot or a rotary encoder to set the target, you could (a) connect your rotary encoder/pot to the arduino (b) write code to read from the rotary encoder/pot and (c) set the target based on the value of the rotary encoder/pot
It is a very useful video. Now I want to control a coil motor with a ACS driver. The quarter encoder signal is not symmetrical. Phase A and Phase B is not exactly 90 degree. The ACS driver always meet encoder not connected error. So for a unsymmetrical and not exactly 90 degree dealy encoder, may you suggest a suitable motor driver? Thanks in advance.
I want to control the position of some mini geared motors with quadrature encoders. Can I use this code? I have 4 motors inside a prosthetic hand I am making for my daughter
The code is applicable to any dc motor with an encoder (although there is always potential for some tweaking being required depending on the hardware).
You need a lot of pins to connect 4 motors. You could try a Arduino Mega, but that probably doesn't have a fast enough clock speed to handle the interrupts from all four. You could consider something faster, like an esp32, arduino due, or another arm based microcontroller (there are several made by adafruit).
@@curiores111 Thank you for your reply. Arduino Mega has only 6 digital pins so I can not able to use that. So can I use two Arduino's with two motor controllers or One Arduino due with two motor controllers? I want to use those dc motors for controlling Mecanum wheels. Please suggest an option for that. can I go with raspberry zero? Thank You
neither, this is setting encoder pulses. If you want to set position you use the encoder and motor characteristics, like gear ratio and pulses per rotation. I explain it briefly near the end of another video: ruclips.net/video/3ozgxPi_tl0/видео.html
@@curiores111 sorry that my wrong question I’m working on bionic hand and I use some n20 gear motor with 8838 motor so my question is May you help me about how should be full rotation and full return about motor forward and backward ? Do you have any mail or website for contact with you ? My thank you
Certainly. You can set the target using something like this: docs.arduino.cc/built-in-examples/basics/AnalogReadSerial and then set the target equal to a multiple of the potentiometer reading.
I looked into it a bit more, the disadvantage of this method is that it is only looking for encoder A pin rising. This means that wiggling the motor back and forth a little looks like the motor is moving continuously forwards. It also counts more than one step if the input bounces. Instead: checking for all four quadrature transitions fixes these problems and means 4x as many pulses per rotation which means you can be more precise.
I added these lines at the beginning:
#define readA bitRead(PIND,2)//faster than digitalRead()
#define readB bitRead(PIND,3)//faster than digitalRead()
I changed the attachInterrupt line so that it triggered on CHANGE rather than rising, and added another line for the B encoder pin:
attachInterrupt(digitalPinToInterrupt(ENCA),readEncoderA,CHANGE);
attachInterrupt(digitalPinToInterrupt(ENCB),readEncoderB,CHANGE);
And I changed the functions triggered by the interrupt to this:
void readEncoderA(){
if(readB != readA) {
posi ++;
} else {
posi --;
}
}
void readEncoderB(){
if (readA == readB) {
posi ++;
} else {
posi --;
}
}
This eliminates bouncing (posi will just count forwards and then backwards with each bounce), increases precision as you get 4x as many interrupts triggered per rotation, and prevents you from 'tricking' the encoder by moving the motor back and forth by a small amount. Credit to Cattledog on the Arduino forums in 2017.
Very helpful - This ended up making my code work and support bi-directional control.
YOU ARE A LIFESAVER. THANK YOU SO MUCH.
You can set a interrupt on both pins and use it to access a lookup table. As a bonus, this can achieve full resolution of encoder.
thanks a lot for this!
thank you. my motor driver doesn't have PWM pin it's HW-95 what should i do ?
One of the best videos I have come across. The combination of the hardware setup and linking this to the block diagram and finally linking block diagram to code is an inspiring idea.
Thank you Rokonuddin. I'm very pleased that the format resonated with you. When I finished the video I was sure that I had covered too much. But I think that it can be worth the effort when you actually want to understand the details of how a system works.
Hi @@curiores111 , the scope of this video is perfect. If you had a feeling that it was too much, perhaps for a beginner it may be too much. For someone that already has a basic understanding and some experience coding it's absolutely perfect!! So well done!! Thank you so much.
A couple of months of my graduate course in just 10 minutes! :-D ... Thanks for sharing!
So well done! Saved me a lot of time...
Glad to be of help! And thank you so much, you are far too generous!
Feel like I struck gold finding this video - huge thank you for making it!
Sure, and thanks for stopping by. 😉
I have to commend you on the best tutorial I have seen on motor control using PID! As others have mentioned you are clear concise and to the point. Your animations and diagrams support your lecture perfectly. Your progressive coding makes it easy to understand your logic flow....given the real world, converted to math, and then to software. Kudos!
can't be more grateful to have found channels like this
The near-perfect tutorial. Clear, concise, the animations are fluid and easy to understand, and straight to the point. Nice!
This is a great tutorial: short and very precise explanation, yet covering a vast area on the subject. Pleaee make more videos like this.
at 2:26 trajectories are wrong. When she said clockwise, it meant counter-clockwise. When she told counter-clockwise, it meant clockwise.
We can see the results at 2:47. When she turns the arrow clockwise, the number goes to negative and vice versa.
I'm fan of your channel by the way :)
Good observation. The gearbox actually reverses the direction of travel, so it's true that it triggers in the opposite order compared to the encoder by itself.
This, in comparison with many other videos on the subject, is very well done!
The video is very well produced, the code explanation is amazing and made me (as a mechanical engineer with rudimentary understanding of motor control) feel capable of implementing this, well done!
Thanks Lucas! I'm glad you feel that the level is right. It is hard to justify putting all that code in from a youtube video perspective, but when it actually comes down to implementing it yourself, it's probably the most important part.
@@curiores111 You managed to keep the (usually boring) code exposure very well connected with the practical application so it wans't boring anymore hehe
Nice combination of electronics, maths and programming. I'd come across those PID values in my Sitech motor controller and now I know what they are ! Thanks for clear presentation and explanation.
When my professor told me he can´t tell me how to implement pid into a microcontroller I thought it must be a very hard thing. Finally I came across your video and this was poor luck because my search on youtube gave nothing like yours. So thank you very much for taking your time to explain all of this. I like control theory because it´s hard to understand but If you understand it makes you proud.
Sounds like my profs. :D
Thank you so much for your comment. Your comment is literally the reason I make videos.
I agree. Control theory is challenging, rewarding, and exciting.
Theory is dry but what you show makes more fun at least :D Hey I have an idea do you think an encoder attached to a bldc motor would allow me to set the motor speed perfectly with your pid method ? I have such a motor left from an old hdd and I would play around with your code. I only knew how to do it with op amps but changing code is faster than changing capacitors and resistors.
As a hobbyist I was struggling to get position control working on diy toy robot build, and this video has cleared a lot of questions for me. Thank you for the share!
I just discovered your channel -- it's fantastic! I appreciate your clarity, pace, and your choice of what to focus on in each video. I hope there will be more videos in the future!
Appreciate this Jeff. I am still working on some videos, but it's definitely a challenge to find the time and the right topics.
Whole PID, encoder, Basic control theory with real applications under 10 minutes. Thank you and you are very well on educating.
Does a great job of setting the ground work for "How to control multiple DC motors with encoders".
almost nobody on the internet used the term "Finite difference approximation", saved me a lot of hassle
Yeah, that's "math talk". More specifically numerical methods. It's kind of funny how educational discipline vernacular tends to have a divergent evolution. Makes vertical disciplines like control theory even more difficult for a beginner (as if they weren't hard enough already).
Super clear and straight to the point, I hope you're going to do more of these!
guess I am just a fucking idiot then
@@DarrinSK I know the feeling, but it probably just means you need to start with some other tutorials on whatever part of this seems complicated.
Extremely well done. Have been utilizing an adaption of this PID control loop for leveling. Instead of using an encoder I pull data from a MPU6050 using the MPU6050_light library usually included in the Arduino IDE. Then Set the target to 0. It works really well!
Keep the hard work , I love how you connect the theoretical part with hand on application 😍
My encoder is not giving values or giving unexpected and illogical values but when I build circuit which also includes the output Z wire and use a library Buttonfever then it gives appropriate values. Whats the reason?
Sounds like your encoder probably has a different interface than the one I used. Certainly, there's no compatibility guarantee with electrical devices -- always consult your datasheets (-- or, a dedicated tutorial, if available, is always useful).
@@curiores111 may be. Thanks for your reply
There's an update to the tutorial to include the volatile directive and the ATOMIC_BLOCK macro. These prevent potential issues with the interrupt. See this page for an example:
www.arduino.cc/reference/en/language/variables/variable-scope-qualifiers/volatile/
This page is down, FYI
@@PatchBOTS Ah yes missed that one, still updating the website...
One of the best technical content I've ever seen on youtube. Please keep posting content!
Thank you, friend. I have a couple even more technical videos planned for hardware implementation of controls, so stay tuned.
I so appreciate that you wrote the code out rather than called library functions - I've been working to control a motor with encoder via an MCU that doesn't work with Arduino IDE so seeing the code written out really helps.
Thanks for mentioning this Darren. Originally I thought I would be criticized for not using the library. Surprisingly, I haven't seen that yet. I'm pleased that the presentation I chose was suitable for your work. Good luck with your project.
Thanks for clear presentation and explanation
it is very clear and percise video and let me say ur voice is very comfort to listen to
glad to hear that, and thank you :)
Your RUclips channel has a bright future. Excellent content. Keep up the good work!!
You are too kind. Thank you.
Thanks to Heavens I found you! THIS IS WHAT I TRULY NEED! Thank You SOOOOOO MUCH.
oh wow! a future Multi-million subscriber channel in it's infancy! what an honor! Amazing content!
😳
Hi Curio, theses videos are amazing! Please keep up the great work!
you are great Curio, made a great simple to understand tutorial
Appreciate that ❤️
Are those Fritzing diagrams?
using this method-- how to set a zero position to start with?
much appreciations for the content and the editing!
You got the same voice tone of a lady on "Element 14" . Although it's a VERY PRECISE tutorial thank you and keep going , I'll test this with a infrared encoder
one of the best tutorials I have ever watched. Have you thought of doing an MPC video?
You're too kind, thank you. Yes, I have, among a couple others. Thank you for the suggestion.
Nice narration - watched it a long time ago but made more sense this time as I have learned more !
glad to hear that! there's a lot to unpack here and experience is everything...
How can we change position value to radian or degrees?
Thanks!
How generous! Thank you so much Squeaky Cheex 😉😄
For single motor operation, HBRIDGE should be pulled high, then the single motor + should be connected to both A+ and A-, and - should be connected to both B+ and B-
Impressively well done tutorial. I hope you find the motivation and time to do more of these
Thanks so much Luis. I am planning to do more videos. Feel free to make a request if you come a cross a topic that you feel needs a better explanation than what is currently available.
at 3:01 why is the motor red/black connected to the controller on A+ and B- instead of A+ and A-?
Good catch Ducksaws! I can barely even see that The reason is that I've jumped the A and B outs. Putting the driver in this parallel configuration allows the driver to handle twice the current. You can see the connections on the Pololu page: www.pololu.com/product/2999
www.pololu.com/product/2999#lightbox-picture0J8698
@@curiores111 oh ok. In this case do you still only need to apply signal to pwm a, ina1 and ina2 and can ignore the b pins?
@@ImminentDingo Well, when they're jumped you're actually applying the same signal to both pins. So in a sense you can ignore them, but in another sense you're not ignoring them, simply simultaneously activating them. Note that you don't have to set things up this way, I just happened to do this because it's an option for the motor driver I was using that worked well for my application.
@@curiores111 oh I understand. Did not realize what you meant by jumped. Thanks
Tried the same with a stepper?
This is a really great video. Thank you! It's very helpful for my latest project.
very well made video. consise, straight to point, focused, visual and audio on point. very good. edit: subscribed.
When I try to measure position, turning the magnet gives me negative values of position no matter which way I turn the magnet. I spin it CW and itll be like -20 and then spin it CCW and itd go down to -40
7:05
Could you explain what 1.0e6 stand for in deltaT?
1e6 is calculator/programming language speak for scientific notation. In other words, 1e6 = 1*10^6 = 1,000,000
Thank you for the very concise and clear explanation :) really looking forward to use this in my next project.
glad you thought so! and good luck with your next project. :)
What does the output on the serial monitor at 2:48 shows, what unit is the output in? I know it measures distance but what is it actually?
The positions refer to how many steps the encoder has taken. How that actually translates into the angular position of the motor shaft is determined by (1) how many encoder steps per unit of angle measurement there are and (2) what the gear ratio of the motor is. You can find that information on the spec sheet for the motor.
Hi, thanks for this tutorial. I have a question. Is there a reason why you didn't use the number of pulses in your calculation
Thank you so much for sharing!!!! Greetings from Panama!!!! 🇵🇦
I do belive you just saved my master thesis...
Glad it helped! Thanks for stopping by.
Speaking of it, there is a little 'mistake' in your integrator. There is a 'wind up' effect because it keeps integrating, even if the actuator is already at max power. If you 'clamp' the integrator, when u is 255, there will be significantly less overshooting :)
I am trying to figure out how DJI control its gimbals because it doen't look like it uses servos to move the motors. Are they using a micro controller like an aurdiuno to control the gimbal motor?
What is DJI?
that was amazingly informative thank you very much for this magnificent work, and the way the overshoot was eliminated was surprisingly accurate, I'll make sure to subscribe.
What happend do if my outputs of encoder print triangles graphics instead of square graphics?
7:50-7:55
e(t) has dimension V, integral e(t)dt has dimension V*sec, derivative de/dt has dimension V/sec.
Is it correct to add values with different dimensions ?
There's nothing "wrong" with adding two signals with different dimensions.
On the other hand, when you add two signals with different dimensions, a question arises: what does the result "mean"? Also, it creates a possible issue: if you rescale either, the sum is no longer the same. So it generates a potential inconsistency, and certainly a likely source of confusion. It's certainly a nice discussion topic.
As far as this video is concerned, those questions are a non-issue, because e(t) and de/dt, and integral of e(t) dt are *not* added to each other.
Instead, they are linearly combined with coefficients kp, ki, and kd. Since those coefficients are arbitrary, they would naturally encode the units required to make the dimensions consistent.
Assuming a dimensionless u(t), that implies kp has units of 1/[e(t)], the integral has units of 1/([t][e(t)]), and kd has units of [t]/[e(t)], where [t] represents the units of t and [e(t)] represents the units of e.
So, they do exist, although admittedly typically ignored and potentially generation a source of confusion at some point for someone trying to re-use coefficients.
I used a PID controller to make a self-balancing robot but the motors I used were stepper motors, though I achieved the most precise positioning yet the implementation was very complex. The stepper motors puls timing is exponential where the PID was failing
oh yeah sounds difficult. I think usually people do the balance bot with DC motors. If you use steppers probably have to tweak the control algorithm a bit.
Excellent Video. It really was what i was searching for!!
wow, what a magnificent combination of hardware and software to explain the PID control. It's was a dream to understand it, and I got it now. How CAN THANK YOU💞
this video is an other level of programming, that make an other challenge and make me better programmer. Thank you very much
how kind. Thank you. I wish you luck in writing many beautiful programs. :)
hi I see that the encoder is connected to 5V of the Arduino why the motor driver is not connected to 5V of Arduino?! i used to do that with normal DC motor
Friend , arduino can not provide I current for components like motors , servo motors (high Torque) , and some components. The here is connected to a motor drive and motor driver is connected to external power supply . U can only power only low power consuming sensors .
What will happen if u connect motor drive to 5v pin of arduino???
Answer: here the pulse coming out of the motor will be disturbed . U can not accurately measure the position of the Shaft. Why the pulse coming out from motor is disturbed ?? Because the motor drive is connected to arduino the motor will take the current from arduino due to high consumation of current the voltage get disturbed there will be fluctuations in voltage , so the pulse is also noised out .
That's why using external power supply
Great video, but im kinda stugling at position measuring maybe because im using diferent wiring ? Ii dont knom, but there is only 0 at the serial monitor.
could someone help me ?
Amazing this is very helpful!
Thank you for this informative video👍
Is there a way to make a s-curve motion for the motor?
Cheers🎉
what happens to the code when you add a gearbox to the motor?
Where I can find the library that is given in the code
Does such a code only work for incremental encoders or can it also work for absolute encoders?
Wouldn't motor power ground lead be connected to second pin A- rather than B-? Also, don't you need VCC +5VDC out from Arduino to VCC pin on motor controller to power controller?
Which part of the function you defined (3:50) sets the speed and how is that adjusted? Also, how accurately can you control RPM using this method?
pwmVal sets the "speed" (really, it sets the duty cycle of the PWM signal). You can control the RPM well with position control by writing some wrapper code around the PID control. I did this in another video: ruclips.net/video/3ozgxPi_tl0/видео.html
Is it possible to have 3 target position for using this code?
Great ! One of the best tutorial on DC motor control. When I run part4.ino, how to close the autoscale in serial plotter?
Excuse me, so in clockwise direction, Is output A before output B or output B before output A ? I got confused in Part 1 and Part 2, they seems not the same
Very nice video, and close to what I'm looking at doing. My plans so far will be with any Arduino board, I'm wanting to have a AS5600 read a direction/step every second and write/save that info, so an average can be calculated for later use. Then once a minute or so read another AS5600 with a Stepper motor and have the stepper match the average direction/steps of the other one.
why do you devide by 1.0e6 ? Where does that come from?
Hi thank you for posting! Would you be able to give me some pointers of how to do PID to reach a target velocity rather than target position?
The first thing I'd try is simply implementing the same feedback loop in terms of velocity and see if that's good enough for your application (this might not work - could be a lot of jitter. There are other more advanced methods that you could try - but it's a good/easy place to start). You can estimate the velocity, the derivative of the velocity, and the integral of the velocity using methods similar to the ones shown here. For example, you could compute the velocity as:
velocity = (position - previousPosition)/deltaT
where "previousPosition" is the position stored in the previous iteration of the loop.
@@curiores111 thanks I'll give that a shot today :)
Excellent, I just finished following your tutorial and everything worked out great. Still playing with the PID values to get the sinus as close as possible to the target but I think the motor just isn't precise enough.
Good work! Using a motor with a higher gear ratio will help with precision. (of course, if you need much better precision a stepper is often a better choice) Adjusting the PID parameters can help, but won't be able to overcome some of the limitations of the motor, as you're finding.
Hello, I have one little problem. Once my motor reaches the target in the serial plotter, the shaft stops rotating. Any idea of why this could be happening? Thank you
If you reach the target, the motor should no longer rotate. Do you expect something else to happen?
This is awesome, and you are a good instructor and a good presenter. Very good content flow esp with lots of diagram & graphics to add with the presentation flow 👍..love it. Thanks for making this tutorial ❤
My dear
Curio Res!
I don't know how to send the commands to Arduino?
Use a potentiometer or other encoder to command the direction and speed of the DC Motor?
How do you do it in the movie???
I just assigned a target inside the code. If you want to use a pot or a rotary encoder to set the target, you could (a) connect your rotary encoder/pot to the arduino (b) write code to read from the rotary encoder/pot and (c) set the target based on the value of the rotary encoder/pot
@@curiores111 Thanks again lovely Jewelry
Nice Detail Explanation . can we change Target RPM when Motor Is the Running condition ?
Helped me a lot. The best video on this topic. Have subbed without thinking. You deserve a lot more audience. Keep going 👏👏👏
Thank you, friend. You are too kind.
If i want the shaft to start at 000 degrees on startup would I need a limit switch to detect 000 degrees?
You need some way to calibrate the starting position... limit switch or otherwise.
@@curiores111 Thanks have it almost hooked up to a nano and l298n motor driver, double checking my wiring.
can we use that on hi torque motor for antenna rotator?
Nice video... Make such videos which gives practical implementation based on Theory.. looking for more videos..keep it up
Excellent video. So much useful information in a very concise delivery.
Thank you for the kind words, Bill.
There is no PWMA input in my motor driver. I am using HW-95 motor driver.
Is there q solution?
Is it ok to IN 1 as PWM and IN(2,3) as IN(1,2)?
Very interesting! If i want to set a speed target, what should i do? Thanks for responding.
Another great video CR, thanks a bunch!
can’t we use BTS7960 motor driver with arduino ?
It is a very useful video. Now I want to control a coil motor with a ACS driver. The quarter encoder signal is not symmetrical. Phase A and Phase B is not exactly 90 degree. The ACS driver always meet encoder not connected error.
So for a unsymmetrical and not exactly 90 degree dealy encoder, may you suggest a suitable motor driver? Thanks in advance.
I want to control the position of some mini geared motors with quadrature encoders. Can I use this code? I have 4 motors inside a prosthetic hand I am making for my daughter
The code is applicable to any dc motor with an encoder (although there is always potential for some tweaking being required depending on the hardware).
@@curiores111 thank you so much
What if the direction changes after encA goes high but before encB goes high? Wouldn't the position get out of sync? How would you reset this then?
how to connect 4 dc motors with encoders with motor driver and Arduino? Or which motor controller do I need?
You need a lot of pins to connect 4 motors. You could try a Arduino Mega, but that probably doesn't have a fast enough clock speed to handle the interrupts from all four. You could consider something faster, like an esp32, arduino due, or another arm based microcontroller (there are several made by adafruit).
@@curiores111 Thank you for your reply. Arduino Mega has only 6 digital pins so I can not able to use that. So can I use two Arduino's with two motor controllers or One Arduino due with two motor controllers? I want to use those dc motors for controlling Mecanum wheels. Please suggest an option for that. can I go with raspberry zero? Thank You
Please do a video using LQR control in arduino! The quality of your explanation would be super!
Thanks for the suggestion!
Excellent ! An objective, clean explanation and good narration as well!
Thank you, Felipe.
according to what we setting target position and what is the position unit for example angle or meter ? i don't un
neither, this is setting encoder pulses. If you want to set position you use the encoder and motor characteristics, like gear ratio and pulses per rotation. I explain it briefly near the end of another video: ruclips.net/video/3ozgxPi_tl0/видео.html
Hello I don’t have pwm pin so what I should to write to analogWrite ? May you help please
no pwm pin?? What microcontroller are you using Mehmet?
@@curiores111 sorry that my wrong question I’m working on bionic hand and I use some n20 gear motor with 8838 motor so my question is May you help me about how should be full rotation and full return about motor forward and backward ? Do you have any mail or website for contact with you ? My thank you
Hi can i use another external potentiometer to give the target ?
Certainly. You can set the target using something like this:
docs.arduino.cc/built-in-examples/basics/AnalogReadSerial
and then set the target equal to a multiple of the potentiometer reading.