ECE juniors' worst nightmare ECE 3400

Milestone 2

Objective

For Milestone 2, our objective was to use wall sensors on our robot to have it successfully navigate a maze using right hand wall following.


Wall Detection

The first thing we needed to do was put IR sensors on the robot to detect walls. We chose to put one on the front and one on the right as right hand follow only cares about if there is a wall to the front or to the right of the robot. After the sensors were mounted we used serial write to check what kinds of outputs the sensors gave. After reading the values we decided to use a threshold of 200 to decide if there was a wall or not.


Right Hand Wall Follow

Next we wrote the logic for right hand wall following. The robot first checks if there is a wall to the right as it will always choose to turn right if that is the case. If there is a right wall it then checks for a wall in front so it knows if it needs to turn left instead of going forward, and finally if both of those conditions weren't met the robot can just go straight ahead. It's worth noting that for the left turn condition we don't have the robot move after turning to let it check again for the cases it needs to do a 180 degree turn (see videos section). The code that implements this is below:

      
void loop() { leftline = analogRead(leftLinePin); rightline = analogRead(rightLinePin); frontwall = analogRead(frontWallSensor); rightwall = analogRead(rightWallSensor); if(rightwall < 200) { //right wall not detected turnRight(); followLine(); } else if(frontwall > 200) { //right and front wall detected turnLeft(); } else { //right wall detected and no front wall followLine(); } }

Showing What The Robot Is Thinking

Finally, for demonstration purposes we added three LEDs to the robot to show when it was deciding whether to turn or not as it navigated a maze. We used a green LED (digital pin 4) to show when the robot decided not to turn, a blue LED (digital pin 2) for left turns, and a red LED (digital pin 3) for right turns. Then we just set the LEDs to turn on and off for each of the conditions. Videos demonstrating the robot's navigation of several mazes with the LEDs are at the bottom of the page. The modified code is below:

      
void loop() { leftline = analogRead(leftLinePin); rightline = analogRead(rightLinePin); frontwall = analogRead(frontWallSensor); rightwall = analogRead(rightWallSensor); if(rightwall < 200) { //right wall not detected digitalWrite(3, HIGH); turnRight(); digitalWrite(3, LOW); followLine(); } else if(frontwall > 200) { //right and front wall detected digitalWrite(2, HIGH); turnLeft(); digitalWrite(2, LOW); } else { //right wall detected and no front wall digitalWrite(4, HIGH); followLine(); digitalWrite(4, LOW); } }

Videos


Moving around a square:                                               Doing 180 degree turns:



Navigating a winding path: