altos: get ao_max6691 driver working
[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_13;
20
21 import java.io.*;
22 import java.util.ArrayList;
23
24 import java.awt.*;
25 import javax.swing.*;
26 import org.altusmetrum.altoslib_13.*;
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
49         static final private AltosUILineStyle gps_height_color = new AltosUILineStyle();
50         static final private AltosUILineStyle altitude_color = new AltosUILineStyle();
51
52         static final private AltosUILineStyle battery_voltage_color = new AltosUILineStyle();
53         static final private AltosUILineStyle pyro_voltage_color = new AltosUILineStyle();
54         static final private AltosUILineStyle drogue_voltage_color = new AltosUILineStyle();
55         static final private AltosUILineStyle main_voltage_color = new AltosUILineStyle();
56         static final private AltosUILineStyle igniter_marker_color = new AltosUILineStyle(1);
57
58         static final private AltosUILineStyle kalman_height_color = new AltosUILineStyle();
59         static final private AltosUILineStyle kalman_speed_color = new AltosUILineStyle();
60         static final private AltosUILineStyle kalman_accel_color = new AltosUILineStyle();
61
62         static final private AltosUILineStyle gps_nsat_color = new AltosUILineStyle ();
63         static final private AltosUILineStyle gps_nsat_solution_color = new AltosUILineStyle ();
64         static final private AltosUILineStyle gps_nsat_view_color = new AltosUILineStyle ();
65         static final private AltosUILineStyle gps_course_color = new AltosUILineStyle ();
66         static final private AltosUILineStyle gps_ground_speed_color = new AltosUILineStyle ();
67         static final private AltosUILineStyle gps_speed_color = new AltosUILineStyle ();
68         static final private AltosUILineStyle gps_climb_rate_color = new AltosUILineStyle ();
69         static final private AltosUILineStyle gps_pdop_color = new AltosUILineStyle();
70         static final private AltosUILineStyle gps_hdop_color = new AltosUILineStyle();
71         static final private AltosUILineStyle gps_vdop_color = new AltosUILineStyle();
72
73         static final private AltosUILineStyle temperature_color = new AltosUILineStyle ();
74         static final private AltosUILineStyle dbm_color = new AltosUILineStyle();
75         static final private AltosUILineStyle pressure_color = new AltosUILineStyle ();
76
77         static final private AltosUILineStyle state_color = new AltosUILineStyle(0);
78         static final private AltosUILineStyle accel_along_color = new AltosUILineStyle();
79         static final private AltosUILineStyle accel_across_color = new AltosUILineStyle();
80         static final private AltosUILineStyle accel_through_color = new AltosUILineStyle();
81         static final private AltosUILineStyle gyro_roll_color = new AltosUILineStyle();
82         static final private AltosUILineStyle gyro_pitch_color = new AltosUILineStyle();
83         static final private AltosUILineStyle gyro_yaw_color = new AltosUILineStyle();
84         static final private AltosUILineStyle mag_along_color = new AltosUILineStyle();
85         static final private AltosUILineStyle mag_across_color = new AltosUILineStyle();
86         static final private AltosUILineStyle mag_through_color = new AltosUILineStyle();
87
88         static AltosUnits dop_units = null;
89         static AltosUnits tick_units = null;
90
91         AltosUIFlightSeries flight_series;
92
93         AltosUITimeSeries[] setup(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
94                 AltosCalData    cal_data = flight_series.cal_data();
95
96                 AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
97                 AltosUIAxis     pressure_axis, thrust_axis;
98                 AltosUIAxis     gyro_axis, orient_axis, mag_axis;
99                 AltosUIAxis     course_axis, dop_axis, tick_axis;
100
101                 if (stats != null && stats.serial != AltosLib.MISSING && stats.product != null && stats.flight != AltosLib.MISSING)
102                         setName(String.format("%s %d flight %d\n", stats.product, stats.serial, stats.flight));
103
104                 height_axis = newAxis("Height", AltosConvert.height, height_color);
105                 pressure_axis = newAxis("Pressure", AltosConvert.pressure, pressure_color, 0);
106                 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
107                 thrust_axis = newAxis("Thrust", AltosConvert.force, accel_color);
108                 tick_axis = newAxis("Tick", tick_units, accel_color, 0);
109                 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
110                 voltage_axis = newAxis("Voltage", AltosConvert.voltage, battery_voltage_color);
111                 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
112                 nsat_axis = newAxis("Satellites", null, gps_nsat_color,
113                                     AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
114                 dbm_axis = newAxis("Signal Strength", null, dbm_color, 0);
115
116                 gyro_axis = newAxis("Rotation Rate", AltosConvert.rotation_rate, gyro_roll_color, 0);
117                 orient_axis = newAxis("Tilt Angle", AltosConvert.orient, orient_color, 0);
118                 mag_axis = newAxis("Magnetic Field", AltosConvert.magnetic_field, mag_along_color, 0);
119                 course_axis = newAxis("Course", AltosConvert.orient, gps_course_color, 0);
120                 dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0);
121
122                 flight_series.register_axis("default",
123                                             speed_color,
124                                             false,
125                                             speed_axis);
126
127                 flight_series.register_marker(AltosUIFlightSeries.state_name,
128                                               state_color,
129                                               true,
130                                               plot,
131                                               true);
132
133                 flight_series.register_marker(AltosUIFlightSeries.pyro_fired_name,
134                                               igniter_marker_color,
135                                               true,
136                                               plot,
137                                               false);
138
139                 flight_series.register_axis(AltosUIFlightSeries.tick_name,
140                                             accel_color,
141                                             false,
142                                             tick_axis);
143
144                 flight_series.register_axis(AltosUIFlightSeries.accel_name,
145                                             accel_color,
146                                             true,
147                                             accel_axis);
148
149                 flight_series.register_axis(AltosUIFlightSeries.vert_accel_name,
150                                             vert_accel_color,
151                                             true,
152                                             accel_axis);
153
154                 flight_series.register_axis(AltosUIFlightSeries.kalman_accel_name,
155                                             kalman_accel_color,
156                                             false,
157                                             accel_axis);
158
159                 flight_series.register_axis(AltosUIFlightSeries.rssi_name,
160                                             dbm_color,
161                                             false,
162                                             dbm_axis);
163
164                 flight_series.register_axis(AltosUIFlightSeries.speed_name,
165                                             speed_color,
166                                             true,
167                                             speed_axis);
168
169                 flight_series.register_axis(AltosUIFlightSeries.kalman_speed_name,
170                                             kalman_speed_color,
171                                             true,
172                                             speed_axis);
173
174                 flight_series.register_axis(AltosUIFlightSeries.pressure_name,
175                                             pressure_color,
176                                             false,
177                                             pressure_axis);
178
179                 flight_series.register_axis(AltosUIFlightSeries.height_name,
180                                             height_color,
181                                             true,
182                                             height_axis);
183
184                 flight_series.register_axis(AltosUIFlightSeries.altitude_name,
185                                             altitude_color,
186                                             false,
187                                             height_axis);
188
189                 flight_series.register_axis(AltosUIFlightSeries.kalman_height_name,
190                                             kalman_height_color,
191                                             false,
192                                             height_axis);
193
194
195                 flight_series.register_axis(AltosUIFlightSeries.temperature_name,
196                                             temperature_color,
197                                             false,
198                                             temperature_axis);
199
200                 flight_series.register_axis(AltosUIFlightSeries.battery_voltage_name,
201                                             battery_voltage_color,
202                                             false,
203                                             voltage_axis);
204
205                 flight_series.register_axis(AltosUIFlightSeries.pyro_voltage_name,
206                                             pyro_voltage_color,
207                                             false,
208                                             voltage_axis);
209
210                 flight_series.register_axis(AltosUIFlightSeries.apogee_voltage_name,
211                                             drogue_voltage_color,
212                                             false,
213                                             voltage_axis);
214
215                 flight_series.register_axis(AltosUIFlightSeries.main_voltage_name,
216                                             main_voltage_color,
217                                             false,
218                                             voltage_axis);
219
220                 flight_series.register_axis(AltosUIFlightSeries.sats_in_view_name,
221                                             gps_nsat_view_color,
222                                             false,
223                                             nsat_axis);
224
225                 flight_series.register_axis(AltosUIFlightSeries.sats_in_soln_name,
226                                             gps_nsat_solution_color,
227                                             false,
228                                             nsat_axis);
229
230                 flight_series.register_axis(AltosUIFlightSeries.gps_pdop_name,
231                                             gps_pdop_color,
232                                             false,
233                                             dop_axis);
234
235                 flight_series.register_axis(AltosUIFlightSeries.gps_hdop_name,
236                                             gps_hdop_color,
237                                             false,
238                                             dop_axis);
239
240                 flight_series.register_axis(AltosUIFlightSeries.gps_vdop_name,
241                                             gps_vdop_color,
242                                             false,
243                                             dop_axis);
244
245                 flight_series.register_axis(AltosUIFlightSeries.gps_altitude_name,
246                                             gps_height_color,
247                                             false,
248                                             height_axis);
249
250                 flight_series.register_axis(AltosUIFlightSeries.gps_height_name,
251                                             gps_height_color,
252                                             false,
253                                             height_axis);
254
255                 flight_series.register_axis(AltosUIFlightSeries.gps_ground_speed_name,
256                                             gps_ground_speed_color,
257                                             false,
258                                             speed_axis);
259
260                 flight_series.register_axis(AltosUIFlightSeries.gps_ascent_rate_name,
261                                             gps_climb_rate_color,
262                                             false,
263                                             speed_axis);
264
265                 flight_series.register_axis(AltosUIFlightSeries.gps_course_name,
266                                             gps_course_color,
267                                             false,
268                                             course_axis);
269
270                 flight_series.register_axis(AltosUIFlightSeries.gps_speed_name,
271                                             gps_speed_color,
272                                             false,
273                                             speed_axis);
274
275                 flight_series.register_axis(AltosUIFlightSeries.accel_along_name,
276                                             accel_along_color,
277                                             false,
278                                             accel_axis);
279
280                 flight_series.register_axis(AltosUIFlightSeries.accel_across_name,
281                                             accel_across_color,
282                                             false,
283                                             accel_axis);
284
285                 flight_series.register_axis(AltosUIFlightSeries.accel_through_name,
286                                             accel_through_color,
287                                             false,
288                                             accel_axis);
289
290                 flight_series.register_axis(AltosUIFlightSeries.gyro_roll_name,
291                                             gyro_roll_color,
292                                             false,
293                                             gyro_axis);
294
295                 flight_series.register_axis(AltosUIFlightSeries.gyro_pitch_name,
296                                             gyro_pitch_color,
297                                             false,
298                                             gyro_axis);
299
300                 flight_series.register_axis(AltosUIFlightSeries.gyro_yaw_name,
301                                             gyro_yaw_color,
302                                             false,
303                                             gyro_axis);
304
305                 flight_series.register_axis(AltosUIFlightSeries.mag_along_name,
306                                             mag_along_color,
307                                             false,
308                                             mag_axis);
309
310                 flight_series.register_axis(AltosUIFlightSeries.mag_across_name,
311                                             mag_across_color,
312                                             false,
313                                             mag_axis);
314
315                 flight_series.register_axis(AltosUIFlightSeries.mag_through_name,
316                                             mag_through_color,
317                                             false,
318                                             mag_axis);
319
320                 flight_series.register_axis(AltosUIFlightSeries.orient_name,
321                                             orient_color,
322                                             false,
323                                             orient_axis);
324
325                 flight_series.register_axis(AltosUIFlightSeries.thrust_name,
326                                             accel_color,
327                                             true,
328                                             thrust_axis);
329
330                 for (int channel = 0; channel < 8; channel++) {
331                         flight_series.register_axis(flight_series.igniter_voltage_name(channel),
332                                                     new AltosUILineStyle(),
333                                                     false,
334                                                     voltage_axis);
335                 }
336
337                 flight_series.check_axes();
338
339                 return flight_series.series(cal_data);
340         }
341
342         public void set_data(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
343                 set_series(setup(stats, flight_series));
344         }
345
346         public AltosGraph(AltosUIEnable enable) {
347                 super(enable, "Flight");
348         }
349
350         public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosUIFlightSeries flight_series) {
351                 this(enable);
352                 this.flight_series = flight_series;
353                 set_series(setup(stats, flight_series));
354         }
355 }