Gameplay Pseudocode
Gameplay Pseudocode
GameplayService
Function
RunGamePlay
Waiting state
If IR transmission is received
Use SPI1 to inform locomotion node to enter relay mode
Start servo sweeping back and forth
Set next state as relay node
Relay State
If hall sensor detects magnets
Use SPI1 to stop locomotion of robot
Use SPI2 to tell IR node to start transmitting
Set next state as transmission
Transmission state
In the case the hall sensor exits
SPI1: Locomotion node to enter parking
SPI2: Tell IR node to stop transmitting
Set next state to parking mode
Initiate timer for parking mode
Stop servo sweeping
Parking mode
If ES_TIMEOUT
Tell Locomotion Node to enter waiting mode
Function: IO Setup
Blue led
ANSELAbits.ANSA3; A3 does not have analog capabilities.
Set to output
Red led
ANSELAbits.ANSA4; A4 does not have analog capabilities.
Set to output
Hall sensor 1
ANSELBbits.ANSB4 = 0; RB4 does not have analog capabilities
Set to input
Function: IOISR
If RB4 changed
If RB4 is now low:
Post ES_HALL1_SENSOR_MAGNET_ENTERS event
If RB4 is now high
Post ES_HALL1_SENSOR_MAGNET_EXITS event
If RA1 changed
Post ES_IR_REQUEST_TX event
Clear interrupts flags
Function: TIMER_5_ISR
If 3s have passed, transmission to waiting