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