## Friday, November 05, 2010

### GAGA-1 Recovery Computer

Finally, got some time to work on the GAGA-1 Recovery Computer that uses a combination of a GPS and a GSM module to send position updates via SMS to a cell phone. The complete code is now in the repository in the gaga-1/recovery/ folder.

The recovery computer itself is a Telit GM862-GPS module mounted on a board that supplies power from four AA batteries. It has two external antennas: one for GPS and one for GSM access. Here's a shot of the computer before installation in the capsule (clearly the cables are going to have to be shortened and the power supply cleaned up before the real flight). The GPS antenna is square and the GSM is the long thin bar.

The GM862-GPS has an integrated Python interpreter so the control software is a set of Python modules that handle getting GPS information (and sundry information like temperature and voltage) and sending SMS messages at appropriate times. Here's the key piece of code for the recovery computer:
# The recovery computer runs through a sequence of simple states that# determine its behaviour.  It starts in the Launch state, transitions# to the Ascent mode once above a preset altitude, then moves to# Flight mode once too high for safe SMS usage.  Once below the safe# altitude it transitions to Recovery mode.state = ''set_state( 'LAUNCH' )sms.init()gps2.init()# The rules for the states are as follows:##   Launch: get GPS position every 1 minute and SMS, check for#   transition to Ascent mode##   Ascent: get GPS position every 2 minute and SMS, check for #   transition to flight mode##   Flight: get GPS position every 5 minutes and check for #   transition to Recovery mode##   Recovery: get GPS position every 1 minute and SMSwhile 1:    position = gps2.get()    if state == 'LAUNCH':        report_position(position)        if position['valid'] and            ( position['altitude'] > ascent_altitude ):            set_state( 'ASCENT' )    elif state == 'ASCENT':        report_position(position)        if position['valid'] and            ( position['altitude'] > flight_altitude ):            set_state( 'FLIGHT' )    elif state == 'FLIGHT':        if position['valid'] and            ( position['altitude'] < recovery_altitude ):            set_state( 'RECOVERY' )    elif state == 'RECOVERY':        report_position(position)    if state == 'LAUNCH' or state == 'RECOVERY':        delay = 1    elif state == 'ASCENT':        delay = 2    else:        delay = 5    MOD.sleep(delay * 600)

That code can be found in gaga-1.py which is the main module executed automatically by the GM862-GPS. The other important modules are logger.py (logs to the serial port for debugging and a file in the NVRAM on the GM862-GPS), at.py (simple wrapper for AT command access on the module), sms.py (module for sending SMS messages) and gps2.py (module to get GPS location).

There's a small Makefile the controls building and uploading of the code to the module (upload is achieved using the upload.pl helper program). The main commands are make all to build the code into compiled Python files, make upload to upload to the GM862-GPS and make test to run a flight simulation.

To test the code I've written modules that pretend to be the Telit Python modules (MDM, MOD, GPS, SER, etc.) and respond realistically to API calls and AT commands from my code. Within these modules I've programmed a simulated flight (an ascent, albeit a fast one, followed by descent) and random appearance of errors coming from the module (such as no GPS fix, no GSM access and other errors).

Here's a log of a simulated flight. You can see times when failures occurred (loss of GPS, can't send SMS: those lines are in red). I've highlighted the altitude in blue for easy reading.