We started with a state diagram to layout the global strategy for the competition and then began to build and test the software as different aspects were assembled. By laying out the problem in a state diagram first, we realized how few sensors were required to achieve the MVP, eventually using only 3 wall sensors and the Beacon sensor to get checked off.
Motor Control
Our code was built around various macros to control the motors, setting their speed at the setup function then controlling their direction with the input pins and a delay.
Despite choosing high-torque, low RPM motors, our motors were still too fast. We slowed the robot down by turning the motors on and off at the input pins:
Wall Following
Our most important code was our wall following algorithms. The robot drives forward, turning away from any switch receiving input. It periodically will turn back towards the wall it is supposed to be following.
If the center switch is triggered, the robot progresses to the next state.
Beacon Sensing
Escaping the random orientation proved to be the hardest task. Our design spins 360 degrees while reading its IR sensor to establish a peak reading. Then it spins again until it finds its establish peak, moving forward towards that peak.
This strategy avoided hardcoding in a threshold value and allowed the robot to adapt based on the arena.
Testing and writing code based off early prototypes provided a solid foundation to build our final code on
State diagrams and segmenting out each step of the MVP was critical for testing code
While using delay commands and simple macros is not perfect, it works for simple motor control as long as you check the sensor quickly in between delay calls
Coding for robots is different than normal coding, just because it seems like it should work in software it might not, so simplify simplify simplify
We used Arduino IDE as our text editor and GitHub for code sharing.
Arduino IDE: https://www.arduino.cc/en/software