summaryrefslogtreecommitdiff
path: root/altosuilib/AltosGraph.java
blob: a758bcdecb284f70e37f6a647acf1617d3793ccd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
 * Copyright © 2013 Keith Packard <keithp@keithp.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

package org.altusmetrum.altosuilib_12;

import java.io.*;
import java.util.ArrayList;

import java.awt.*;
import javax.swing.*;
import org.altusmetrum.altoslib_12.*;

import org.jfree.ui.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.renderer.*;
import org.jfree.chart.renderer.xy.*;
import org.jfree.chart.labels.*;
import org.jfree.data.xy.*;
import org.jfree.data.*;

public class AltosGraph extends AltosUIGraph {

	/* These are in 'priority' order so that earlier ones get simpler line styles,
	 * then they are grouped so that adjacent ones get sequential colors
	 */
	static final private AltosUILineStyle height_color = new AltosUILineStyle();
	static final private AltosUILineStyle speed_color = new AltosUILineStyle();
	static final private AltosUILineStyle accel_color = new AltosUILineStyle();
	static final private AltosUILineStyle vert_accel_color = new AltosUILineStyle();
	static final private AltosUILineStyle orient_color = new AltosUILineStyle();

	static final private AltosUILineStyle gps_height_color = new AltosUILineStyle();
	static final private AltosUILineStyle altitude_color = new AltosUILineStyle();

	static final private AltosUILineStyle battery_voltage_color = new AltosUILineStyle();
	static final private AltosUILineStyle pyro_voltage_color = new AltosUILineStyle();
	static final private AltosUILineStyle drogue_voltage_color = new AltosUILineStyle();
	static final private AltosUILineStyle main_voltage_color = new AltosUILineStyle();
	static final private AltosUILineStyle igniter_marker_color = new AltosUILineStyle(1);

	static final private AltosUILineStyle kalman_height_color = new AltosUILineStyle();
	static final private AltosUILineStyle kalman_speed_color = new AltosUILineStyle();
	static final private AltosUILineStyle kalman_accel_color = new AltosUILineStyle();

	static final private AltosUILineStyle gps_nsat_color = new AltosUILineStyle ();
	static final private AltosUILineStyle gps_nsat_solution_color = new AltosUILineStyle ();
	static final private AltosUILineStyle gps_nsat_view_color = new AltosUILineStyle ();
	static final private AltosUILineStyle gps_course_color = new AltosUILineStyle ();
	static final private AltosUILineStyle gps_ground_speed_color = new AltosUILineStyle ();
	static final private AltosUILineStyle gps_speed_color = new AltosUILineStyle ();
	static final private AltosUILineStyle gps_climb_rate_color = new AltosUILineStyle ();
	static final private AltosUILineStyle gps_pdop_color = new AltosUILineStyle();
	static final private AltosUILineStyle gps_hdop_color = new AltosUILineStyle();
	static final private AltosUILineStyle gps_vdop_color = new AltosUILineStyle();

	static final private AltosUILineStyle temperature_color = new AltosUILineStyle ();
	static final private AltosUILineStyle dbm_color = new AltosUILineStyle();
	static final private AltosUILineStyle pressure_color = new AltosUILineStyle ();

	static final private AltosUILineStyle state_color = new AltosUILineStyle(0);
	static final private AltosUILineStyle accel_along_color = new AltosUILineStyle();
	static final private AltosUILineStyle accel_across_color = new AltosUILineStyle();
	static final private AltosUILineStyle accel_through_color = new AltosUILineStyle();
	static final private AltosUILineStyle gyro_roll_color = new AltosUILineStyle();
	static final private AltosUILineStyle gyro_pitch_color = new AltosUILineStyle();
	static final private AltosUILineStyle gyro_yaw_color = new AltosUILineStyle();
	static final private AltosUILineStyle mag_along_color = new AltosUILineStyle();
	static final private AltosUILineStyle mag_across_color = new AltosUILineStyle();
	static final private AltosUILineStyle mag_through_color = new AltosUILineStyle();

	static AltosUnits dop_units = null;
	static AltosUnits tick_units = null;

	AltosUIFlightSeries flight_series;

	AltosUITimeSeries[] setup(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
		AltosCalData	cal_data = flight_series.cal_data();

		AltosUIAxis	height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
		AltosUIAxis	pressure_axis, thrust_axis;
		AltosUIAxis	gyro_axis, orient_axis, mag_axis;
		AltosUIAxis	course_axis, dop_axis, tick_axis;

		if (stats != null && stats.serial != AltosLib.MISSING && stats.product != null && stats.flight != AltosLib.MISSING)
			setName(String.format("%s %d flight %d\n", stats.product, stats.serial, stats.flight));

		height_axis = newAxis("Height", AltosConvert.height, height_color);
		pressure_axis = newAxis("Pressure", AltosConvert.pressure, pressure_color, 0);
		speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
		thrust_axis = newAxis("Thrust", AltosConvert.force, accel_color);
		tick_axis = newAxis("Tick", tick_units, accel_color, 0);
		accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
		voltage_axis = newAxis("Voltage", AltosConvert.voltage, battery_voltage_color);
		temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
		nsat_axis = newAxis("Satellites", null, gps_nsat_color,
				    AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
		dbm_axis = newAxis("Signal Strength", null, dbm_color, 0);

		gyro_axis = newAxis("Rotation Rate", AltosConvert.rotation_rate, gyro_roll_color, 0);
		orient_axis = newAxis("Tilt Angle", AltosConvert.orient, orient_color, 0);
		mag_axis = newAxis("Magnetic Field", AltosConvert.magnetic_field, mag_along_color, 0);
		course_axis = newAxis("Course", AltosConvert.orient, gps_course_color, 0);
		dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0);

		flight_series.register_axis("default",
					    speed_color,
					    false,
					    speed_axis);

		flight_series.register_marker(AltosUIFlightSeries.state_name,
					      state_color,
					      true,
					      plot,
					      true);

		flight_series.register_marker(AltosUIFlightSeries.pyro_fired_name,
					      igniter_marker_color,
					      true,
					      plot,
					      false);

		flight_series.register_axis(AltosUIFlightSeries.tick_name,
					    accel_color,
					    false,
					    tick_axis);

		flight_series.register_axis(AltosUIFlightSeries.accel_name,
					    accel_color,
					    true,
					    accel_axis);

		flight_series.register_axis(AltosUIFlightSeries.vert_accel_name,
					    vert_accel_color,
					    true,
					    accel_axis);

		flight_series.register_axis(AltosUIFlightSeries.kalman_accel_name,
					    kalman_accel_color,
					    false,
					    accel_axis);

		flight_series.register_axis(AltosUIFlightSeries.rssi_name,
					    dbm_color,
					    false,
					    dbm_axis);

		flight_series.register_axis(AltosUIFlightSeries.speed_name,
					    speed_color,
					    true,
					    speed_axis);

		flight_series.register_axis(AltosUIFlightSeries.kalman_speed_name,
					    kalman_speed_color,
					    true,
					    speed_axis);

		flight_series.register_axis(AltosUIFlightSeries.pressure_name,
					    pressure_color,
					    false,
					    pressure_axis);

		flight_series.register_axis(AltosUIFlightSeries.height_name,
					    height_color,
					    true,
					    height_axis);

		flight_series.register_axis(AltosUIFlightSeries.altitude_name,
					    altitude_color,
					    false,
					    height_axis);

		flight_series.register_axis(AltosUIFlightSeries.kalman_height_name,
					    kalman_height_color,
					    false,
					    height_axis);


		flight_series.register_axis(AltosUIFlightSeries.temperature_name,
					    temperature_color,
					    false,
					    temperature_axis);

		flight_series.register_axis(AltosUIFlightSeries.battery_voltage_name,
					    battery_voltage_color,
					    false,
					    voltage_axis);

		flight_series.register_axis(AltosUIFlightSeries.pyro_voltage_name,
					    pyro_voltage_color,
					    false,
					    voltage_axis);

		flight_series.register_axis(AltosUIFlightSeries.apogee_voltage_name,
					    drogue_voltage_color,
					    false,
					    voltage_axis);

		flight_series.register_axis(AltosUIFlightSeries.main_voltage_name,
					    main_voltage_color,
					    false,
					    voltage_axis);

		flight_series.register_axis(AltosUIFlightSeries.sats_in_view_name,
					    gps_nsat_view_color,
					    false,
					    nsat_axis);

		flight_series.register_axis(AltosUIFlightSeries.sats_in_soln_name,
					    gps_nsat_solution_color,
					    false,
					    nsat_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_pdop_name,
					    gps_pdop_color,
					    false,
					    dop_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_hdop_name,
					    gps_hdop_color,
					    false,
					    dop_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_vdop_name,
					    gps_vdop_color,
					    false,
					    dop_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_altitude_name,
					    gps_height_color,
					    false,
					    height_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_height_name,
					    gps_height_color,
					    false,
					    height_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_ground_speed_name,
					    gps_ground_speed_color,
					    false,
					    speed_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_ascent_rate_name,
					    gps_climb_rate_color,
					    false,
					    speed_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_course_name,
					    gps_course_color,
					    false,
					    course_axis);

		flight_series.register_axis(AltosUIFlightSeries.gps_speed_name,
					    gps_speed_color,
					    false,
					    speed_axis);

		flight_series.register_axis(AltosUIFlightSeries.accel_along_name,
					    accel_along_color,
					    false,
					    accel_axis);

		flight_series.register_axis(AltosUIFlightSeries.accel_across_name,
					    accel_across_color,
					    false,
					    accel_axis);

		flight_series.register_axis(AltosUIFlightSeries.accel_through_name,
					    accel_through_color,
					    false,
					    accel_axis);

		flight_series.register_axis(AltosUIFlightSeries.gyro_roll_name,
					    gyro_roll_color,
					    false,
					    gyro_axis);

		flight_series.register_axis(AltosUIFlightSeries.gyro_pitch_name,
					    gyro_pitch_color,
					    false,
					    gyro_axis);

		flight_series.register_axis(AltosUIFlightSeries.gyro_yaw_name,
					    gyro_yaw_color,
					    false,
					    gyro_axis);

		flight_series.register_axis(AltosUIFlightSeries.mag_along_name,
					    mag_along_color,
					    false,
					    mag_axis);

		flight_series.register_axis(AltosUIFlightSeries.mag_across_name,
					    mag_across_color,
					    false,
					    mag_axis);

		flight_series.register_axis(AltosUIFlightSeries.mag_through_name,
					    mag_through_color,
					    false,
					    mag_axis);

		flight_series.register_axis(AltosUIFlightSeries.orient_name,
					    orient_color,
					    false,
					    orient_axis);

		flight_series.register_axis(AltosUIFlightSeries.thrust_name,
					    accel_color,
					    true,
					    thrust_axis);

		for (int channel = 0; channel < 8; channel++) {
			flight_series.register_axis(flight_series.igniter_voltage_name(channel),
						    new AltosUILineStyle(),
						    false,
						    voltage_axis);
		}

		flight_series.check_axes();

		return flight_series.series(cal_data);
	}

	public void set_data(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
		set_series(setup(stats, flight_series));
	}

	public AltosGraph(AltosUIEnable enable) {
		super(enable, "Flight");
	}

	public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosUIFlightSeries flight_series) {
		this(enable);
		this.flight_series = flight_series;
		set_series(setup(stats, flight_series));
	}
}