The software for the BARNACOAL consists of a flat state machine with the Wait 4 Message state that processes all messages received from the SPECTACOAL byte by byte and changes the status of the thrusters and dumping servo accordingly. When the fuel counter runs out, BARNACOAL automatically enters recharge mode and the SPECTACOAL will have to enter recharge mode and perform the respective recharge action in order to refuel the fuel Gauge.
This module contains the flat state machine that processes the messages the BARNACOAL receives. The module will first check if a SPECTACOAL has sent a pairing message and, once paired, will ignore pairing messages from other SPECTACOALs. It checks each 13-byte (as specified in the communications protocol) message received byte by byte and adjusts the direction the BARNACOAL moves and the status of the rotating wall accordingly (whether or not it is currently dumping or not). When the BARNACOAL first receives a byte of data, it will check it with respect to the Xbee RX packet frame structure and increment a bytecounter that starts at 0. If the 3rd byte of the message received does not have the correct LSB of 0x09, the rest of the message is ignored but the bytecounter will be continually incremented until it reaches a threshold of 13 to ensure that the next correct message received will be correctly processed. With each byte of data received, the BARNACOAL will adjusts its outputs accordingly based on the information provided in each RX data packet as specified in the communications protocol. Additionally, every 0.2 seconds the BARNACOAL will send a message containing how much fuel is left to the paired SPECTACOAL.
This module is responsible for converting inputs received from the SPECTACOAL into outputs on the BARNACOAL such as the joystick values into the PWM of the left and right thrusters as well as the servo connected to the rotating wall being lowered or not.