The Leader PIC controls the driving/navigation and game logic.
The highest level HSM is comprised of a GameInactive state machine and a Game Active state machine. The SQRL is initialized in the GameInactiveSM and the start game button moves teh SQRL into the Game Active state machine for the game duration of 2 minutes and 18 seconds.
The GameActiveSM has two sub state machines. The StartingDriveSM is used for initial orientation and the DrivingSM is used for navigation from the starting position to the trees and also includes ACORN shooting.
The StartingDrive State Machine is responsible for the initial orientation of the SQRL before it drives to the center of the field. We place the initial ACORN on the center line between the SQRL and the fence. This allows us to determined which direction is forward. The SQRL then goes through a series of small rotations to center the front center tape sensor and wheel base center tape sensor on the tape.
The Drive State Machine is used for navigation from the starting area to the trees and also includes commands for shooting. The Tape Control Service (see below) is responsible for posting events to this state machine in order to trigger the transition between states and therefore navigation throughout the field.
All motor control is included in a separate HAL that is called within the HSM. The HAL module includes motor configuration, driving forward at different speeds, driving backwards at different speeds, rotating clockwise, and rotating counterclockwise. A scalar was empirically determined and applied to one motor in order to drive straight. This was further corrected in the Encoder Service (see below).
This HSM was used to achieve the MVP, which includes ACORN detection, yard detection, and navigation to shoot an ACORN. Transitions between states are governed by timers instead of tape events.
The Encoder Service uses PI control to keep each wheel at the desired RPM so that the SQRL stays straight.
The Tape Control Service uses bang-bang control to correct for when the SQRL veers off the tape. When the tape sensor on the right detects tape, the service will speed up the left motor and slow down the right motor by the same amount to correct.
The Shooting Service controls the servo the bat is attached to. The service has a set starting position and ending position and when an event is posted to the service, it will control the servo to quickly move from one extreme to the other to either hit the ACORN or reset its position.
The LED Service controls the game active LED. The LED is turned on when the Game button is pressed and turns off when the game expires.
The follower PIC software is comprised of a collection of services to control 3 servos, detect beacons, and detect ACORNS.
This service helps in identifying the each beacon and then send that event to the yard detection servo.
This service uses an interrupt to detect the acorn . it then post the event to the Follower SPI which in turn sends it to the Leader.
This service controls the movement of the servo the beacon-sensing phototransistor is mounted to. An ES_ACORN event triggers the servo to slowly rotate 90 degrees.
This service controls the movement of the servo that points to either Ed or Karl to determine which yard we are in. The direction it moves is determined by the IRDetection Service. The movement of this servo results in an ES_YARD event that tells the SQRL we can start driving.
This is done with the help of HAL. The leader sends a query at a set rate this allows for a quick communication between the leader and the follower. The leader sends events to the follower when it reaches certain points in the arena and the follower sends back events when the bot has finished its shoting mechanism or has seen an acorn on the feild.
SPILeaderService communicates between leader and follower PIC. This service is on the leader's side and initializes communications. Events are posted to it which it sends over SPI as it receives them. It gets back messages from the follower pic which it posts as events to the framework.
Receives messages from the Leader PIC which it posts as events to its framework. If it receives events from its framework, it writes them as messages to the buffer and they are transmitted to the leader when it initializes a transfer.