Reference Language | Libraries | Comparison | Changes
Change the parameters for line following.
Use this function if line-following is not working as expected, or you want to change the robot's speed while line-following.
This function changes the "PD algorithms" that enable to robot to think about what may happen next while line reading. The robot attempts to predict any possible errors on the next reading of the IR sensors, and corrects its movement accordingly by changing the speed of each wheel separately.
See the note below for a deeper explanation.
- KP : int, proportional gain
- KD : int, derivative gain
- integrationTime: int, delay time between each time we run the algorithm in ms
- robotSpeed: int, between 0 and 100, indicating the percentage speed of motors.
Robot.lineFollowConfig(11,5,50,10);//set PID parameters
//pauses line-following for 3 seconds every 5 seconds
In the function, KP helps the robot follow the line, and KD dampens the oscillation of the robot.
To find good values for this, there needs to be some experimentation to find a good pair of values. An example test is listed below :
- Set KP as 5, KD as 0, choose your robot speed. Set intergrationTime as 10
- Run the robot on a line-following track
- If the robot goes off the track, increase KP by 1
- Repeat as long as the robot improves keeping on the line. Stop changing KP when it's no longer improved.
- Increase KD by 1
- Run the robot, note if the robot is waving less
- Continue incrementing KD by 1, until it stops improving.
- When you get the robot following the track without running off the line, you are done with tuning. Take down the numbers so you can use it in the future.
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a
Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.