All software files for the Leader PIC32 microcontroller are accessible in our Leader PIC repository.
All software files for the Follower PIC32 microcontroller are accessible in our Follower PIC repository.
Top Level HSM
The GameHSM governs the entire game plan though 5 major states: Calibration state, Right Tree state, Left Tree state, Sweep state, and FinalShoot state. If everything goes well, the robot will go through each state sequentially to collect acorns from both trees and eject them to the opponent's yard. At the end of the game, the robot will move across the field to push acorns in the high point region to the low point region. In case of unexpected disturbance and system malfunction, the robot will turn off motors and game LED when the 2mins and 18 seconds game time runs out or stuck in the field for more than 15 seconds, whichever is earlier.
Lower Level HSM
Calibration HSM
The calibration state is a critical state at the beginning of the game as it is repsonsible for determining the yard the robot is in and guiding robot to the horizontal tape line. The robot starts the game by rotating 360 degrees in the field to read all beacon signals and triangulate its positions based on angles of each beacon. It then move towards the upper right beacon until it reaches the horizontal tape line. After that it will adjust its position to face towards the right tree.
Right Tree HSM
The Right Tree state guides the robot to the right acorn tree once it finds the horizontal line. Before reaching the right tree, the robot will shoot out an acorn it collected at the start of the game. Once all acorns are collected from the tree, the robot will back up and shoot them all to the opponent's yard and turn towards left tree for the next state.
Left Tree HSM
In the left tree state, the robot will head towards the left tree and collect all acorns from the left tree and turn towards right tree for the next state. During the competition, we added a defensive motion path to the left tree state and temporarily shut the sweeper to prevent acorns in the field from accidentally entering the robot and jamming the lift system.
Once entering the final shoot state, the robot will eject all acorns from left tree to the opponent's yard. Then it will enter the sweep state and move across the field to push acorns in the central field to the side.
Flat State Machines and Services
Movement Control Service
Movement Control Service is a flat state machine that executes movement commands sent from other state machines. It can execute various robot movements such as rotating, moving straight, and tape following. When a movement has been done, the Movement Control Service posts the "ES_MOVEMENT_COMPLETE" event to GameHSM.
A PI speed controller is embedded in the Movement Control Service to adjust the PWM duty cycle dynamically to precisely control motor speed.
We break the Movement Control Service down into three sections for clarity (the 3 IDLE states are the same state).
Collection FSM
Collection FSM controls the openning and closing of the sweeper to collect acorns from the tree or in the field.
Store FSM
The store FSM sychronizes the motion of the valve, sweeper, and lift servos to store collected acorns into the tube inside the robot.
Release SM
The release FSM controls the ejection of acorns by coordinating motions of the ejector DC, sweeper servo, and valve servo.
Services
EventCheckers
Event check functions are created in the framework to constantly check status of peripheral sensors connected to leader and follower PIC32.
Check4StartSwitch: check if start button has been pressed
Check4Wall: check if the robot has hit the wall and both limit switches are triggered
Check4Acorn: check if an acorn has been detected by the IR sensor
Check4EjectSensor: check if the IR sensor on the ejector has been triggered
SPI Communication
One key feature of embedded systems for short distance communication between integrated circuits is Serial Peripheral Interface (SPI). It involves a master-slave architecture where one device acts as a master, dictating the communication with slave devices, which respond to commands from the slave. slave and master devices share four communication lines:
SS (Slave Select): used by master to select a specific slave device with which it wants to communicate.
SCLK (Serial Clock): generate clock signal for synchronizing data transmission between the master and slave devices.
MOSI (Master Out Slave In): transfer data from master to slave.
MISO(Master In Slave Out): transfer data from slave to master.
In addition, we developed a SPI hardware abstraction layer to configure the communication between leader and follower PICs. Hexadecimal values were defined to represent various commands sent between leader and follower PICs as listed below.
Leader and Follower Services