For this task, we had to do a number of thing. When the penny drop area was detected, we had to:
void PennyDrop(int cm) {
long now = millis();
Stop(0);
delay(300);
//back it up, just back it up
leftMotorSpeed=-leftMotorDefaultSpeed/1.3;
rightMotorSpeed=-rightMotorDefaultSpeed/1.2;
Forward(0);
leftTick=0;
while(leftTick<10 && !lost);
if (lost) return;
Stop(0);
delay(300);
//turn to face penny drop
leftTick=0;
leftMotorSpeed=leftMotorDefaultSpeed/1.3;//*0.64;
rightMotorSpeed=-rightMotorDefaultSpeed/1.3;//*0.8;
Forward(0);
while(leftTick<14 && !lost); //is 90ish degrees
if (lost) return;
Stop(0);
delay(500);
//line up with edge of paper
leftMotorSpeed=leftMotorDefaultSpeed*0.69;
rightMotorSpeed=rightMotorDefaultSpeed*0.8;
Forward(0);
while(digitalRead(LineSensor)==LOW || digitalRead(PaperSensor)==LOW); //find edge of paper
Stop(0);
//if either sensor is off the paper, back up until it is just on the edge of the paper
if (digitalRead(PaperSensor)==HIGH) {
rightMotorSpeed=-120;
leftMotorSpeed=0;
Forward(0);
while (digitalRead(PaperSensor)==HIGH && !lost);
if (lost) return;
Stop(0);
delay(500);
}
if (analogRead(PaperSensor2)>30) {
leftMotorSpeed=120;
rightMotorSpeed=0;
Forward(0);
while(analogRead(PaperSensor2)>30 && !lost);
if (lost) return;
Stop(0);
delay(500);
}
//drive distance inputted at beginning
leftTick=0;
leftMotorSpeed=leftMotorDefaultSpeed*0.75;
rightMotorSpeed=rightMotorDefaultSpeed*0.8;
Forward(0);
while(leftTick<(cm+34)*0.945 && !lost); //34cm is the length of the robot.
if (lost) return;
Stop(0);
delay(300);
//turn servo
if (!my2servo.attached()) my2servo.attach(servo2Pin);
my2servo.write(180); // sets the servo position according to the current degree
now = millis();
while (millis()-now<2000);
servo2Off();
//turn around
leftTick=0;
leftMotorSpeed=-leftMotorDefaultSpeed*0.8;//*0.77;
rightMotorSpeed=rightMotorDefaultSpeed*0.8;//*0.8;
Forward(0);
while(leftTick<26);
Stop(0);
//acquire line
findLineAgain();
//reset adjustments (that's what the 1 does);
followCurvyLine(1);
}
As seen in the video above, the robot turned too far and aimed for the wrong part of the line. Earlier, the robot was not turning enough, and therefore it would reacquire the line after the next portion of the course. Finding the balance between the two was only a difference of about two ticks in turning. Furthermore, depending on the battery level for the motors, different results were encountered. If running with a fully charged battery, the robot would turn to far. But as we began to test the robot, the robot would die, and we were back to our original settings.
The robot would often curve, but it would still drop the penny within the correct range. Although it did not effect the drop zone, if it had curved to the left, and then went to turn back to face the course, turning left, it would over-steer and reacquire the track before the penny drop zone. No one said anything about doing the same part of the track twice, right?
Need a million sensors to ensure everything is working perfectly.