PIC 32 LEADER
Top Level State machine
Lower Level State machines
SPI Leader service
Line Following Service
Motor Drive Service
PIC 32 Follower
Find Beacon service
Servo Service
SPI Follower Service
Event Checker for button
Our top level state machine consists of 5 main states: an initialization state, finding beacon, deposit cube, pick up cube, and an end game state. On startup, the robot begins by querying the follower to check if the game start button has been pressed. Once a button has been pressed and the leader receives that information, we transition to the Finding Beacon state where we spin the robot and again query the follower until we determine what side we are on. Once a side has been determined, we run the Deposit Cube State machine and the Pick up Cube state machine, transitioning between both until the final game timer expires.
The Deposit Cube Service runs when a cube is placed in the robot and after all calibration has been completed. We then transition to a a series of turns, line following, and junction detection until we are at the stack to deposit. This can be determined either by detecting the junction at the stack or the TOF sensor reaching a certain threshold. We then eject the cube by actuating a servo.
Once a cube has been deposited, we turn around to find the next cube. depending on the number of cubes we have already deposited, we follow a different set of instructions to find the next cube. After all instructions have been completed, we transition back to the deposit cube state machine.
The find beacon state machine operates on the follower PIC 32. When the game start button is pressed, inpput capture is turned on. Everytime an input capture event is recorded, the time between the previous event and the current event is recorded and averaged. After 20 events have occurred, if the average period is within certain thresholds of the beacon's frequency ranges, we determine the side and turn off input capture. If it is outside of the threshold, we repeat for another 20 events until a side has been determined.
All of the game logic is performed on the leader PIC32, and we tried to minimize the need for the leader to request information from the follower by wiring most sensors and inputs to the leader. The two exceptions are the game start button and the beacon detection circuit. At the start of the game, before the button has been pressed, the leader sends a message to the follower until a response is given which is trigged by the game button being pressed. Similarly, the leader sends a message to the follower constantly while waiting to determine the side until the follower returns a message. The SPI follower service receives messages about servo commands and posts events to the servo service on the follower. Data related to servos, game starting and ending, and side determination is the only information passed between the PIC 32 Leader and Follower.
Our line following service handles all analog inputs which include 5 line sensors and 1 Time of Flight (TOF) sensor. Our line following algorithm employs a PD controller. By having 5 line sensors close to each other, we create a weighted function which takes into account the line's position relative to each sensor and gives a very accurate position of the line on the robot. The PD controller creates fast and efficient line following which is a strength of our robot. We actively calibrate the line sensors at the start of the game and during the game so that under different lighting and playing conditions, we do not have to recalibrate. Junction detection is determined by summing the line sensor values and comparing it to a threshold which updates based on the calibration of the line sensors.
The Motor Driver service configures the output compare pins on the leader to drive the motors, and the Servo Service configures output compare pins on the follower to drive the servos. We use a drive-brake method for quasi-linear control.