Software Design
Overview
During the software design and development process for Jackbot, we focused on creating a modular and easily testable body of code. We developed directly in the Arduino IDE and hosted our code on a GitHub repository. The code consisted of a main loop driving a state machine, and then several modules which handled subsystems of the robot:
- MAIN module: Initialization of all modules, state machine loop, central timers. Uses the Timer library to create separate update loops with different periods for each module. This lets us run the critical code at a faster speed than the auxiliary functions. For example, by having serial commands read only every 100ms, the sensor processing can happen at a faster speed.
- COMM module: Allowed each module to register serial commands to callback functions, with an optional integer argument. The module reads in serial characters and saves them to a String buffer. When the end command '\n' is reached, it parses the full command and invokes any callbacks which are looking for this command. For example, the DRIVE module has the code COMM_check_command(String("DRIVE_FORWARD"), DRIVE_forward);. When a command of the form 'DRIVE_FORWARD 200\n' is sent over the serial connection, DRIVE_forward(200) is invoked, a method to drive the motors. In this way, we can test and control every individual function of the robot without having to change the code from autonomous function.
- MUX module: Handles multiplexing of inputs, instead of digitalRead or analogRead, modules call MUX_read or MUX_read_digital. These functions write to the multiplexer chip which pin they want to read, wait one clock cycle, and then read and return the pin value.
- DRIVE module: Handles driving and turning by interfacing with the L298 chip.
- BEACON module: Counted frequency of infrared pulses received from the beacons to determine Server vs Exchange.
- LINE module: Handles tape sensors and line following.
- MINE module: Handles button pushing (mining), turning the shooter, and shooting.
In some ways, Jackbot's software is simple because of its shooting mechanism. We can break the game down into three stages:
- Initialization: The most complicated procedure is the initial sweep to determine what side of the map he is on.
- Locomotion: The next part involves driving toward the Server at an angle so that we hit the tape, and then backing up on the tape to reach the Server straight on.
- Shooting: Once the robot reaches the Server, the only tasks are to push the Algorithm to get botcoins, turn towards the Exchanges, and shoot. There is no more driving for the rest of the game.