Transmit computed ground pressure and acceleration values 0.4
authorKeith Packard <keithp@keithp.com>
Mon, 18 May 2009 06:36:21 +0000 (23:36 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 18 May 2009 06:36:21 +0000 (23:36 -0700)
These are the last two values relevant to figuring out the state of the
flight computer, and as they are computed by averaging 10 seconds of 100Hz
sample data, they're a lot more accurate than anything the receiver could do
on its own.

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

diff --git a/ao.h b/ao.h
index 315585293e9b25a51a44b3416ddb465e7f39e50e..411b950deb23c2e22bd26c2155825863d3609862 100644 (file)
--- a/ao.h
+++ b/ao.h
@@ -725,8 +725,10 @@ struct ao_telemetry {
        uint8_t                 addr;
        uint8_t                 flight_state;
        int16_t                 flight_accel;
        uint8_t                 addr;
        uint8_t                 flight_state;
        int16_t                 flight_accel;
+       int16_t                 ground_accel;
        int32_t                 flight_vel;
        int16_t                 flight_pres;
        int32_t                 flight_vel;
        int16_t                 flight_pres;
+       int16_t                 ground_pres;
        struct ao_adc           adc;
        struct ao_gps_data      gps;
        char                    callsign[AO_MAX_CALLSIGN];
        struct ao_adc           adc;
        struct ao_gps_data      gps;
        char                    callsign[AO_MAX_CALLSIGN];
index 880f257ca87d1ccfd52ec11882f48150d4f4f51b..5997d427a4388536687bf1a0c3a4c93238d655bb 100644 (file)
@@ -36,12 +36,12 @@ ao_monitor(void)
                if (state > ao_flight_invalid)
                        state = ao_flight_invalid;
                if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) {
                if (state > ao_flight_invalid)
                        state = ao_flight_invalid;
                if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) {
-                       printf ("CALL %s SERIAL %3d RSSI %3d STATUS %02x STATE %7s ",
+                       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]);
                                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 fv: %7ld fp: %5d ",
+                       printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d fa: %5d ga: %d fv: %7ld fp: %5d gp: %5d ",
                               recv.telemetry.adc.tick,
                               recv.telemetry.adc.accel,
                               recv.telemetry.adc.pres,
                               recv.telemetry.adc.tick,
                               recv.telemetry.adc.accel,
                               recv.telemetry.adc.pres,
@@ -50,8 +50,10 @@ ao_monitor(void)
                               recv.telemetry.adc.sense_d,
                               recv.telemetry.adc.sense_m,
                               recv.telemetry.flight_accel,
                               recv.telemetry.adc.sense_d,
                               recv.telemetry.adc.sense_m,
                               recv.telemetry.flight_accel,
+                              recv.telemetry.ground_accel,
                               recv.telemetry.flight_vel,
                               recv.telemetry.flight_vel,
-                              recv.telemetry.flight_pres);
+                              recv.telemetry.flight_pres,
+                              recv.telemetry.ground_pres);
                        ao_gps_print(&recv.telemetry.gps);
                        ao_rssi_set((int) recv.rssi - 74);
                } else {
                        ao_gps_print(&recv.telemetry.gps);
                        ao_rssi_set((int) recv.rssi - 74);
                } else {
index b4461e927a065811dbc5fb2cc93056b061bf456a..5cf9ca6134c3bfcc4de4e4cb3f9a7180f1a36a18 100644 (file)
@@ -37,8 +37,10 @@ ao_telemetry(void)
                        ao_sleep(&ao_telemetry_interval);
                telemetry.flight_state = ao_flight_state;
                telemetry.flight_accel = ao_flight_accel;
                        ao_sleep(&ao_telemetry_interval);
                telemetry.flight_state = ao_flight_state;
                telemetry.flight_accel = ao_flight_accel;
+               telemetry.ground_accel = ao_ground_accel;
                telemetry.flight_vel = ao_flight_vel;
                telemetry.flight_pres = ao_flight_pres;
                telemetry.flight_vel = ao_flight_vel;
                telemetry.flight_pres = ao_flight_pres;
+               telemetry.ground_pres = ao_ground_pres;
                ao_adc_get(&telemetry.adc);
                ao_mutex_get(&ao_gps_mutex);
                memcpy(&telemetry.gps, &ao_gps_data, sizeof (struct ao_gps_data));
                ao_adc_get(&telemetry.adc);
                ao_mutex_get(&ao_gps_mutex);
                memcpy(&telemetry.gps, &ao_gps_data, sizeof (struct ao_gps_data));
index 44412bec53b66ed66cb5296f8a9fdf5463678340..4abbde88839ca0c8bdd4420dc3ff0c62824b9cde 100644 (file)
@@ -59,8 +59,10 @@ struct aostate {
        int     drogue;
        int     main;
        int     flight_accel;
        int     drogue;
        int     main;
        int     flight_accel;
+       int     ground_accel;
        int     flight_vel;
        int     flight_pres;
        int     flight_vel;
        int     flight_pres;
+       int     ground_pres;
        int     nsat;
        int     locked;
        struct {
        int     nsat;
        int     locked;
        struct {
index b0189c60698d2777935596773f2ae1054c8f6123..7a04c82f88a653e31d32f189ab9104bda94c0a33 100644 (file)
@@ -82,7 +82,7 @@ aoview_monitor_parse(char *line)
                if (words[nword] == NULL)
                        break;
        }
                if (words[nword] == NULL)
                        break;
        }
-       if (nword < 32)
+       if (nword < 36)
                return;
        if (strcmp(words[0], "CALL") != 0)
                return;
                return;
        if (strcmp(words[0], "CALL") != 0)
                return;
@@ -101,15 +101,17 @@ aoview_monitor_parse(char *line)
        aoview_parse_int(&state.drogue, words[20]);
        aoview_parse_int(&state.main, words[22]);
        aoview_parse_int(&state.flight_accel, words[24]);
        aoview_parse_int(&state.drogue, words[20]);
        aoview_parse_int(&state.main, words[22]);
        aoview_parse_int(&state.flight_accel, words[24]);
-       aoview_parse_int(&state.flight_vel, words[26]);
-       aoview_parse_int(&state.flight_pres, words[28]);
-       aoview_parse_int(&state.nsat, words[30]);
-       if (strcmp (words[32], "unlocked") != 0 && nword >= 35) {
+       aoview_parse_int(&state.ground_accel, words[26]);
+       aoview_parse_int(&state.flight_vel, words[28]);
+       aoview_parse_int(&state.flight_pres, words[30]);
+       aoview_parse_int(&state.ground_pres, words[32]);
+       aoview_parse_int(&state.nsat, words[34]);
+       if (strcmp (words[36], "unlocked") != 0 && nword >= 41) {
                state.locked = 1;
                state.locked = 1;
-               sscanf(words[32], "%d:%d:%d", &state.gps_time.hour, &state.gps_time.minute, &state.gps_time.second);
-               aoview_parse_pos(&state.lat, words[33]);
-               aoview_parse_pos(&state.lon, words[34]);
-               sscanf(words[35], "%dm", &state.alt);
+               sscanf(words[36], "%d:%d:%d", &state.gps_time.hour, &state.gps_time.minute, &state.gps_time.second);
+               aoview_parse_pos(&state.lat, words[39]);
+               aoview_parse_pos(&state.lon, words[40]);
+               sscanf(words[41], "%dm", &state.alt);
        } else {
                state.locked = 0;
                state.gps_time.hour = state.gps_time.minute = state.gps_time.second = 0;
        } else {
                state.locked = 0;
                state.gps_time.hour = state.gps_time.minute = state.gps_time.second = 0;
index dda92af9a2993277ca4f62ec3bc1430e05c01d1c..02ae0307c249ac9cb7c736de7ff649a1edf576e6 100644 (file)
 #include "aoview.h"
 #include <math.h>
 
 #include "aoview.h"
 #include <math.h>
 
-static int     pad_pres;
-static int     pad_accel;
-static int     pad_pres_total;
-static int     pad_accel_total;
 static double  pad_lat_total;
 static double  pad_lon_total;
 static int     pad_alt_total;
 static double  pad_lat_total;
 static double  pad_lon_total;
 static int     pad_alt_total;
-static int     npad;
 static int     npad_gps;
 static int     prev_tick;
 static double  prev_accel;
 static int     npad_gps;
 static int     prev_tick;
 static double  prev_accel;
@@ -88,40 +83,28 @@ aoview_state_notify(struct aostate *state)
        double  max_accel;
 
        if (!strcmp(state->state, "pad")) {
        double  max_accel;
 
        if (!strcmp(state->state, "pad")) {
-               if (npad < NUM_PAD_SAMPLES) {
-                       pad_accel_total += state->flight_accel;
-                       pad_pres_total += state->flight_pres;
-                       if (state->locked) {
-                               pad_lat_total += state->lat;
-                               pad_lon_total += state->lon;
-                               pad_alt_total += state->alt;
-                               npad_gps++;
-                       }
-                       npad++;
+               if (state->locked && npad_gps < NUM_PAD_SAMPLES) {
+                       pad_lat_total += state->lat;
+                       pad_lon_total += state->lon;
+                       pad_alt_total += state->alt;
+                       npad_gps++;
                }
                }
-               if (npad <= NUM_PAD_SAMPLES) {
-                       pad_pres = pad_pres_total / npad;
-                       pad_accel = pad_accel_total / npad;
-                       if (npad_gps) {
-                               pad_lat = pad_lat_total / npad_gps;
-                               pad_lon = pad_lon_total / npad_gps;
-                               pad_alt = pad_alt_total / npad_gps;
-                       }
-               }
-               if (npad == NUM_PAD_SAMPLES) {
-                       npad++;
-                       min_pres = pad_pres;
-                       min_accel = pad_accel;
+               if (state->locked && npad_gps <= NUM_PAD_SAMPLES) {
+                       pad_lat = pad_lat_total / npad_gps;
+                       pad_lon = pad_lon_total / npad_gps;
+                       pad_alt = pad_alt_total / npad_gps;
                }
                }
+               min_pres = state->ground_pres;
+               min_accel = state->ground_accel;
        }
        if (state->flight_pres < min_pres)
                min_pres = state->flight_pres;
        if (state->flight_accel < min_accel)
                min_accel = state->flight_accel;
        }
        if (state->flight_pres < min_pres)
                min_pres = state->flight_pres;
        if (state->flight_accel < min_accel)
                min_accel = state->flight_accel;
-       altitude = aoview_pres_to_altitude(state->flight_pres) - aoview_pres_to_altitude(pad_pres);
-       accel = (pad_accel - state->flight_accel) / 27.0;
+       altitude = aoview_pres_to_altitude(state->flight_pres) - aoview_pres_to_altitude(state->ground_pres);
+       accel = (state->ground_accel - state->flight_accel) / 27.0;
        velocity = state->flight_vel / 2700.0;
        velocity = state->flight_vel / 2700.0;
-       max_accel = (pad_accel - min_accel) / 27.0;
+       max_accel = (state->ground_accel - min_accel) / 27.0;
        ticks = state->tick - prev_tick;
        temp = ((state->temp / 32767.0 * 3.3) - 0.5) / 0.01;
        battery = (state->batt / 32767.0 * 5.0);
        ticks = state->tick - prev_tick;
        temp = ((state->temp / 32767.0 * 3.3) - 0.5) / 0.01;
        battery = (state->batt / 32767.0 * 5.0);
@@ -132,20 +115,20 @@ aoview_state_notify(struct aostate *state)
        prev_tick = state->tick;
        aoview_table_start();
 
        prev_tick = state->tick;
        aoview_table_start();
 
-       if (npad >= NUM_PAD_SAMPLES)
+       if (npad_gps >= NUM_PAD_SAMPLES)
                aoview_table_add_row("Ground state", "ready");
        else
                aoview_table_add_row("Ground state", "ready");
        else
-               aoview_table_add_row("Ground state", "preparing (%d)",
-                                    NUM_PAD_SAMPLES - npad);
+               aoview_table_add_row("Ground state", "waiting for gps (%d)",
+                                    NUM_PAD_SAMPLES - npad_gps);
        aoview_table_add_row("Rocket state", "%s", state->state);
        aoview_table_add_row("Callsign", "%s", state->callsign);
        aoview_table_add_row("Rocket serial", "%d", state->serial);
 
        aoview_table_add_row("Rocket state", "%s", state->state);
        aoview_table_add_row("Callsign", "%s", state->callsign);
        aoview_table_add_row("Rocket serial", "%d", state->serial);
 
-       aoview_table_add_row("RSSI", "%ddB", state->rssi);
+       aoview_table_add_row("RSSI", "%ddBm", state->rssi);
        aoview_table_add_row("Height", "%dm", altitude);
        aoview_table_add_row("Max height", "%dm",
                             aoview_pres_to_altitude(min_pres) -
        aoview_table_add_row("Height", "%dm", altitude);
        aoview_table_add_row("Max height", "%dm",
                             aoview_pres_to_altitude(min_pres) -
-                            aoview_pres_to_altitude(pad_pres));
+                            aoview_pres_to_altitude(state->ground_pres));
        aoview_table_add_row("Acceleration", "%gm/s²", accel);
        aoview_table_add_row("Max acceleration", "%gm/s²", max_accel);
        aoview_table_add_row("Velocity", "%gm/s", velocity);
        aoview_table_add_row("Acceleration", "%gm/s²", accel);
        aoview_table_add_row("Max acceleration", "%gm/s²", max_accel);
        aoview_table_add_row("Velocity", "%gm/s", velocity);
@@ -153,7 +136,7 @@ aoview_state_notify(struct aostate *state)
        aoview_table_add_row("Battery", "%gV", battery);
        aoview_table_add_row("Drogue", "%gV", drogue_sense);
        aoview_table_add_row("Main", "%gV", main_sense);
        aoview_table_add_row("Battery", "%gV", battery);
        aoview_table_add_row("Drogue", "%gV", drogue_sense);
        aoview_table_add_row("Main", "%gV", main_sense);
-       aoview_table_add_row("Pad altitude", "%dm", aoview_pres_to_altitude(pad_pres));
+       aoview_table_add_row("Pad altitude", "%dm", aoview_pres_to_altitude(state->ground_pres));
        aoview_table_add_row("Satellites", "%d", state->nsat);
        if (state->locked) {
                aoview_state_add_deg("Latitude", state->lat);
        aoview_table_add_row("Satellites", "%d", state->nsat);
        if (state->locked) {
                aoview_state_add_deg("Latitude", state->lat);
@@ -181,14 +164,9 @@ aoview_state_notify(struct aostate *state)
 void
 aoview_state_new(void)
 {
 void
 aoview_state_new(void)
 {
-       pad_pres = 0;
-       pad_accel = 0;
-       pad_pres_total = 0;
-       pad_accel_total = 0;
        pad_lat_total = 0;
        pad_lon_total = 0;
        pad_alt_total = 0;
        pad_lat_total = 0;
        pad_lon_total = 0;
        pad_alt_total = 0;
-       npad = 0;
        npad_gps = 0;
        prev_tick = 0;
        prev_accel = 0;
        npad_gps = 0;
        prev_tick = 0;
        prev_accel = 0;