2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 static double pad_lat_total;
22 static double pad_lon_total;
23 static int pad_alt_total;
26 static double prev_accel;
27 static double pad_lat;
28 static double pad_lon;
29 static double pad_alt;
30 static double min_pres;
31 static double min_accel;
33 #define NUM_PAD_SAMPLES 10
36 aoview_great_circle (double start_lat, double start_lon,
37 double end_lat, double end_lon,
38 double *dist, double *bearing)
40 double rad = M_PI / 180;
41 double earth_radius = 6371.2;
42 double lat1 = rad * start_lat;
43 double lon1 = -rad * start_lon;
44 double lat2 = rad * end_lat;
45 double lon2 = -rad * end_lon;
47 double d = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2));
48 double argacos = (sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1));
50 if (sin(lon2-lon1) < 0)
53 crs = 2 * M_PI - acos(argacos);
54 *dist = d * earth_radius;
55 *bearing = crs * 180/M_PI;
59 aoview_state_add_deg(char *label, double deg, char pos, char neg)
69 int_part = floor (deg);
70 min = (deg - int_part) * 60.0;
71 aoview_table_add_row(label, "%d°%lf'%c",
72 (int) int_part, min, sign);
76 static char *ascent_states[] = {
84 aoview_state_speak(struct aostate *state)
86 static char last_state[32];
88 gboolean report = FALSE;
89 static time_t last_time;
91 static int last_altitude;
94 if (strcmp(state->state, last_state)) {
95 aoview_voice_speak("rocket state now %s\n", state->state);
96 if (!strcmp(state->state, "drogue"))
97 aoview_voice_speak("maximum altitude %d meters\n",
98 aoview_pres_to_altitude(min_pres) -
99 aoview_pres_to_altitude(state->ground_pres));
101 strcpy(last_state, state->state);
103 this_time = time(NULL);
104 this_altitude = aoview_pres_to_altitude(state->flight_pres) - aoview_pres_to_altitude(state->ground_pres);
105 if (this_time - last_time >= 10)
107 if (this_altitude / 1000 != last_altitude / 1000)
111 aoview_voice_speak("altitude %d meters\n",
113 for (i = 0; ascent_states[i]; i++)
114 if (!strcmp(ascent_states[i], state->state)) {
115 aoview_voice_speak("speed %d meters per second\n",
116 state->flight_vel / 2700);
121 last_time = this_time;
122 last_altitude = this_altitude;
126 aoview_state_notify(struct aostate *state)
136 double drogue_sense, main_sense;
139 if (!strcmp(state->state, "pad")) {
140 if (state->locked && npad_gps < NUM_PAD_SAMPLES) {
141 pad_lat_total += state->lat;
142 pad_lon_total += state->lon;
143 pad_alt_total += state->alt;
146 if (state->locked && npad_gps <= NUM_PAD_SAMPLES) {
147 pad_lat = pad_lat_total / npad_gps;
148 pad_lon = pad_lon_total / npad_gps;
149 pad_alt = pad_alt_total / npad_gps;
151 min_pres = state->ground_pres;
152 min_accel = state->ground_accel;
154 if (state->flight_pres < min_pres)
155 min_pres = state->flight_pres;
156 if (state->flight_accel < min_accel)
157 min_accel = state->flight_accel;
158 altitude = aoview_pres_to_altitude(state->flight_pres) - aoview_pres_to_altitude(state->ground_pres);
159 accel = (state->ground_accel - state->flight_accel) / 27.0;
160 velocity = state->flight_vel / 2700.0;
161 max_accel = (state->ground_accel - min_accel) / 27.0;
162 ticks = state->tick - prev_tick;
163 temp = ((state->temp / 32767.0 * 3.3) - 0.5) / 0.01;
164 battery = (state->batt / 32767.0 * 5.0);
165 drogue_sense = (state->drogue / 32767.0 * 15.0);
166 main_sense = (state->main / 32767.0 * 15.0);
169 prev_tick = state->tick;
170 aoview_table_start();
172 if (npad_gps >= NUM_PAD_SAMPLES)
173 aoview_table_add_row("Ground state", "ready");
175 aoview_table_add_row("Ground state", "waiting for gps (%d)",
176 NUM_PAD_SAMPLES - npad_gps);
177 aoview_table_add_row("Rocket state", "%s", state->state);
178 aoview_table_add_row("Callsign", "%s", state->callsign);
179 aoview_table_add_row("Rocket serial", "%d", state->serial);
181 aoview_table_add_row("RSSI", "%ddBm", state->rssi);
182 aoview_table_add_row("Height", "%dm", altitude);
183 aoview_table_add_row("Max height", "%dm",
184 aoview_pres_to_altitude(min_pres) -
185 aoview_pres_to_altitude(state->ground_pres));
186 aoview_table_add_row("Acceleration", "%gm/s²", accel);
187 aoview_table_add_row("Max acceleration", "%gm/s²", max_accel);
188 aoview_table_add_row("Velocity", "%gm/s", velocity);
189 aoview_table_add_row("Temperature", "%g°C", temp);
190 aoview_table_add_row("Battery", "%gV", battery);
191 aoview_table_add_row("Drogue", "%gV", drogue_sense);
192 aoview_table_add_row("Main", "%gV", main_sense);
193 aoview_table_add_row("Pad altitude", "%dm", aoview_pres_to_altitude(state->ground_pres));
194 aoview_table_add_row("Satellites", "%d", state->nsat);
196 aoview_state_add_deg("Latitude", state->lat, 'N', 'S');
197 aoview_state_add_deg("Longitude", state->lon, 'E', 'W');
198 aoview_table_add_row("GPS alt", "%d", state->alt);
199 aoview_table_add_row("GPS time", "%02d:%02d:%02d",
200 state->gps_time.hour,
201 state->gps_time.minute,
202 state->gps_time.second);
203 aoview_table_add_row("GPS ground speed", "%fm/s %d°",
206 aoview_table_add_row("GPS climb rate", "%fm/s",
208 aoview_table_add_row("GPS precision", "%f(hdop) %dm(h) %dm(v)\n",
209 state->hdop, state->h_error, state->v_error);
210 aoview_great_circle(pad_lat, pad_lon, state->lat, state->lon,
212 aoview_table_add_row("Distance from pad", "%gm", dist * 1000);
213 aoview_table_add_row("Direction from pad", "%g°", bearing);
215 aoview_table_add_row("GPS", "unlocked");
218 aoview_state_add_deg("Pad latitude", pad_lat, 'N', 'S');
219 aoview_state_add_deg("Pad longitude", pad_lon, 'E', 'W');
220 aoview_table_add_row("Pad GPS alt", "%gm", pad_alt);
222 aoview_table_finish();
223 aoview_state_speak(state);
227 aoview_state_new(void)
243 aoview_state_init(GladeXML *xml)
246 aoview_voice_speak("initializing rocket flight monitoring system\n");