Software

Gameplay HSM

The Gameplay HierarchicalState Machine (HSM) controls the main functionality of the robot. It handles motor control, tape sensing, two ultrasonic sensors, three button inputs, and acts as the leader for SPI communication.  The Gameplay HSM has four states, three of which also function as state machines: the idle state, calibration state, tape following state, and switching branch state.

Calibration SM 

The Calibration SM is responsible for orienting the robot along the first lane from its random starting position. Using the IR receiver, tape sensors, and rear ultrasonic, it successfully positions itself to immediately begin down the first lane.

Tape Follow SM

The Tape Follow SM is responsible for guiding the robot straight up and down each lane using the two-side ultrasonic sensors. Afterward, it squares the robot with the back wall to begin again in a predictable orientation.

Switch Branch SM

The Switch Branch SM is responsible for navigating between the various lanes of the arena. It keeps track of the current lane and uses the side ultrasonics and the tape sensors to rotate 90, drive to the desired lane, and then realign with the lane to prepare to push the wall.

Other Services on Leader PIC

Motor Service

The Motor Service handles all of the communication with the two DC motors. The Gameplay HSM posts events to this service to navigate around the arena.

SPI Leader Service

The SPI Leader Service is responsible for communicating with the follower PIC. It would routinely ask the follower "questions" to retrieve data from sensors connected to the follower PIC. It could also give the follower "commands" to turn on/off the LEDs and manipulate the servo.


Ultrasonic Service (Leader)

The Ultrasonic Service on the leader is responsible for processing the echo pulse output from the two-side ultrasonic sensors to calculate the distance.

Button Module

The Button Module is an event checker that checks if any of the three input buttons have been pressed.

Follower PIC Code

SPI Follower Service

The SPI Follower Service keeps track of the distance output by the rear ultrasonic sensor and which beacon the robot is currently facing. The leader can ask for any of this data and the follower will send it back with the next query. The follower can also receive commands to turn on/off the LEDs and manipulate the servo.

Ultrasonic Service (Follower)

The Ultrasonic Service on the follower is responsible for creating the trigger that all three ultrasonic sensors need to function in addition to processing the echo pulse output by the rear ultrasonic sensor to calculate the distance.

Beacon Service

The Beacon Service calculates the period output by the signal conditioning circuit to determine which, if any, beacon the robot is currently facing.

Other Files