We broke down the task into four sub-tasks.
We accomplished this task by reusing a lot of the lab 1 setup. Digital pins 9 and 10 still gave the servo control signals, but instead of simply proceeding at full speed, we only use roughly 10% of full speed when traveling in a straight line. Turns still proceed at full speed, with one servo running at full forward and the other at full reverse during a turn.
void turn_left(){
drive_ramp(MOTOR_STRAIGHT);//center the robot pivot point on the junction
delay(125);
drive_ramp(RIGHT_FORWARD_LEFT_BACKWARD);//turn
delay(630);
drive_ramp(MOTOR_STRAIGHT);//get out of the junction
delay(125);
drive_ramp(MOTOR_STOP);
}
drive_ramp
is a helper function that Alex Coy felt would lead to smoother
turns by ramping up motor speed gradually. It takes an argument that is the desired
motor response.
The line sensors work by shining an infrared beam towards a surface and returning a reflection strength. It turns out, white surfaces yield a low output voltage from the sensor, while dark surfaces yield a high voltage from the sensor. For the time being, Ryan and Tyrone connected the line sensors to analog inputs A0 through A4. Joseph worked on a Schmitt trigger circuit in the hopes that we can make the line sensors digital at some point. We did not implement Schmitt trigger circuit for this milestone.
while(1){
poll_sensors;
if(outside_sensors_black){
if(inside_sensors_black) both_servos_same_forward;
else if(inside_right_white) right_slightly_slower;
else if(inside_left_white) left_slightly_slower;
}else if(outside_sensors_white){
make_correct_turn;
}
}
In the above code snippet, the robot polls the line sensors every iteration of the loop. We found that the robot polls quickly enough to navigate successfully at the moment. The robot makes a decision on what to do next based on its current state; it tries to correct its course if it gets off of the line, and if it meets a junction, it makes the next turn in the figure 8 sequence (using a counter variable in the actual code). The robot assumes that it starts in the bottom right corner of the 8 (or the top right corner of an infinity sign).