0% found this document useful (0 votes)
85 views2 pages

Gameplay Pseudocode

The document describes the gameplay state machine and functions of a robotics module. It outlines states like initial, waiting, relay, transmission, and parking. It also covers initializing servo position, team selection, SPI communication, hall sensor detection, and timer interrupts.

Uploaded by

api-531773521
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views2 pages

Gameplay Pseudocode

The document describes the gameplay state machine and functions of a robotics module. It outlines states like initial, waiting, relay, transmission, and parking. It also covers initializing servo position, team selection, SPI communication, hall sensor detection, and timer interrupts.

Uploaded by

api-531773521
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Module

GameplayService

Function
RunGamePlay

If state is initial pseudo state

Timer 2 for Servo PWM


Servo PWM Init
Set Initial Position of servo
Set up IO elements

Setup SPI 1 and 2, call spiHal functions

Team Selection and set LEDs accordingly


If switches are in relay state
Set next state to relay
Use SPI1 to inform locomotion node of initial state
Start servo sweep
If switches are in the waiting state
Set next state to waiting
Stop servo sweep
If switches are in the transmission state
Set next state to transmission
Stop servo sweep

Hardware test debugging state, if active, skip


gameplay states and enter debug mode.

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

Switch to determine Team A or Team B


ANSELAbits.ANSA2; A2 does not have analog capabilities.
Set to input

Switch A for Starting position


ANSELBbits.ANSB9; RB9 does not have analog capabilities
Set to input

Switch B for Starting position


RB12 does have analog capabilities
Set to input

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

IO line - IR request for data transfer


Set to input

Set up interrupt for IO lines

Set priority for IO line interrupts

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

You might also like