State Machines

Keeping track of the game's state.

State Diagrams

Description

On each controller we used an event-driven finite state machine (FSM) to transition between states. The system depends heavily on messages sent between controllers. The master alerts the rocket when a coin has been inserted, and the rocket alerts the master when it has finished resetting, crashed, or landed successfully. There are slight differences between controllers, but the primary states can be grouped as idle, reset, flying, win and lose.

List of States

State Description
Idle Game is waiting for a coin to be inserted.
Reset Rocket is being reset and positioned to the top center.
Flying This is where the bulk of the game play happens. The rocket is controlled via inputs from the UI panel.
Win All actuators are stopped. The barge lights glow green to indicate success.
Lose Similar to the win state, except the barge lights glow red to indicate failure. The number of lives is also decremented.

The primary difference between controllers is that the rocket has an additional state: reset from origin. The reset state positions the rocket in the top left corner. If there are no more lives and the game is over, it then transitions into the idle state. If there are remaining lives, the reset state transitions into reset from origin. This moves the rocket a fixed number of steps, centering it above the game before transitioning into the flying state.

The Arduino has a similar state machine, with the main difference being that the reset and idle states are combined. This means the LEDs have the same behavior for idle and reset states. This reduced the number of states to four, meaning that only 2 digital I/O pins were required to send the state from the master. A timer interrupt checks the 2 digital input pins on the arduino periodically and changes state based off of the signal from the master.

Success Conditions

Outcome Results
Win The barge switch is pressed at the correct speed and angle.
Loss Any of the x or y axis endstops are pressed. The rocket runs out of fuel. The barge switch is pressed, but the rocket is too fast or at too great of a tilt an angle.