Objective

The goal of this milestone was to give Gary the ability to follow a set of arbitrary walls through right-hand wall following. While doing this, we needed to ensure that Gary could detect the presence of other robots as well, so we used our IR detection materials from Lab 2. We added IR sensors on Gary's sides that detect the proximity of the walls. With some code, we could tell Gary to check at every intersection whether or not there was a wall in front of him that he needed to avoid. With all of this put together, we enabled Gary to circle a wall while following a line and stop when in close proximity to another robot!



Figuring out IR Wall Sensors

Using long range IR sensors, we were able to avoid walls. To start, we simply hooked up the analog input of the wall sensor to the Arduino to find a reasonable threshold value at which point we would determine there was in fact a wall in front of Gary. Next, we integrated the wall sensors onto our robot, temporarily zip tying them to both sides of the robot and to the front at a height appropriate for the walls. Below is a picture of the IR sensors we used.


Wall sensor

Implementing Wall Following

In order to implement right-hand wall following, we attached IR sensors to our robot on the front and the right side since we only needed two sensors for the sake of this milestone. We had a bit difficulty navigating a maze that required Gary to see a left wall so we decided to add another wall sensor on the left side. Our logic was simple. At an intersection, Gary checks to see a front wall. If the front wall exists, then Gary will go ahead and check his sides. Gary will then turn in the direction that is free of wall. Gary then continues to follow the line. The process repeats indefinitely.
Below is a snippet of our code which shows how we implemented this.


      else if(center<thresh && right<thresh && left<thresh){ //checks if we are at an intersection
      if(frontw()) //checks if there is a wall in front of the robot
      { 
        digitalWrite(wall, HIGH); //turns of indicating LED
        if(rightw() && !leftw()) //checks which way we should turn
        {
          turn_left();
          Serial.println("turning left");
        }
        else if (leftw() && !rightw())
        {
          turn_right();
          Serial.println("turning right");
        }
        else if(leftw() && rightw())
        {
          turn_around();
          Serial.println("turning around");
        }
        else
        {
          turn_left();
          Serial.println("only front wall");
        }
        digitalWrite(wall, LOW);  //LED turns off
      } 
      

Below is a short video showing Gary detecting walls in front and on the sides and making a u-turn to avoid crashing into the wall. This video shows how Gary can detect walls on all sides with IR sensors.


Implementing Wall Following, IR Sensing and Line Following

We already had line following and IR sensing implemented from previous labs, so all we had to do was schedule the 3 processes. Essentially, we would follow lines until we reached an intersection, when we would check for walls and also check for other robots.This implementation was a way for us to avoid pulsation in the robot caused by the FFT function. When another robot is detected, Gary stops in its path to avoid colliding into the other robot. We decided to stop Gary for now but in the future, Gary might turn around or move to the right to pass by the robot. We have not determined the final action for Gary yet. We are aware that some background noise might interrupt the IR sensing, so we decided to check a number of times and average our findings. This way, we can ensure that the IR emission was not from a reflection or some background noise. In this video you can see Gary following lines, avoiding walls, and sensing other robots! The yellow LED indicating wall sensing is a little hard to see, but it will turn on when it recognizes the walls. The green LED indicates another robot has been sensed.