i thought pid was though but when i say your video i just understood it very well waiting for the next video on pid and also want a video with arduino and l298n motor driver.the same algorothim
@KASTUDIOkanzalhaqa2 жыл бұрын
Your efforts, your work,can be seen in us.
@RobotResearchLab2 жыл бұрын
Thanks a lot for this.
@steveh2433 Жыл бұрын
Great Video😀Has made understanding PID programming really easy
@akarshtechshooter81934 жыл бұрын
can we implement PID for sharp turns, chess boxes, discontinues lines. Is PID restricted for curves smooth performance ???
@RobotResearchLab4 жыл бұрын
PID will work for sharp turns however, you won't know what it's reaction will be because it's going to be dependent on the readings from the sensor. So, if you have a left and right, it may go right sometimes and it may go left other times. If you want to make a decision at a turn or intersection then you would do something like what I do in this video kzbin.info/www/bejne/iGK4fpdne713rbc Let me know if this helps.
@nhatpham57979 ай бұрын
hello, thank you for your lecture, can I ask you about this PID algorithm but with the motor running backward? I still can't do it
@rock12234 жыл бұрын
Thanks for all PID videos Sir 😍
@RobotResearchLab4 жыл бұрын
Thanks for the support
@ninhtrieu9731 Жыл бұрын
Can I use TB6612fng to control? The line I sensor in the middle receives a white line, the other 2 on each side receive a black line. I use TCRT5000, thank you very much.
@RobotResearchLab Жыл бұрын
Sorry for the late reply, you could use the TB6612fng motor driver to control the motors. Almost any motor driver would work as long as it handles at least two motors.
@usuariogenerico24 жыл бұрын
Why didn't you use the Integral term? And also, why your KD is zero? Thank you very much for this explanation!!
@RobotResearchLab4 жыл бұрын
I didn't use the Integral term because it's generally not needed for a simple line follow and it adds a lot of complexity because you have to pay attention to overflow and other aspects. I set KD to zero when I tune the PD algorithm because it's more difficult to tune P and D together. By setting it to zero it multiplies away the D calculation. Once I get a good line follow with only P, I will then start adding a D value and adjusting it. If I tried to set both P and D at the same time, I would never know for certain if the problem was P or D so always set one at a time. Then you can adjust them slightly later once they've all been added. Thanks for watching!
@usuariogenerico24 жыл бұрын
@@RobotResearchLab undestood! Thanks
@usuariogenerico24 жыл бұрын
@@RobotResearchLab Sorry to ask you again, but, do you think that, if I implement a full PID controller on my line follower, it will have a good raise on stability?
@RobotResearchLab4 жыл бұрын
@@usuariogenerico2 I'm not sure what you mean but "raise on stability" but if you are just doing a line follower on a simple track it's possible a full PID would be better but again, the I term isn't necessary for simpler applications. It helps if one motor is significantly weaker than another, if there are hills, if the surface changes causing more or less traction. Basically the I term helps with external influences.
@Mr0neShotAway5 жыл бұрын
These videos are great! Could you please make a video showing your approach with very sharp/acute and 90 deg angles? Also, how to sense color with multiple color sensors with a single Arduino/mC. Thanks a lot for the information!
@RobotResearchLab5 жыл бұрын
Thanks, I'll add it to my list, unfortunately I'm long overdue for a video but just haven't had the time. When you say 90 degree turn are you talking about only one turn or like a T or cross where there are multiple directions at 90 degrees?
@Mr0neShotAway5 жыл бұрын
@@RobotResearchLab What i mean is this: robotics.stackexchange.com/questions/9728/how-to-check-for-a-sharp-angle-with-a-line-follower
@RobotResearchLab5 жыл бұрын
@@Mr0neShotAway Sorry, I didn't get notified of this comment for some reason. Off the cuff I would say you could try to build some intelligence into your program so if it loses the line it remembers which sensor last saw it so it knows to keep turning in that direction until getting back to the line. Although, I may not be understanding your issue exactly as it's difficult without videos of the problem. You could also try to use the QTR library, just set it up with a 2 sensor array and the rest should work the same. Also, I just created a video on programming a color sensor that I'll be posting soon but your comment mentions "multiple sensors with a single Arduino". The video only covers using one sensor, are you talking about using multiple color sensors on the same pin? If not then you could use the same code to run one and just modify it to read a second one (maybe that's what your needing help with, copying and modifying code for one sensor to work with more than one?)
@romejilfredlaguidao7624 Жыл бұрын
Hello, sir. May i ask, what is the problem with my line following robot because the left gear motor is not running and the right one is running. My components are Arduino Uno, L298N, and the QTR-8RC SENSOR ARRAY. Also, i use 12V battery.
@gowrishankar7011 Жыл бұрын
Great video good explanation.. I have a doubt y we need d term?
@ascrolpatil61544 жыл бұрын
HELLO SIR . How to use counter in a pid code and how to stop a robot at the end of the track ?
@RobotResearchLab4 жыл бұрын
Working on it, hopefully it will be up soon, thanks for the suggestion.
@ascrolpatil61544 жыл бұрын
@@RobotResearchLab Also it is possible to share the code of maze solver Robot using pid ?
@RobotResearchLab4 жыл бұрын
@@ascrolpatil6154 I will add it to my list, the line counting video should be up soon so keep an eye out.
@RobotResearchLab4 жыл бұрын
As requested... a video on counting lines, let me know if it helped you or if I'm missing something. Thanks kzbin.info/www/bejne/iGK4fpdne713rbc
@ascrolpatil61544 жыл бұрын
@@RobotResearchLab Yeh Thankyou a lot.. I will try it
@Thinkdifferentsagnic3 жыл бұрын
instead of using constrain can we just write this?- if((MAX_SPEED+adjustment)>255) {driver.setMotorAPower(MAX_SPEED);} else {driver.setMotorAPower(MAX_SPEED+adjustment);} if((MAX_SPEED-adjustment)
@RobotResearchLab2 жыл бұрын
The code you wrote is basically the same as the Arduino source code for constrain so yes. You have a typo in your first if statement, it should set the motor power to 255, not MAX_SPEED. Here's the actual source from the Arduino core library, it might look confusing if you aren't familiar with ternary operators. Constrain() just makes the code look simpler since it only uses one line of code but in the background it is the same. #define constrain(amt,low,high) ((amt)(high)?(high):(amt))) A lot of the Arduino functions are like this, they are just ways of simplifying code making it easier for people to learn how to code. Good catch. If you're ever interested in learning how other functions in Arduino work, you can use the search field in the github repository here github.com/arduino/ArduinoCore-avr
@Thinkdifferentsagnic2 жыл бұрын
@@RobotResearchLab Thank You Sir
@alltop17211 ай бұрын
1) What i have to do to replace the motor driver with L298. 2) If i want to use TB6612FNG then will it work with the same library of TB67H420TBG or i have to make anything change. and what's that? please help sir🙏
@jovangarcia29353 жыл бұрын
hello sir. can i use qtr-md-05rc sensor array for this project? thank you!
@RobotResearchLab3 жыл бұрын
Sorry for the delay, yes you can use any QTR sensor array you want. You just need to modify the code so it knows how many sensors you have. And you'll have to recalculate your "goal" and "pid" values. For example, you'll need to change NUM_SENSORS to 5, and adjust the array of pins they're attached to. Then for the goal, I can't recall if I covered the math in the video but you have 5 sensors so your readings will be between 0 and 4000, so to have a goal of center, you'd want to use a goal value of 2000 (which will be under the third sensor). Then for your initial P value, you'll want it a bit larger so that 4000*P equals your max motor speed... so if you're using a library with motor speeds 0-100 that would be about 100/4000=~0.025 or if your motor speeds are 0-255 that would be 255/4000=~.0063
@jovangarcia29353 жыл бұрын
@@RobotResearchLab i've watched your motor driver video. im using l298n motor driver. what would i do? ill just replace the object with l298? btw thanks for the reply and help!
@RobotResearchLab3 жыл бұрын
@@jovangarcia2935 That's exactly right, just replace the object declaration with your motor driver type. So, if you're using the L298 you would use this line L298 driver(3, 4, 5, 6); Where 3 and 4 are pins for AIN 1 and 2, 5 and 6 are for BIN 1 and 2. So just change those to whatever pins you are using, be sure they are PWM pins. It also assumes that you pull the enable pin high. There are two ways to hook up an L298 and the way the library expects it is to always have the enable line high, then provide a PWM for the AIN1, AIN2, BIN1, and BIN2 pins. The other way to hook it up requires 6 pins so I did it this way to require less pins but still get forward and backward motion. Also, I got your message from my contact page, thanks, I am glad I'm able to help. Unfortunately I don't have much time these days to post videos but I almost always have time to respond to comments so I try to continue helping in that way. Thanks for your support!
@jovangarcia29353 жыл бұрын
@@RobotResearchLab Thank you sir!
@keshavshanmukhanathane3500 Жыл бұрын
One doubt!!! Is this path dependent or path independent? Can this code be run for other lines?
@RobotResearchLab Жыл бұрын
This is path-independent. All the code is doing is trying to stay on a line. Therefore, if there are tees or intersections, it may make a left turn one time, and another time it might make a right turn. With intersections, it generally goes straight since the line is going to give you a center-weighted value. It depends on how the robot approaches the tee or intersection at that specific time.
@hadwart Жыл бұрын
sir you have my 1 subscribe. Your video absolutely saves me ass lol
@joegabriel80212 жыл бұрын
hi can u suggest the code when l293d motor shield is used
@RobotResearchLab2 жыл бұрын
I use a library I wrote. I prefer this library because it will work no matter which motor driver you use, and if you change motor drivers, you only have to change one line of code, the rest is the same. With that said, here's the library, there is no example for the L293 chip but if you look on the first page in the README it shows how I change the DRV8835 code to work on L293 so there is code pasted right in the README. github.com/mcc-robotics/Dynamic_Motor_Driver Let me know if you have issues.
@godgajet6763 Жыл бұрын
how can i do this with 5 tcrt array?
@shafiqalom84084 жыл бұрын
Awesome...♥️ What should I change in the code, 1) if White line onto back background only or (black+white) line with opposite background comes randomly? How to change Calibration then? 2) If one side of line follower track remain dark 🌃 weather but other side remain in sunlight ⛅ then how to calibrate line follower?Can you make such type of line follower video?
@RobotResearchLab4 жыл бұрын
These are great ideas for new videos, I'll add them to my list. Just to give you some immediate feedback though. For issue number 1, one solution would be to monitor the track using the sensors individual readings. So something like "if more than 4 of 8 sensors see black, assume we have a black background with white tape but if more than 4 of 8 sensors see white, assume we have a white background with black tape" Then depending on the situation, you can pass a variable into the readLine function to tell it if you're following a black or white line. With the new library there are two different functions 'readLineBlack' and 'readLineWhite' so just use whichever you need to based on your if statement. For issue number 2, one solution might be (not sure this would be enough) to run two calibration phases. Run a calibration in the sunny area and one in the dark area, the calibration won't get reset between the two phases so you don't need to worry about that. Ideally you want to calibrate your sensors in every environment that your robot will see so while it might work just calibrating in the sunny or the dark area, it would be best to calibrate once in each area. This could be as simple as just running the calibration, then putting a ten second pause until another calibration loop to give you time to move to the other section of the track. A better solution might be to use a button though. Also, and probably more importantly, you should try to shield your sensor from any sunlight, even putting a "wall" of electrical tape around your sensor is better than letting the sun interfere with your readings. The sun has a lot of IR light so it can wash out your sensor values so much that you'll never get good enough readings to read the line. I hope that helps you out until I can get time to come up with some videos on this, thanks for watching.
@teodora88904 жыл бұрын
Hello thank you for your video I would like to know if this algorithm will work with a feedback mechanism too, like an encoder for example? Also if my robot is meant to go up a slope, should I include the I term for better stability or is it not necessary?
@RobotResearchLab4 жыл бұрын
In this particular video I'm using one of the motor libraries I developed. 100 in this case means percent of power so when I say 100 I mean full power. Typically power ranges from 0 to 255 which I thought might be confusing so I developed my library using 0 to 100 for the power range.
@RobotResearchLab3 жыл бұрын
Yes, this algorithm will work for pretty much any case where you have an output and a goal setpoint, you just have to come up with the right way to convert the error into an adjustment value. For encoders, what I have done in the past is set the goal to some specific distance for each encoder (like say, the goal is to be 1 meter from where I currently am) and the PID would return the current distance from the start point. Then you can compare the current position with the goal. The other way you can do this is to have a setpoint be a speed (meters/second). You can take a very quick read of the encoders to see what speed is being recorded currently, then you can adjust the motors to maintain a specific speed. The most complicated way to do this would be combine both, you set a distance and a speed, the PID monitors the speed and you just simply keep checking the distance traveled since the start of the movement until you hit the desired distance. As far as needing an I term for an incline, it depends on a lot of variables. If your motors are weak and need more power to get up the incline the I term might be needed to get up the incline. But, it's also possible that you would be on the center of the line and so PID returns an adjustment closer to zero, in this case the only way to know if your robot is moving up the hill would be to use encoders. This is probably a lot to process in one response so let me know if you have any questions on this response. Good questions though.
@harshitsrivastava55594 жыл бұрын
Can I use arduino for the same code??
@RobotResearchLab4 жыл бұрын
Yes, the same code will work for an Arduino, but you'll have to hook it up to the correct pins for the Arduino board you choose. Like making sure you choose the correct pins for PWM outputs (for the motors). Also, be aware that the QTR-8RC uses 8 digital pins which is quite a few pins from the Uno and Nano boards, and if you use QTR-8A you won't have enough analog pins for all 8 sensors. It can still work but you'll only be able to use 6 sensors (I would leave the outside sensors disconnected). For using Arduino, I would recommend the Mega board as it has enough analog and digital pins but it's a little bulky and expensive for what you get but if you must use Arduino that's what I would choose.
@buileanh41365 жыл бұрын
can i download these two library that you used on arduino app
@RobotResearchLab5 жыл бұрын
You can't download them from the Library Manager in the IDE but you can download them from github and then add them using the Library Manager under "Add Zip File" The motor driver library can be found here github.com/mcc-robotics/Dynamic_Motor_Driver The QTR Sensors library can be found here github.com/gberl001/qtr-sensors-arduino
@harshitsrivastava55594 жыл бұрын
Can I use 6v n20 motor for this??
@RobotResearchLab4 жыл бұрын
You would need to use a different motor driver for 6V motors, technically you could run 6V motors at 12V but they will likely burn out much faster than normal. So, you'd need to change the 12V regulator to a 6V regulator that handles the right current draw, then you'd have to have a motor driver that supports 6V motors for the amount of current you need to draw. I chose the 12V because they draw less current for the same power since the voltage is twice that of 6V. It's harder (and typically more expensive) to find components for higher current motors.
@eljeryseif85503 жыл бұрын
where is the code ?
@RobotResearchLab3 жыл бұрын
There's a link in the description... apparently my site is down but I'll work on getting that fixed robotresearchlab.com/2019/03/13/build-a-custom-pid-line-following-robot-from-scratch/
@capistor14 жыл бұрын
hi..i have a question. in your code you wrote "/* * Initialize our driver with the pins (motorA1, motorA2, motorB1, motorB2) and we're assuming: * Motor A = Left motor * Motor B = Right motor * The pins here would map to AIN1, AIN2, BIN1, BIN2 respectively */ L298 driver(3, 4, 5, 6);" you are using two motors here but you haven't defined any pin for PWM/ENA or ENB...so how do you actually control the speed?
@RobotResearchLab4 жыл бұрын
Sorry, I didn't see this comment until just now. There are two main ways to program an L298 driver, you can use 4 PWM and 2 digital or 4 digital and 2 PWM. If I recall, the way I programmed the L298 in the library assumed that you would have the enable lines pulled high and the 4 pins for the two motors would all be PWM. What this does is it has the motors always enabled since they're pulled high with a wire, and then the speed and direction is controlled by the INA1, INA2, etc lines. For example, to go one direction you would send a PWM signal to INA1 and drive INA2 low, then to go the other your would do the opposite. To brake you would send the same PWM signal to both though I believe I found through research that it was not that simple so a true "brake" cannot be performed on the L298 so you should only expect a "coast". The other way to program this would be to use digital pins on INA1 and INA2 to control direction (setting one high and one low) and then use PWM on the Enable lines ENA to control the speed. I believe when I wrote the library I wanted the 298 to be easily interchangeable with the DRV8835 since both were commonly used by students in my class. That is why I wrote it in a way that used four PWM pins rather than 4 digital and 2 PWM (because the DRV8835 used 4 PWM pins)
@antonioluiz17264 жыл бұрын
thanks, i will recommend you to my friends!!!
@RobotResearchLab4 жыл бұрын
Antonio luiz thank you for the support, I’m taking a break during the pandemic but rest assured I’ll be creating content again soon.
@errazvanoficial535 жыл бұрын
Hi, can you make a PID code based only on analogWrite for the motors? I use a L298n mini driver and a QTR-8RC Poolu line sensor
@RobotResearchLab5 жыл бұрын
Sure can, I'll add it to my list, it's been a while since I uploaded a video so I'm hoping to get one done soon. Thanks for the feedback
@errazvanoficial535 жыл бұрын
@@RobotResearchLab Do you have some time for make it sooner? My competition is tomorrow
@RobotResearchLab5 жыл бұрын
@@errazvanoficial53 That's a little too soon ha ha. It's going to depend on how you hooked up your L298 but I can try to help out in a comment here. The library I'm using will work for the L298 series motor drivers, just use the exact same code but instead of creating a TB67H420G object create an L298 object and adjust the pin values as needed. I actually wrote up an example on the README in the library, check it out here and scroll down to read it github.com/mcc-robotics/Dynamic_Motor_Driver If you want to go ahead with using analogWrite() then: OPTION 1: If you have Enable A connected to PWM, then IN1 and IN2 connected to digital, writing IN1 HIGH and IN2 LOW with analogWrite to the Enable pin will power the motor in one direction. Then if you flip the signals so IN1 is LOW and IN2 is HIGH you'll go the other direction. OPTION 2: If you have Enable A connected to digital, then IN1 and IN2 each to PWM you set Enable A to HIGH so the motor is always enabled, then using analogWrite a positive value to IN1 and analogWrite(IN2, 0) will go one direction and set analogWrite(IN1, 0) and a positive analogWrite to IN2 and it will go the other direction. Hope some of that helps, happy coding.
@RobotResearchLab5 жыл бұрын
Just a quick follow up, the proper format would be the following: L298 driver(in1, in2, enableA, in3, in4, enableB) Where in1, in2, in3, and in4 are digital pins and a PWM pin is assigned to EnableA and EnableB Again, I hope this helps.