Milestone 2: Detection

The goal of this milestone is to make the robot successfully circle an arbitrary set of walls and successfully avoid other robots by stopping when it detects another IR emitting hat.

Wall Following

Hardware

The wall detection was done using a distance measuring sensor unit, composed of an integrated combination of PSD (position sensitive detector), IR-LED (infrared emitting diode) and signal processing circuit. The datasheet for the distance measuring sensor unit can be found here. We positioned the sensor at the front of the robot, and attached it with a 3D printed plastic piece. The sensor is communicating with the Arduino through port A2.
This piece of code is placed in the function go_straight() for future use.

Software

Most of the code was already implemented from line following and motor servo behavior. However, they all had to be synthesized together and incorporated with the aforementioned distance sensor.

void loop() {
  go_straight();

  if (wallDetected() == true){
    move(left);
    if(wallDetected() == true){
      move(left);
    }
  else go_straight;
  }
}

Wall Detection is a simple subroutine that returns a boolean on whether a wall is detected in front of the robot or not. This is based on reading the analog value that the sensor returns.

bool wallDetected(){
  int distance = analogRead(front_wall);
  Serial.println(distance);
  return (distance > 400);
}


Avoiding other Robots

Using the phototransistors to sense other IR hats. We created an RC low pass filter to avoid decoy signals. After confirming that the circuit was safe and functioning correctly on the function generator, the threshold and bin number were determined by graphing the magnitude of the bins. The data was read from the serial monitor.

Serial.println("start");
for (byte i = 0 ; i < FFT_N/2 ; i++) { 
     Serial.println(fft_log_out[i]); // send out the data
}
Serial.println("done");

The chosen sampling frequency is 115200; plotting data indicated that while bins 44, 45, and 46 all increased in size when 6.0kHz was played, the highest peak occurred in bin 45 so it was determined that bin 45 would be used as an indicator of the signal.

Lastly, the thresholds for different distances were measured so the robot would not only be able to sense the presence of the another robot, but also have and indication of how far away it is (in future we plan to utilize to determine whether the robot should reverse or merely stop).

We moved the sensor to the front of the robot for better detection range. In the go_straight() function, I implemented a continuous check on detecting robot. If a robot is detected, then it will handle the response, similar to an interrupt handler.

Thus, if another robot was detected, the robot would stop -- otherwise it would continue with the right hand wall following algorithm.


Work Distribution

The Milestone 2 Work Distribution is as follows:
  - Nathalia and Priya worked on wall following.
  - Joyce and Vini worked on IR hat sensing and robot detection.
The Lab Report Work Distribution is as follows:
  - Nathalia wrote the documentation and code snippets for wall following.
  - Vini did the documentation and graphs for IR sensing and FFT bins.
The Website Work distribution is as follows:
  - Nathalia: Website Milestone 2 Set Up and Maintenance