The software of NIMBY is modularized into a hierarchical structure, with a high-level hierarchical state machine (HSM) module handling the high-level logic and reasoning, and low-level modules that handle critical functions including driving motors, encoder feedback, SPI communications, sensor input capture (IC), PWM output, etc. Each module is implemented in event-driven C on the PIC32 microcontroller, adapting Prof. Ed Carryer's Events and Services Framework. The functionality is distributed among the modules as follows:
RobStrat_TopLevelSM: Handles transitions between Idle, MainGame, SuddenDeath
RobStrat_IdleSM: Maps button inputs to toggle between game modes and start game
RobStrat_MainGameSM: Implements logic sequence for a full tournament game
RobStrat_SuddenDeathSM: Implements logic sequence for sudden-death game mode
RobStrat_Init: Initialization sequence to collect first puck, determine side-of-field by homing onto IR beacons, and align to the tape line
RobStrat_TapeFollowing: Responds to tape sensor signals to implement tape-following logic
RobStrat_TreePuck: Commands sequence to harvest tree of ACORNs and shoot them to the opponent's field
RobStrat_TreeCounting: Tracks of the number of trees we've harvested for ACORNs
RobStrat_RealignToTape: Realigns to tape after the first tree interaction
RobStrat_PatrolFreePuckSearch: Sweeps field along center tape line for loose pucks during free-puck stage
RobStrat_TestHarnessService [Test Harness]: Injects events into high-level SM from keyboard input
IRService: Configures interrupt-driven IC of IR beacon signal to measure signal frequency and post events when valid beacon detected
LeaderSPICommSM: Handles two-way SPI communications with Follower PIC32
OnOffService: Event checker for button long-press and short-press events, handles LED effects (On, Off, Slow Flash, Fast Flash)
PIC32_SPI_HAL: Hardware-Abstraction Layer for SPI communication on PIC32
ServoAndPuckSensorsService: Handles PWM output and interrupt-driven IC for frequency analysis of reflected IR signal off of puck for puck sensor, AND generating event-driven servo control signal (both functionality based off of same hardware timer)
TapeSensorService: Posts events when tape sensor detects or loses sight of tape
TestDrivetrainSPIService [Test Harness] : Test drivetrain through LeaderSPI
DCService: Set PWM signals to control the drivetrain motors according to high-level commands (eg drive forward, curve right, etc)
EncoderPIDFSM: Process quadrature encoder signal to apply PI control signal to the motors given a desired goal speed or position for drive turns, drive straights, etc
FollowerSPICommService: Handles two-way SPI communications with Leader PIC32, including interrupt-driven logic to maintain a buffer of valid messages to transfer upon request from the Leader
IntakeService: Handles direction and PWM motor control signals to drive intake motors through the integrated H-bridge motor control circuit
PIC32_SPI_HAL: Hardware-Abstraction Layer for SPI communication on PIC32
(Photos From Freepik)
Starts Game and toggles between Main Game and Sudden Deathgame modes
Game Mode to identify side and launch first puck as quickly as possible
Initialization sequence to collect first puck, determine side-of-field by homing onto IR beacons, and align to the tape line
Responds to tape sensor signals to implement tape-following logic
Realigns to tape after the first tree interaction
Commands sequence to harvest tree of ACORNs and shoot them to the opponent's field AND Tracks of the number of trees we've harvested for ACORNs
Sweeps field along center tape line for loose pucks during free-puck stage
Handles two-way SPI communications with Follower PIC32