Milestone 2
Right-Hand Wall Following
Read the Report


Milestone 2


Integrate the following sensors and functionality:

Demonstrate a robot that successfully circles an arbitrary set of walls through right-hand wall following, while performing line tracking, and detection and avoidance for other robots and walls.



      #define VAL_6_INCH 100
      #define VAL_3_INCH 200

      #include "ir_rangefinder.h"
      #include 

      int read_range_sensor(int pin){
        return analogRead(pin);
      }
      bool detect_wall_6in(int pin){
        int val = read_range_sensor(pin);
        if(val > VAL_6_INCH)
          return true;
        else
          return false;
      }
      bool detect_wall_3in(int pin){
        int val = read_range_sensor(pin);
        if(val > VAL_3_INCH)
          return true;
        else
          return false;
      }
      



GOAL: a robot that recognizes 660 Hz, does line tracking, and avoids robots and walls


      // wall detected at intersection
      if ((sensorStatus[0] == 0) && (sensorStatus[1] == 0) && (sensorStatus[2] == 0) && detect_wall_6in(3) ) {
            if (detect_wall_6in(1)){
              turnLeftIntersection(servo_L, servo_R);
            }
            else{
              turnRightIntersection(servo_L, servo_R);
            }
        }
        // wall detected but not at an intersection
        else if (detect_wall_3in(3)) {
          turnLeft(servo_L, servo_R);
        }
        // no wall detected --> just track the line
        else if (sensorStatus[0] == 0) //turn Right
          adjustRight(servo_L, servo_R, 85);
        else if (sensorStatus[2] == 0) //turn Left
          adjustLeft(servo_L, servo_R, 85);
        else {
          moveForward(servo_L, servo_R);
        }