Pass accel calibration over telemetry stream. Telemetry data format change.
authorKeith Packard <keithp@keithp.com>
Tue, 3 Nov 2009 08:40:38 +0000 (00:40 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 3 Nov 2009 08:40:38 +0000 (00:40 -0800)
This allows the ground station to convert the accelerometer sensor
values into acceleration and speed data. This requires a new telemetry
data structure, and so TeleMetrum and TeleDongle units must be updated
synchronously. ao-view will parse either telemetry stream, and the
serial format from TeleDongle now has a version number to allow for
future changes.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-view/aoview.h
ao-tools/ao-view/aoview_monitor.c
ao-tools/ao-view/aoview_state.c
src/ao.h
src/ao_monitor.c
src/ao_telemetry.c

index c582159..b6d5bcd 100644 (file)
@@ -104,6 +104,8 @@ struct aodata {
        int     flight_vel;
        int     flight_pres;
        int     ground_pres;
+       int     accel_plus_g;
+       int     accel_minus_g;
        struct aogps    gps;
        struct aogps_tracking   gps_tracking;
 };
index 48e2032..6d57f55 100644 (file)
@@ -77,7 +77,9 @@ gboolean
 aoview_monitor_parse(const char *input_line)
 {
        char *saveptr;
-       char *words[PARSE_MAX_WORDS];
+       char *raw_words[PARSE_MAX_WORDS];
+       char **words;
+       int version = 0;
        int nword;
        char line_buf[8192], *line;
        struct aodata   data;
@@ -89,13 +91,19 @@ aoview_monitor_parse(const char *input_line)
        line_buf[sizeof(line_buf) - 1] = '\0';
        line = line_buf;
        for (nword = 0; nword < PARSE_MAX_WORDS; nword++) {
-               words[nword] = strtok_r(line, " \t\n", &saveptr);
+               raw_words[nword] = strtok_r(line, " \t\n", &saveptr);
                line = NULL;
-               if (words[nword] == NULL)
+               if (raw_words[nword] == NULL)
                        break;
        }
        if (nword < 36)
                return FALSE;
+       words = raw_words;
+       if (strcmp(words[0], "VERSION") == 0) {
+               aoview_parse_int(&version, words[1]);
+               words += 2;
+               nword -= 2;
+       }
        if (strcmp(words[0], "CALL") != 0)
                return FALSE;
        aoview_parse_string(data.callsign, sizeof (data.callsign), words[1]);
@@ -115,6 +123,15 @@ aoview_monitor_parse(const char *input_line)
        aoview_parse_int(&data.flight_vel, words[28]);
        aoview_parse_int(&data.flight_pres, words[30]);
        aoview_parse_int(&data.ground_pres, words[32]);
+       if (version >= 1) {
+               aoview_parse_int(&data.accel_plus_g, words[34]);
+               aoview_parse_int(&data.accel_minus_g, words[36]);
+               words += 4;
+               nword -= 4;
+       } else {
+               data.accel_plus_g = data.ground_accel;
+               data.accel_minus_g = data.ground_accel + 530;
+       }
        aoview_parse_int(&data.gps.nsat, words[34]);
        if (strcmp (words[36], "unlocked") == 0) {
                data.gps.gps_connected = 1;
index f75066d..f8f0168 100644 (file)
@@ -105,6 +105,7 @@ aoview_state_derive(struct aodata *data, struct aostate *state)
        double  new_height;
        double  height_change;
        double  time_change;
+       double  accel_counts_per_mss;
        int     tick_count;
 
        state->report_time = aoview_time();
@@ -123,8 +124,9 @@ aoview_state_derive(struct aodata *data, struct aostate *state)
        state->height = new_height;
        if (time_change)
                state->baro_speed = (state->baro_speed * 3 + (height_change / time_change)) / 4.0;
-       state->acceleration = (data->ground_accel - data->flight_accel) / 27.0;
-       state->speed = data->flight_vel / 2700.0;
+       accel_counts_per_mss = ((data->accel_minus_g - data->accel_plus_g) / 2.0) / 9.80665;
+       state->acceleration = (data->ground_accel - data->flight_accel) / accel_counts_per_mss;
+       state->speed = data->flight_vel / (accel_counts_per_mss * 100.0);
        state->temperature = ((data->temp / 32767.0 * 3.3) - 0.5) / 0.01;
        state->drogue_sense = data->drogue / 32767.0 * 15.0;
        state->main_sense = data->main / 32767.0 * 15.0;
index 22e8785..bc9afcc 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -784,6 +784,7 @@ ao_gps_report_init(void);
  */
 
 #define AO_MAX_CALLSIGN                8
+#define AO_TELEMETRY_VERSION   1
 
 struct ao_telemetry {
        uint8_t                 addr;
@@ -793,6 +794,8 @@ struct ao_telemetry {
        int32_t                 flight_vel;
        int16_t                 flight_pres;
        int16_t                 ground_pres;
+       int16_t                 accel_plus_g;
+       int16_t                 accel_minus_g;
        struct ao_adc           adc;
        struct ao_gps_data      gps;
        char                    callsign[AO_MAX_CALLSIGN];
index d0c1da3..cd0d693 100644 (file)
@@ -37,12 +37,14 @@ ao_monitor(void)
                if (state > ao_flight_invalid)
                        state = ao_flight_invalid;
                if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) {
-                       printf ("CALL %s SERIAL %3d RSSI %4d STATUS %02x STATE %7s ",
-                               callsign,
-                               recv.telemetry.addr,
-                               (int) recv.rssi - 74, recv.status,
-                               ao_state_names[state]);
-                       printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d fa: %5d ga: %d fv: %7ld fp: %5d gp: %5d ",
+                       printf("VERSION %d CALL %s SERIAL %3d RSSI %4d STATUS %02x STATE %7s ",
+                              AO_TELEMETRY_VERSION,
+                              callsign,
+                              recv.telemetry.addr,
+                              (int) recv.rssi - 74, recv.status,
+                              ao_state_names[state]);
+                       printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d "
+                              "fa: %5d ga: %d fv: %7ld fp: %5d gp: %5d a+: %5d a-: %5d ",
                               recv.telemetry.adc.tick,
                               recv.telemetry.adc.accel,
                               recv.telemetry.adc.pres,
@@ -54,7 +56,9 @@ ao_monitor(void)
                               recv.telemetry.ground_accel,
                               recv.telemetry.flight_vel,
                               recv.telemetry.flight_pres,
-                              recv.telemetry.ground_pres);
+                              recv.telemetry.ground_pres,
+                              recv.telemetry.accel_plus_g,
+                              recv.telemetry.accel_minus_g);
                        ao_gps_print(&recv.telemetry.gps);
                        putchar(' ');
                        ao_gps_tracking_print(&recv.telemetry.gps_tracking);
index d52e589..9c92398 100644 (file)
@@ -32,6 +32,8 @@ ao_telemetry(void)
        ao_config_get();
        memcpy(telemetry.callsign, ao_config.callsign, AO_MAX_CALLSIGN);
        telemetry.addr = ao_serial_number;
+       telemetry.accel_plus_g = ao_config.accel_plus_g;
+       telemetry.accel_minus_g = ao_config.accel_minus_g;
        ao_rdf_time = ao_time();
        for (;;) {
                while (ao_telemetry_interval == 0)