Source Code
The software was developed in modules to minimize dependencies and ease gradual testing. Each module is summarized below.
Strategy
pseudocode | strategy.h | strategy.c
The strategy module uses a state machine architecture to control what our robot does during the game. It sends commands to the SPI and checks responses via flag updates. We implement a hierarchical state machine, with the highest state being the current game condition (paused, running, red won, green won) and a lower level state machine taking care of state transitions when the game is running.
Main
pseudocode | main.c
The main module is responsible for coordinating all the modules and executing our program. In main, we initialize all of our modules, check the state of the switches, and then run an infinite loop that updates the SPI and strategy state machines. We also implement a testing suite that includes unit tests for every module and overall tests as well. This saved us countless hours of debugging headaches as we built up the robot, replaced parts, and wreaked general hardware mayhem.
IR Sensing
pseudocode | beacon.h | beacon.c
The beacon module is responsible for updating whether or not the two phototransistors currently see a beacon. It uses input capture and output compare interrupts to signal when we start and stop seeing a beacon.
Drive Motor
pseudocode | drive_motor.h | drive_motor.c
The drive motor module allows us to execute basic driving procedures, such as driving forward and reverse, as well as rotating. It can also check whether our two tape sensors are seeing tape since these sensors directly affect when we stop the drive motors.
Lift Motor
pseudocode | lift_motor.h | lift_motor.c
The lift motor module allows us to lift and lower our lift motor. It can also check when the top and bottom limit switches are pressed, signaling that the lift is fully raised or lowered.
PWM
pseudocode | PWM.h | PWM.c
The PWM module provides a generic interface to 5 PWM channels on the E128. We can control the PWM frequency for two groups of PWM channels (0,1,4 and 2,3). We have arbitrary control over which channels are on or off and what their duty cycles and polarities are.
SPI
pseudocode | SPI.h | SPI.c
The SPI module uses a state machine architecture to query the SPI. We implement a queue that checks the game state by default and can also accept one other command at a time. The SPI module updates flags based on responses from the OC. These flags are monitored by the strategy state machine and affect our actions in the game.
Ultrasonic
pseudocode | ultrasonic.h | ultrasonic.c
The ultrasonic module interfaces with the Parallax ultrasonic sensor and provides a distance reading. It uses output compare to send a short pulse to activate the sensor, and then input captures the high time of the response back. The width of the high time is proportional to the distance traveled by the ultrasonic wave.
Switches
pseudocode | switch.h | switch.c
The switch modules simply checks the status of the overtime, full court, and color switches.
Strategy
pseudocode | strategy.h | strategy.c
The strategy module uses a state machine architecture to control what our robot does during the game. It sends commands to the SPI and checks responses via flag updates. We implement a hierarchical state machine, with the highest state being the current game condition (paused, running, red won, green won) and a lower level state machine taking care of state transitions when the game is running.
Main
pseudocode | main.c
The main module is responsible for coordinating all the modules and executing our program. In main, we initialize all of our modules, check the state of the switches, and then run an infinite loop that updates the SPI and strategy state machines. We also implement a testing suite that includes unit tests for every module and overall tests as well. This saved us countless hours of debugging headaches as we built up the robot, replaced parts, and wreaked general hardware mayhem.
IR Sensing
pseudocode | beacon.h | beacon.c
The beacon module is responsible for updating whether or not the two phototransistors currently see a beacon. It uses input capture and output compare interrupts to signal when we start and stop seeing a beacon.
Drive Motor
pseudocode | drive_motor.h | drive_motor.c
The drive motor module allows us to execute basic driving procedures, such as driving forward and reverse, as well as rotating. It can also check whether our two tape sensors are seeing tape since these sensors directly affect when we stop the drive motors.
Lift Motor
pseudocode | lift_motor.h | lift_motor.c
The lift motor module allows us to lift and lower our lift motor. It can also check when the top and bottom limit switches are pressed, signaling that the lift is fully raised or lowered.
PWM
pseudocode | PWM.h | PWM.c
The PWM module provides a generic interface to 5 PWM channels on the E128. We can control the PWM frequency for two groups of PWM channels (0,1,4 and 2,3). We have arbitrary control over which channels are on or off and what their duty cycles and polarities are.
SPI
pseudocode | SPI.h | SPI.c
The SPI module uses a state machine architecture to query the SPI. We implement a queue that checks the game state by default and can also accept one other command at a time. The SPI module updates flags based on responses from the OC. These flags are monitored by the strategy state machine and affect our actions in the game.
Ultrasonic
pseudocode | ultrasonic.h | ultrasonic.c
The ultrasonic module interfaces with the Parallax ultrasonic sensor and provides a distance reading. It uses output compare to send a short pulse to activate the sensor, and then input captures the high time of the response back. The width of the high time is proportional to the distance traveled by the ultrasonic wave.
Switches
pseudocode | switch.h | switch.c
The switch modules simply checks the status of the overtime, full court, and color switches.