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_14;
22 import java.util.ArrayList;
26 import org.altusmetrum.altoslib_14.*;
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();
48 static final private AltosUILineStyle azimuth_color = new AltosUILineStyle();
49 static final private AltosUILineStyle compass_color = new AltosUILineStyle();
51 static final private AltosUILineStyle gps_height_color = new AltosUILineStyle();
52 static final private AltosUILineStyle altitude_color = new AltosUILineStyle();
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);
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();
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();
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 ();
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();
91 static final private AltosUILineStyle motor_pressure_color = new AltosUILineStyle();
93 static AltosUnits dop_units = null;
94 static AltosUnits tick_units = null;
96 AltosUIFlightSeries flight_series;
98 boolean enable_axis(int product_id, String label) {
100 case AltosLib.product_easymotor:
101 return(label.equals(AltosUIFlightSeries.motor_pressure_name) ||
102 label.equals(AltosUIFlightSeries.accel_name));
108 AltosUITimeSeries[] setup(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
109 AltosCalData cal_data = flight_series.cal_data();
110 int product_id = cal_data.device_type;
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;
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));
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);
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);
139 motor_pressure_axis = newAxis("Motor Pressure", AltosConvert.pressure, motor_pressure_color, 0);
141 flight_series.register_axis("default",
146 flight_series.register_marker(AltosUIFlightSeries.state_name,
148 enable_axis(product_id, AltosUIFlightSeries.state_name),
152 flight_series.register_marker(AltosUIFlightSeries.pyro_fired_name,
153 igniter_marker_color,
158 flight_series.register_axis(AltosUIFlightSeries.tick_name,
163 flight_series.register_axis(AltosUIFlightSeries.accel_name,
165 enable_axis(product_id, AltosUIFlightSeries.accel_name),
168 flight_series.register_axis(AltosUIFlightSeries.vert_accel_name,
170 enable_axis(product_id, AltosUIFlightSeries.vert_accel_name),
173 flight_series.register_axis(AltosUIFlightSeries.kalman_accel_name,
178 flight_series.register_axis(AltosUIFlightSeries.rssi_name,
183 flight_series.register_axis(AltosUIFlightSeries.speed_name,
185 enable_axis(product_id, AltosUIFlightSeries.speed_name),
188 flight_series.register_axis(AltosUIFlightSeries.kalman_speed_name,
190 enable_axis(product_id, AltosUIFlightSeries.kalman_speed_name),
193 flight_series.register_axis(AltosUIFlightSeries.pressure_name,
198 flight_series.register_axis(AltosUIFlightSeries.height_name,
200 enable_axis(product_id, AltosUIFlightSeries.height_name),
203 flight_series.register_axis(AltosUIFlightSeries.altitude_name,
208 flight_series.register_axis(AltosUIFlightSeries.kalman_height_name,
214 flight_series.register_axis(AltosUIFlightSeries.temperature_name,
219 flight_series.register_axis(AltosUIFlightSeries.battery_voltage_name,
220 battery_voltage_color,
224 flight_series.register_axis(AltosUIFlightSeries.pyro_voltage_name,
229 flight_series.register_axis(AltosUIFlightSeries.apogee_voltage_name,
230 drogue_voltage_color,
234 flight_series.register_axis(AltosUIFlightSeries.main_voltage_name,
239 flight_series.register_axis(AltosUIFlightSeries.sats_in_view_name,
244 flight_series.register_axis(AltosUIFlightSeries.sats_in_soln_name,
245 gps_nsat_solution_color,
249 flight_series.register_axis(AltosUIFlightSeries.gps_pdop_name,
254 flight_series.register_axis(AltosUIFlightSeries.gps_hdop_name,
259 flight_series.register_axis(AltosUIFlightSeries.gps_vdop_name,
264 flight_series.register_axis(AltosUIFlightSeries.gps_altitude_name,
269 flight_series.register_axis(AltosUIFlightSeries.gps_height_name,
274 flight_series.register_axis(AltosUIFlightSeries.gps_ground_speed_name,
275 gps_ground_speed_color,
279 flight_series.register_axis(AltosUIFlightSeries.gps_ascent_rate_name,
280 gps_climb_rate_color,
284 flight_series.register_axis(AltosUIFlightSeries.gps_course_name,
289 flight_series.register_axis(AltosUIFlightSeries.gps_speed_name,
294 flight_series.register_axis(AltosUIFlightSeries.accel_along_name,
299 flight_series.register_axis(AltosUIFlightSeries.accel_across_name,
304 flight_series.register_axis(AltosUIFlightSeries.accel_through_name,
309 flight_series.register_axis(AltosUIFlightSeries.gyro_roll_name,
314 flight_series.register_axis(AltosUIFlightSeries.gyro_pitch_name,
319 flight_series.register_axis(AltosUIFlightSeries.gyro_yaw_name,
324 flight_series.register_axis(AltosUIFlightSeries.mag_along_name,
329 flight_series.register_axis(AltosUIFlightSeries.mag_across_name,
334 flight_series.register_axis(AltosUIFlightSeries.mag_through_name,
339 flight_series.register_axis(AltosUIFlightSeries.mag_total_name,
344 flight_series.register_axis(AltosUIFlightSeries.orient_name,
349 flight_series.register_axis(AltosUIFlightSeries.azimuth_name,
354 flight_series.register_axis(AltosUIFlightSeries.compass_name,
359 flight_series.register_axis(AltosUIFlightSeries.thrust_name,
361 enable_axis(product_id, AltosUIFlightSeries.thrust_name),
364 for (int channel = 0; channel < 8; channel++) {
365 flight_series.register_axis(flight_series.igniter_voltage_name(channel),
366 new AltosUILineStyle(),
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);
376 flight_series.check_axes();
378 return flight_series.series(cal_data);
381 public void set_data(AltosFlightStats stats, AltosUIFlightSeries flight_series) {
382 set_series(setup(stats, flight_series));
385 public AltosGraph(AltosUIEnable enable) {
386 super(enable, "Flight");
389 public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosUIFlightSeries flight_series) {
391 this.flight_series = flight_series;
392 set_series(setup(stats, flight_series));