Milestone 2

Tasks:

- Navigate an arbitrary set of walls (right-hand wall following)
- Avoids other robots
- Full demo (try to “show” what the robot is thinking”)

Avoiding Other Robots

Our first step towards completing milestone 2 was to try to integrate both the hardware and software from milestone 1 with the hardware and software for IR detection. In theory, this would allow us to make a figure 8 on the grid, and stop if we encounter another robot. However, we encountered a couple of obstacles when we began testing

To integrate the code, we created two methods, one runs our code for IR detection, and the other runs the code for making a figure 8. We also had to combine the two setup functions into one. When we tried running this, the robot just didn’t move. We found that there were a couple of different parts interfering.

The first was that the timer used by the FFT library was the same as the one used by the servo library. We weren’t able to find a way to change which timer is used by default, so instead we stop both servos at an intersection, and then detach them before checking for other robots. We then reattach the servos and resume.

After doing this we realized another source of interference. The FFT code sets the adc to operate in free-running mode by writing to some of the internal Arduino registers. This caused the readings from the line sensors to be unpredictable and the robot could no longer detect lines correctly. To fix this issue, we save the values of the registers before running the IR detection code and restore them to their previous values at the end of the function. Making these two fixes allowed us to make a figure 8, and stop if we detect another robot at an intersection.

Avoiding Walls

The next step towards completing milestone 2 was to implement wall avoidance. To do this we chose to use short-range IR sensors. We began by just connecting one of these sensors to our robot and collecting readings with a wall placed at different distances. We found that when there was a wall at the intersection in any direction, the reading was around 220-250, and when the wall was one or more intersections away the reading was around 50.

Once we had gotten a sense of how to detect whether or not a wall is present, we had to change the code that we run at an intersection. We created a series of if-else statements to replace the figure 8 code. First we check for a right wall, if there is none than we turn right. If there is a right wall but no wall in front, than we go straight. If there is a right and front wall, we turn around. Unfortunately we did not have time to solder wires to another sensor and there were no more pre-built connectors so we don’t currently have a left wall sensor, so we have no way to determine if there is a left wall, so we take the conservative action and turn around, rather than turning left.

While trying to get the wall sensors working, we again encountered a few difficulties. The robot would sometimes make unexpected turns based on the readings we expected to get. We at first thought that perhaps some loose wires were getting in front of the sensors and interfering with the readings. However after securing them we continued to have issues. Eventually we realized that the error was because our robot was moving too fast. The movement of the robot caused a time offset between the transmitter and receiver of the sensor, giving us unpredictable results. To fix this, we briefly stop the robot at intersections before taking the readings. Doing this gave us much more reliable results, as you can see in our demo.

Demo

With wall detection working, the last step was to create a scheme to show what is happening internally as the robot navigates the maze. A green light indicates that there was no wall detected to the right, so the robot will turn right. The red light turns on if there is a wall to the right but no wall in front, so the robot should continue moving forward. The yellow light occurs when there are walls in front and to the right of the robot, so we turn around.

As you can see from the demo, when there is a wall to the right the robot continues moving straight. When there is no wall to the right, the robot turns to the right. And when there is both a right and front wall, the robot turns around. As you can see once the robot starts going in the other direction, a sensor on the left would allow us to turn left and traverse the maze in reverse as well. We hope to be able to do this for lab 3.

Other Video Links