Overview
Powerpuff Bot is run off of three micro-controllers: the leader, the motor controller, and the launcher controller. The leader manages most of the sensors, updates the "displays", and manages the flow of the game through timers and commands. The motor controller uses encoder readings and a limit switch to drive the two motors in response to the commands passed down by the leader. The launcher controller controls the launcher and the "local" reload – a process in which the next ball is placed into position to be launched.
Leader Controller
The Leader PIC program consists of an FSM that takes care of timing paired with an HSM that controls the game. The highest level of the HSM simply keeps track of whether or not the game is currently running. The level immediately below that controls the flow of the game between moving, launching, and reloading. A communication SM controls activation and deactivation of the moving and launching states – states that involve the other two controllers. The motor control SM distinguishes between the different varieties of movement required by the game.
Pseudocode
Your browser does not support viewing this document. Click here to download the document.
Files
Motor Controller
The motor controller software design consisted of 1 flat state machine (left) to drive the motors and 1 service for SPI communication (right). The SPI Service posted an ES_RECEIVEDCOMMAND to the Motor FSM when the SPI receive interrupt was triggered and a command from the Leader PIC was in the SPI buffer. The Motor FSM acted accordingly based on the command and updated the outputted PWM signal to sweep in the clockwise and counterclockwise directions, move forward, or move backward. Framework timers were used to control how long the motors moved forward until the launch position was reached, and triggering the limit switch on the back of the robot indicated that the reload position was reached. The leader PIC regularly queried the motor follower PIC, and when the launch or reload position was reached, the Motor FSM would post an ES_REACHEDLAUNCH or ES_REACHEDRELOAD event to SPI Service to send the appropriate command to the leader PIC. Lastly, for speed control, PI control was used to regularly update the motors' duty cycles to reach a specified target speed.
Pseudocode
Your browser does not support viewing this document. Click here to download the document.
Files
Launcher Controller
Pseudocode
Your browser does not support viewing this document. Click here to download the document.
Files