2 * Copyright © 2013 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; either version 2 of the License, or
7 * (at your option) any later version.
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.
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.
19 package org.altusmetrum.altosuilib_12;
22 import java.util.ArrayList;
26 import org.altusmetrum.altoslib_12.*;
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.*;
38 public class AltosGraph extends AltosUIGraph {
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
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();
49 static final private AltosUILineStyle gps_height_color = new AltosUILineStyle();
50 static final private AltosUILineStyle altitude_color = new AltosUILineStyle();
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);
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();
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();
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 ();
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();
88 static AltosUnits dop_units = null;
89 static AltosUnits tick_units = null;
91 AltosUIFlightSeries flight_series;
93 AltosUITimeSeries[] setup(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
94 AltosCalData cal_data = flight_series.cal_data();
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;
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));
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);
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);
122 flight_series.register_axis("default",
127 flight_series.register_marker(AltosUIFlightSeries.state_name,
133 flight_series.register_marker(AltosUIFlightSeries.pyro_fired_name,
134 igniter_marker_color,
139 flight_series.register_axis(AltosUIFlightSeries.tick_name,
144 flight_series.register_axis(AltosUIFlightSeries.accel_name,
149 flight_series.register_axis(AltosUIFlightSeries.vert_accel_name,
154 flight_series.register_axis(AltosUIFlightSeries.kalman_accel_name,
159 flight_series.register_axis(AltosUIFlightSeries.rssi_name,
164 flight_series.register_axis(AltosUIFlightSeries.speed_name,
169 flight_series.register_axis(AltosUIFlightSeries.kalman_speed_name,
174 flight_series.register_axis(AltosUIFlightSeries.pressure_name,
179 flight_series.register_axis(AltosUIFlightSeries.height_name,
184 flight_series.register_axis(AltosUIFlightSeries.altitude_name,
189 flight_series.register_axis(AltosUIFlightSeries.kalman_height_name,
195 flight_series.register_axis(AltosUIFlightSeries.temperature_name,
200 flight_series.register_axis(AltosUIFlightSeries.battery_voltage_name,
201 battery_voltage_color,
205 flight_series.register_axis(AltosUIFlightSeries.pyro_voltage_name,
210 flight_series.register_axis(AltosUIFlightSeries.apogee_voltage_name,
211 drogue_voltage_color,
215 flight_series.register_axis(AltosUIFlightSeries.main_voltage_name,
220 flight_series.register_axis(AltosUIFlightSeries.sats_in_view_name,
225 flight_series.register_axis(AltosUIFlightSeries.sats_in_soln_name,
226 gps_nsat_solution_color,
230 flight_series.register_axis(AltosUIFlightSeries.gps_pdop_name,
235 flight_series.register_axis(AltosUIFlightSeries.gps_hdop_name,
240 flight_series.register_axis(AltosUIFlightSeries.gps_vdop_name,
245 flight_series.register_axis(AltosUIFlightSeries.gps_altitude_name,
250 flight_series.register_axis(AltosUIFlightSeries.gps_height_name,
255 flight_series.register_axis(AltosUIFlightSeries.gps_ground_speed_name,
256 gps_ground_speed_color,
260 flight_series.register_axis(AltosUIFlightSeries.gps_ascent_rate_name,
261 gps_climb_rate_color,
265 flight_series.register_axis(AltosUIFlightSeries.gps_course_name,
270 flight_series.register_axis(AltosUIFlightSeries.gps_speed_name,
275 flight_series.register_axis(AltosUIFlightSeries.accel_along_name,
280 flight_series.register_axis(AltosUIFlightSeries.accel_across_name,
285 flight_series.register_axis(AltosUIFlightSeries.accel_through_name,
290 flight_series.register_axis(AltosUIFlightSeries.gyro_roll_name,
295 flight_series.register_axis(AltosUIFlightSeries.gyro_pitch_name,
300 flight_series.register_axis(AltosUIFlightSeries.gyro_yaw_name,
305 flight_series.register_axis(AltosUIFlightSeries.mag_along_name,
310 flight_series.register_axis(AltosUIFlightSeries.mag_across_name,
315 flight_series.register_axis(AltosUIFlightSeries.mag_through_name,
320 flight_series.register_axis(AltosUIFlightSeries.orient_name,
325 flight_series.register_axis(AltosUIFlightSeries.thrust_name,
330 for (int channel = 0; channel < 8; channel++) {
331 flight_series.register_axis(flight_series.igniter_voltage_name(channel),
332 new AltosUILineStyle(),
337 flight_series.check_axes();
339 return flight_series.series(cal_data);
342 public void set_data(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
343 set_series(setup(stats, flight_series));
346 public AltosGraph(AltosUIEnable enable) {
347 super(enable, "Flight");
350 public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosUIFlightSeries flight_series) {
352 this.flight_series = flight_series;
353 set_series(setup(stats, flight_series));