Code Overview

You can download the communications protocol here.

You can download a zip of all of the COACH code here, and the TWORP code here.

COACH Master Code
The entire COACH is run off of one PIC. This include communications with the ZigBee radio, running the event checker and the event handler, and processing all I/O.
TOWRP Master Code
The TOWRP master PIC handles communications with the ZIGBEE radio, running the event checker and the event handler, and sending speed and direction commands to the slaves using SSP.
TOWRP Slave Motor Code
This PIC receives SSP signals and uses them to adjust the motor speed.
TOWRP Slave Servo Code
This PIC receives SSP signals and uses them to adjust the servo position.

Timing on the Master PICs

Use TIMER 0 for timing the state machine:
Timer0 overflow: 10MHz/4 = 2.5MHz / 256 / 256 = 38.15Hz = 26.2 ms
To create timers, for example:
for 5Hz, would check every 8 overflows = .2 seconds
for 1Hz, would check every 39 overflows = 1 second
for .2Hz, would check every 191 overflows = 5 seconds
SSP clock rate: 10MHz/ 16 = 625kHz