altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / altosuilib / AltosGraph.java
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altosuilib_14;
20
21 import java.io.*;
22 import java.util.ArrayList;
23
24 import java.awt.*;
25 import javax.swing.*;
26 import org.altusmetrum.altoslib_14.*;
27
28 import org.jfree.ui.*;
29 import org.jfree.chart.*;
30 import org.jfree.chart.plot.*;
31 import org.jfree.chart.axis.*;
32 import org.jfree.chart.renderer.*;
33 import org.jfree.chart.renderer.xy.*;
34 import org.jfree.chart.labels.*;
35 import org.jfree.data.xy.*;
36 import org.jfree.data.*;
37
38 public class AltosGraph extends AltosUIGraph {
39
40         /* These are in 'priority' order so that earlier ones get simpler line styles,
41          * then they are grouped so that adjacent ones get sequential colors
42          */
43         static final private AltosUILineStyle height_color = new AltosUILineStyle();
44         static final private AltosUILineStyle speed_color = new AltosUILineStyle();
45         static final private AltosUILineStyle accel_color = new AltosUILineStyle();
46         static final private AltosUILineStyle vert_accel_color = new AltosUILineStyle();
47         static final private AltosUILineStyle orient_color = new AltosUILineStyle();
48         static final private AltosUILineStyle azimuth_color = new AltosUILineStyle();
49         static final private AltosUILineStyle compass_color = new AltosUILineStyle();
50
51         static final private AltosUILineStyle gps_height_color = new AltosUILineStyle();
52         static final private AltosUILineStyle altitude_color = new AltosUILineStyle();
53
54         static final private AltosUILineStyle battery_voltage_color = new AltosUILineStyle();
55         static final private AltosUILineStyle pyro_voltage_color = new AltosUILineStyle();
56         static final private AltosUILineStyle drogue_voltage_color = new AltosUILineStyle();
57         static final private AltosUILineStyle main_voltage_color = new AltosUILineStyle();
58         static final private AltosUILineStyle igniter_marker_color = new AltosUILineStyle(1);
59
60         static final private AltosUILineStyle kalman_height_color = new AltosUILineStyle();
61         static final private AltosUILineStyle kalman_speed_color = new AltosUILineStyle();
62         static final private AltosUILineStyle kalman_accel_color = new AltosUILineStyle();
63
64         static final private AltosUILineStyle gps_nsat_color = new AltosUILineStyle ();
65         static final private AltosUILineStyle gps_nsat_solution_color = new AltosUILineStyle ();
66         static final private AltosUILineStyle gps_nsat_view_color = new AltosUILineStyle ();
67         static final private AltosUILineStyle gps_course_color = new AltosUILineStyle ();
68         static final private AltosUILineStyle gps_ground_speed_color = new AltosUILineStyle ();
69         static final private AltosUILineStyle gps_speed_color = new AltosUILineStyle ();
70         static final private AltosUILineStyle gps_climb_rate_color = new AltosUILineStyle ();
71         static final private AltosUILineStyle gps_pdop_color = new AltosUILineStyle();
72         static final private AltosUILineStyle gps_hdop_color = new AltosUILineStyle();
73         static final private AltosUILineStyle gps_vdop_color = new AltosUILineStyle();
74
75         static final private AltosUILineStyle temperature_color = new AltosUILineStyle ();
76         static final private AltosUILineStyle dbm_color = new AltosUILineStyle();
77         static final private AltosUILineStyle pressure_color = new AltosUILineStyle ();
78
79         static final private AltosUILineStyle state_color = new AltosUILineStyle(0);
80         static final private AltosUILineStyle accel_along_color = new AltosUILineStyle();
81         static final private AltosUILineStyle accel_across_color = new AltosUILineStyle();
82         static final private AltosUILineStyle accel_through_color = new AltosUILineStyle();
83         static final private AltosUILineStyle gyro_roll_color = new AltosUILineStyle();
84         static final private AltosUILineStyle gyro_pitch_color = new AltosUILineStyle();
85         static final private AltosUILineStyle gyro_yaw_color = new AltosUILineStyle();
86         static final private AltosUILineStyle mag_along_color = new AltosUILineStyle();
87         static final private AltosUILineStyle mag_across_color = new AltosUILineStyle();
88         static final private AltosUILineStyle mag_through_color = new AltosUILineStyle();
89         static final private AltosUILineStyle mag_total_color = new AltosUILineStyle();
90
91         static final private AltosUILineStyle motor_pressure_color = new AltosUILineStyle();
92
93         static AltosUnits dop_units = null;
94         static AltosUnits tick_units = null;
95
96         AltosUIFlightSeries flight_series;
97
98         boolean enable_axis(int product_id, String label) {
99                 switch (product_id) {
100                 case AltosLib.product_easymotor:
101                         return(label.equals(AltosUIFlightSeries.motor_pressure_name) ||
102                                label.equals(AltosUIFlightSeries.accel_name));
103                 default:
104                         return true;
105                 }
106         }
107
108         AltosUITimeSeries[] setup(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
109                 AltosCalData    cal_data = flight_series.cal_data();
110                 int             product_id = cal_data.device_type;
111
112                 AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
113                 AltosUIAxis     pressure_axis, thrust_axis;
114                 AltosUIAxis     gyro_axis, orient_axis, mag_axis;
115                 AltosUIAxis     course_axis, dop_axis, tick_axis;
116                 AltosUIAxis     motor_pressure_axis;
117
118                 if (stats != null && stats.serial != AltosLib.MISSING && stats.product != null && stats.flight != AltosLib.MISSING)
119                         setName(String.format("%s %d flight %d\n", stats.product, stats.serial, stats.flight));
120
121                 height_axis = newAxis("Height", AltosConvert.height, height_color);
122                 pressure_axis = newAxis("Pressure", AltosConvert.pressure, pressure_color, 0);
123                 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
124                 thrust_axis = newAxis("Thrust", AltosConvert.force, accel_color);
125                 tick_axis = newAxis("Tick", tick_units, accel_color, 0);
126                 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
127                 voltage_axis = newAxis("Voltage", AltosConvert.voltage, battery_voltage_color);
128                 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
129                 nsat_axis = newAxis("Satellites", null, gps_nsat_color,
130                                     AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
131                 dbm_axis = newAxis("Signal Strength", null, dbm_color, 0);
132
133                 gyro_axis = newAxis("Rotation Rate", AltosConvert.rotation_rate, gyro_roll_color, 0);
134                 orient_axis = newAxis("Angle", AltosConvert.orient, orient_color, 0);
135                 mag_axis = newAxis("Magnetic Field", AltosConvert.magnetic_field, mag_along_color, 0);
136                 course_axis = newAxis("Course", AltosConvert.orient, gps_course_color, 0);
137                 dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0);
138
139                 motor_pressure_axis = newAxis("Motor Pressure", AltosConvert.pressure, motor_pressure_color, 0);
140
141                 flight_series.register_axis("default",
142                                             speed_color,
143                                             false,
144                                             speed_axis);
145
146                 flight_series.register_marker(AltosUIFlightSeries.state_name,
147                                               state_color,
148                                               enable_axis(product_id, AltosUIFlightSeries.state_name),
149                                               plot,
150                                               true);
151
152                 flight_series.register_marker(AltosUIFlightSeries.pyro_fired_name,
153                                               igniter_marker_color,
154                                               true,
155                                               plot,
156                                               false);
157
158                 flight_series.register_axis(AltosUIFlightSeries.tick_name,
159                                             accel_color,
160                                             false,
161                                             tick_axis);
162
163                 flight_series.register_axis(AltosUIFlightSeries.accel_name,
164                                             accel_color,
165                                             enable_axis(product_id, AltosUIFlightSeries.accel_name),
166                                             accel_axis);
167
168                 flight_series.register_axis(AltosUIFlightSeries.vert_accel_name,
169                                             vert_accel_color,
170                                             enable_axis(product_id, AltosUIFlightSeries.vert_accel_name),
171                                             accel_axis);
172
173                 flight_series.register_axis(AltosUIFlightSeries.kalman_accel_name,
174                                             kalman_accel_color,
175                                             false,
176                                             accel_axis);
177
178                 flight_series.register_axis(AltosUIFlightSeries.rssi_name,
179                                             dbm_color,
180                                             false,
181                                             dbm_axis);
182
183                 flight_series.register_axis(AltosUIFlightSeries.speed_name,
184                                             speed_color,
185                                             enable_axis(product_id, AltosUIFlightSeries.speed_name),
186                                             speed_axis);
187
188                 flight_series.register_axis(AltosUIFlightSeries.kalman_speed_name,
189                                             kalman_speed_color,
190                                             enable_axis(product_id, AltosUIFlightSeries.kalman_speed_name),
191                                             speed_axis);
192
193                 flight_series.register_axis(AltosUIFlightSeries.pressure_name,
194                                             pressure_color,
195                                             false,
196                                             pressure_axis);
197
198                 flight_series.register_axis(AltosUIFlightSeries.height_name,
199                                             height_color,
200                                             enable_axis(product_id, AltosUIFlightSeries.height_name),
201                                             height_axis);
202
203                 flight_series.register_axis(AltosUIFlightSeries.altitude_name,
204                                             altitude_color,
205                                             false,
206                                             height_axis);
207
208                 flight_series.register_axis(AltosUIFlightSeries.kalman_height_name,
209                                             kalman_height_color,
210                                             false,
211                                             height_axis);
212
213
214                 flight_series.register_axis(AltosUIFlightSeries.temperature_name,
215                                             temperature_color,
216                                             false,
217                                             temperature_axis);
218
219                 flight_series.register_axis(AltosUIFlightSeries.battery_voltage_name,
220                                             battery_voltage_color,
221                                             false,
222                                             voltage_axis);
223
224                 flight_series.register_axis(AltosUIFlightSeries.pyro_voltage_name,
225                                             pyro_voltage_color,
226                                             false,
227                                             voltage_axis);
228
229                 flight_series.register_axis(AltosUIFlightSeries.apogee_voltage_name,
230                                             drogue_voltage_color,
231                                             false,
232                                             voltage_axis);
233
234                 flight_series.register_axis(AltosUIFlightSeries.main_voltage_name,
235                                             main_voltage_color,
236                                             false,
237                                             voltage_axis);
238
239                 flight_series.register_axis(AltosUIFlightSeries.sats_in_view_name,
240                                             gps_nsat_view_color,
241                                             false,
242                                             nsat_axis);
243
244                 flight_series.register_axis(AltosUIFlightSeries.sats_in_soln_name,
245                                             gps_nsat_solution_color,
246                                             false,
247                                             nsat_axis);
248
249                 flight_series.register_axis(AltosUIFlightSeries.gps_pdop_name,
250                                             gps_pdop_color,
251                                             false,
252                                             dop_axis);
253
254                 flight_series.register_axis(AltosUIFlightSeries.gps_hdop_name,
255                                             gps_hdop_color,
256                                             false,
257                                             dop_axis);
258
259                 flight_series.register_axis(AltosUIFlightSeries.gps_vdop_name,
260                                             gps_vdop_color,
261                                             false,
262                                             dop_axis);
263
264                 flight_series.register_axis(AltosUIFlightSeries.gps_altitude_name,
265                                             gps_height_color,
266                                             false,
267                                             height_axis);
268
269                 flight_series.register_axis(AltosUIFlightSeries.gps_height_name,
270                                             gps_height_color,
271                                             false,
272                                             height_axis);
273
274                 flight_series.register_axis(AltosUIFlightSeries.gps_ground_speed_name,
275                                             gps_ground_speed_color,
276                                             false,
277                                             speed_axis);
278
279                 flight_series.register_axis(AltosUIFlightSeries.gps_ascent_rate_name,
280                                             gps_climb_rate_color,
281                                             false,
282                                             speed_axis);
283
284                 flight_series.register_axis(AltosUIFlightSeries.gps_course_name,
285                                             gps_course_color,
286                                             false,
287                                             course_axis);
288
289                 flight_series.register_axis(AltosUIFlightSeries.gps_speed_name,
290                                             gps_speed_color,
291                                             false,
292                                             speed_axis);
293
294                 flight_series.register_axis(AltosUIFlightSeries.accel_along_name,
295                                             accel_along_color,
296                                             false,
297                                             accel_axis);
298
299                 flight_series.register_axis(AltosUIFlightSeries.accel_across_name,
300                                             accel_across_color,
301                                             false,
302                                             accel_axis);
303
304                 flight_series.register_axis(AltosUIFlightSeries.accel_through_name,
305                                             accel_through_color,
306                                             false,
307                                             accel_axis);
308
309                 flight_series.register_axis(AltosUIFlightSeries.gyro_roll_name,
310                                             gyro_roll_color,
311                                             false,
312                                             gyro_axis);
313
314                 flight_series.register_axis(AltosUIFlightSeries.gyro_pitch_name,
315                                             gyro_pitch_color,
316                                             false,
317                                             gyro_axis);
318
319                 flight_series.register_axis(AltosUIFlightSeries.gyro_yaw_name,
320                                             gyro_yaw_color,
321                                             false,
322                                             gyro_axis);
323
324                 flight_series.register_axis(AltosUIFlightSeries.mag_along_name,
325                                             mag_along_color,
326                                             false,
327                                             mag_axis);
328
329                 flight_series.register_axis(AltosUIFlightSeries.mag_across_name,
330                                             mag_across_color,
331                                             false,
332                                             mag_axis);
333
334                 flight_series.register_axis(AltosUIFlightSeries.mag_through_name,
335                                             mag_through_color,
336                                             false,
337                                             mag_axis);
338
339                 flight_series.register_axis(AltosUIFlightSeries.mag_total_name,
340                                             mag_total_color,
341                                             false,
342                                             mag_axis);
343
344                 flight_series.register_axis(AltosUIFlightSeries.orient_name,
345                                             orient_color,
346                                             false,
347                                             orient_axis);
348
349                 flight_series.register_axis(AltosUIFlightSeries.azimuth_name,
350                                             azimuth_color,
351                                             false,
352                                             orient_axis);
353
354                 flight_series.register_axis(AltosUIFlightSeries.compass_name,
355                                             compass_color,
356                                             false,
357                                             orient_axis);
358
359                 flight_series.register_axis(AltosUIFlightSeries.thrust_name,
360                                             accel_color,
361                                             enable_axis(product_id, AltosUIFlightSeries.thrust_name),
362                                             thrust_axis);
363
364                 for (int channel = 0; channel < 8; channel++) {
365                         flight_series.register_axis(flight_series.igniter_voltage_name(channel),
366                                                     new AltosUILineStyle(),
367                                                     false,
368                                                     voltage_axis);
369                 }
370
371                 flight_series.register_axis(AltosUIFlightSeries.motor_pressure_name,
372                                             motor_pressure_color,
373                                             enable_axis(product_id, AltosUIFlightSeries.motor_pressure_name),
374                                             motor_pressure_axis);
375
376                 flight_series.check_axes();
377
378                 return flight_series.series(cal_data);
379         }
380
381         public void set_data(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
382                 set_series(setup(stats, flight_series));
383         }
384
385         public AltosGraph(AltosUIEnable enable) {
386                 super(enable, "Flight");
387         }
388
389         public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosUIFlightSeries flight_series) {
390                 this(enable);
391                 this.flight_series = flight_series;
392                 set_series(setup(stats, flight_series));
393         }
394 }