The Software - rswhiting/MinefieldBot GitHub Wiki

The IDE

The Arduino IDE may be wonderful for inexperienced developers, but it drives me nuts. I wanted a full blown IDE, not a custom built, simplified one. So I got Netbeans and a plugin for it. The tutorial here was great, though missing some steps relating to setting it up on Ubuntu.

Just dig into the Makefile some. Update the port, replace all Windows-style paths, and use the AVR_DUDE_LINUX instead of AVR_DUDE_WINDOWS.

If you have doubts/questions, take a look at my Makefile.

Monitoring

The tutorial for NetBeans didn't tell me how to monitor serial (for debugging), so I wrote a script to launch in a terminal window (within NB?). Just be sure to hit CTRL-A to pause monitoring while uploading to the Arduino or there will be a serial port conflict. Also, install minicom (sudo apt-get install minicom).

#!/bin/bash
minicom -b 9600 -o -D /dev/ttyACM0

State Machines

It's been a long time since I've touched C++ code, so I looked up how to do a good state machine (using the design pattern instead of doing the old switch statement nonsense). I found a good tutorial (see references).

My bot has the following states:

  • READY - it's ready. I thought I'd use this for initialization and such, but it's all done before this state. Maybe I'll add a button to send it from READY to GO.
  • GO - the bot goes straight forward while checking sensors.
  • TURN - the bot stops, backs up, and turns based on which sensor was triggered (or if both, the last recorded single sensor)
  • DONE - this state is if I ever implement distance tracking so that when it completes the course it can do a victory dance (spin in circles?).

External Libraries

I had some trouble with getting AFMotor recognized in NetBeans. It was frustrating because it was already included in the C++ Code Assistance, so the IDE recognized it but the compiler didn't. Eventually I found out that I needed to update a line in the Makefile to include the library:

INCLUDE_LIBS=EEPROM;AFMotor;Bounce;

Debouncing

I implemented my own debouncer based on the example found in the Arduino button section, but it didn't seem to work when I converted it from a flat file to object oriented. After several frustrated hours, I found that someone already implemented the Bounce library, which is not only better than what I had coded up--it actually worked.