X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=aoview%2Faoview_state.c;h=13b0f73b8c9ad07e3279974dfcdf04daf665814b;hp=85ed7b5a629964442e131793d87c949981aa6dae;hb=4ca2d910f3be689fd3c78a4f1be0555d6b1a30c1;hpb=4316b6af86b37522038e642235c163fcaad52e96 diff --git a/aoview/aoview_state.c b/aoview/aoview_state.c index 85ed7b5a..13b0f73b 100644 --- a/aoview/aoview_state.c +++ b/aoview/aoview_state.c @@ -18,19 +18,12 @@ #include "aoview.h" #include -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 int npad; static int npad_gps; static int prev_tick; static double prev_accel; -static double velocity; static double pad_lat; static double pad_lon; static double pad_alt; @@ -63,16 +56,70 @@ aoview_great_circle (double start_lat, double start_lon, } static void -aoview_state_add_deg(char *label, double deg) +aoview_state_add_deg(char *label, double deg, char pos, char neg) { double int_part; double min; + char sign = pos; + if (deg < 0) { + deg = -deg; + sign = neg; + } int_part = floor (deg); min = (deg - int_part) * 60.0; - aoview_table_add_row(label, "%d°%lf'", - (int) int_part, min); + aoview_table_add_row(label, "%d°%lf'%c", + (int) int_part, min, sign); + +} + +static char *ascent_states[] = { + "boost", + "fast", + "coast", + 0, +}; + +void +aoview_state_speak(struct aostate *state) +{ + static char last_state[32]; + int i; + gboolean report = FALSE; + static time_t last_time; + time_t this_time; + static int last_altitude; + int this_altitude; + + if (strcmp(state->state, last_state)) { + aoview_voice_speak("rocket state now %s\n", state->state); + if (!strcmp(state->state, "drogue")) + aoview_voice_speak("maximum altitude %d meters\n", + aoview_pres_to_altitude(min_pres) - + aoview_pres_to_altitude(state->ground_pres)); + report = TRUE; + strcpy(last_state, state->state); + } + this_time = time(NULL); + this_altitude = aoview_pres_to_altitude(state->flight_pres) - aoview_pres_to_altitude(state->ground_pres); + if (this_time - last_time >= 10) + report = TRUE; + if (this_altitude / 1000 != last_altitude / 1000) + report = TRUE; + + if (report) { + aoview_voice_speak("altitude %d meters\n", + this_altitude); + for (i = 0; ascent_states[i]; i++) + if (!strcmp(ascent_states[i], state->state)) { + aoview_voice_speak("speed %d meters per second\n", + state->flight_vel / 2700); + break; + } + } + last_time = this_time; + last_altitude = this_altitude; } void @@ -80,54 +127,39 @@ aoview_state_notify(struct aostate *state) { int altitude; double accel; - double velocity_change; int ticks; double dist; double bearing; double temp; + double velocity; double battery; double drogue_sense, main_sense; double max_accel; if (!strcmp(state->state, "pad")) { - if (npad < NUM_PAD_SAMPLES) { - pad_accel_total += state->accel; - pad_pres_total += state->pres; - if (state->locked) { - pad_lat_total += state->lat; - pad_lon_total += state->lon; - pad_alt_total += state->alt; - npad_gps++; - } - npad++; - velocity = 0; - } - 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 (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) { - npad++; - velocity = 0; - 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->pres < min_pres) - min_pres = state->pres; - if (state->accel < min_accel) - min_accel = state->accel; - altitude = aoview_pres_to_altitude(state->pres) - aoview_pres_to_altitude(pad_pres); - accel = (pad_accel - state->accel) / 264.8 * 9.80665; - max_accel = (pad_accel - min_accel) / 264.8 * 9.80665; - velocity_change = (accel + prev_accel) / 2.0; + 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(state->ground_pres); + accel = (state->ground_accel - state->flight_accel) / 27.0; + velocity = state->flight_vel / 2700.0; + max_accel = (state->ground_accel - min_accel) / 27.0; ticks = state->tick - prev_tick; - velocity -= velocity_change * (ticks / 100.0); temp = ((state->temp / 32767.0 * 3.3) - 0.5) / 0.01; battery = (state->batt / 32767.0 * 5.0); drogue_sense = (state->drogue / 32767.0 * 15.0); @@ -137,20 +169,20 @@ aoview_state_notify(struct aostate *state) 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", "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("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_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); @@ -158,16 +190,23 @@ 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("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_state_add_deg("Longitude", state->lon); + aoview_state_add_deg("Latitude", state->lat, 'N', 'S'); + aoview_state_add_deg("Longitude", state->lon, 'E', 'W'); aoview_table_add_row("GPS alt", "%d", state->alt); aoview_table_add_row("GPS time", "%02d:%02d:%02d", state->gps_time.hour, state->gps_time.minute, state->gps_time.second); + aoview_table_add_row("GPS ground speed", "%fm/s %d°", + state->ground_speed, + state->course); + aoview_table_add_row("GPS climb rate", "%fm/s", + state->climb_rate); + aoview_table_add_row("GPS precision", "%f(hdop) %dm(h) %dm(v)\n", + state->hdop, state->h_error, state->v_error); aoview_great_circle(pad_lat, pad_lon, state->lat, state->lon, &dist, &bearing); aoview_table_add_row("Distance from pad", "%gm", dist * 1000); @@ -176,23 +215,33 @@ aoview_state_notify(struct aostate *state) aoview_table_add_row("GPS", "unlocked"); } if (npad_gps) { - aoview_state_add_deg("Pad latitude", pad_lat); - aoview_state_add_deg("Pad longitude", pad_lon); + aoview_state_add_deg("Pad latitude", pad_lat, 'N', 'S'); + aoview_state_add_deg("Pad longitude", pad_lon, 'E', 'W'); aoview_table_add_row("Pad GPS alt", "%gm", pad_alt); } aoview_table_finish(); + aoview_state_speak(state); } void aoview_state_new(void) { + pad_lat_total = 0; + pad_lon_total = 0; + pad_alt_total = 0; + npad_gps = 0; + prev_tick = 0; + prev_accel = 0; + pad_lat = 0; + pad_lon = 0; + pad_alt = 0; min_pres = 32767; min_accel = 32767; - npad = 0; } void aoview_state_init(GladeXML *xml) { aoview_state_new(); + aoview_voice_speak("initializing rocket flight monitoring system\n"); }