G[OG]GLE State Machines

The ADC State machine handles sampling all of the analog input sensors including the rotary switch, joystick, and pressure sensor. It starts by setting ADCON0 register to the desired pin, and sets a timer to wait for the capacitance on the input to settle. Once the timer times out, the GO/Done bit on the ADCON0 register is set HI. Once the GO/Done bit is clear the analog value on the pin is read from the ADC Buffer. Finally, the next pin is loaded into the ADCON0 register, and the settling timer is again set. This process repeats as the state machine cycles through all of the analog inputs.

The communication state machine has two parts, one for transmitting and one for receiving. When prompted to send a message the module pulls bytes from other modules(these other modules constantly update data based on user input) to form a packet. It sends the bytes one by one using interrupt flags to determine when to load the next packet into the transmit buffer. The module receives bytes by responding to interrupts that are raised when the RX buffer is loaded with a new byte. If the byte received is a proper start byte, it will begin tracking the incoming bytes in an array.

The GOGGLE(Controller) has a very simple state diagram at a high level. It initiates into a waiting to pair state, waiting for a button press to initiate a pairing attempt. Once this occurs, it commands the communication state machine to start sending pair messages to the targeted bot. If a acknowledgement is received back, it will move to the paired state and begin to send command packets to the targeted bot. This maintains until the user unpairs or the controller stops receiving messages back from the bot, indicating a break in communication.

G[OG]GLE Pseudocode

WHA:LE State Machines

WHA:LE Pseudocode

Code Files