Now that we have a robot that can proportionally adjust its wheels based on how close/far it is from the wall, we were asked to add derivative control to our robot.
The derivative control simply accounts for the difference in error between the current and last reading. Did the last adjustment make much of an improvement in correcting the error? How fast is the error being corrected?
Note: The changes from the previous example having been bolded.
void followWallBeta() {
delay(500); //wait for us to lift our finger off the button.
addCSVHeader = true; //for logging data
leftMotorSpeed=leftMotorDefaultSpeed;
rightMotorSpeed=rightMotorDefaultSpeed;
long error;
long previousError=0;
while (digitalRead(LineSensor)==HIGH) {
long pingTime = ping();
if (pingTime!=0) {
currentPingDistance = microsecondsToCentimeters(pingTime);
error = wallDistance-currentPingDistance; //error
long deriv_error = error - previousError;
previousError = error;
rightMotorSpeed=rightMotorDefaultSpeed+(Kp*error)+(Kd*deriv_error);
leftMotorSpeed=leftMotorDefaultSpeed-(Kp*error)+(Kd*deriv_error);
} if (pingTime==0) {
currentPingDistance = microsecondsToCentimeters(pingTime);
}
rightMotorSpeed = constrain(rightMotorSpeed, 40, 255);
leftMotorSpeed = constrain(leftMotorSpeed, 40, 255);
Forward(0);
if (useSave) saveData(useSave);
delay(100); //only check 10 times a second. :)
}
Stop();
During our runs, we were having a hard time finding what worked best.
Here the robot followed the wall for a while, until it loses sight of the wall and goes crazy.
A video of the above run.
Here, the robot continued to go in circles, getting further and further away from the wall with each spin, and never recovered the wall again.
We didn't take any video of this run.
The high spikes are when the robot loses the wall, turns around in a circle, and then reacquires the wall.
This is a closer look at the above trail before it lost sight of the wall
Changes made today:
It seems that as we increase the Kd value, the robot performs worse.
The Baseline
No Kd value here. Just some Kp.
At the end the robot still seems to lose the wall.