add thrust as a graphable time series type
[fw/altos] / altosuilib / AltosGraphNew.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_11;
20
21 import java.io.*;
22 import java.util.ArrayList;
23
24 import java.awt.*;
25 import javax.swing.*;
26 import org.altusmetrum.altoslib_11.*;
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 AltosGraphNew extends AltosUIGraphNew {
39
40         static final private Color height_color = new Color(194,31,31);
41         static final private Color gps_height_color = new Color(150,31,31);
42         static final private Color pressure_color = new Color (225,31,31);
43         static final private Color range_color = new Color(100, 31, 31);
44         static final private Color distance_color = new Color(100, 31, 194);
45         static final private Color speed_color = new Color(31,194,31);
46         static final private Color thrust_color = new Color(31,194,31);
47         static final private Color accel_color = new Color(31,31,194);
48         static final private Color voltage_color = new Color(194, 194, 31);
49         static final private Color battery_voltage_color = new Color(194, 194, 31);
50         static final private Color drogue_voltage_color = new Color(150, 150, 31);
51         static final private Color main_voltage_color = new Color(100, 100, 31);
52         static final private Color gps_nsat_color = new Color (194, 31, 194);
53         static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
54         static final private Color gps_nsat_view_color = new Color (150, 31, 150);
55         static final private Color gps_course_color = new Color (100, 31, 112);
56         static final private Color gps_ground_speed_color = new Color (31, 112, 100);
57         static final private Color gps_climb_rate_color = new Color (31, 31, 112);
58         static final private Color gps_pdop_color = new Color(50, 194, 0);
59         static final private Color gps_hdop_color = new Color(50, 0, 194);
60         static final private Color gps_vdop_color = new Color(194, 0, 50);
61         static final private Color temperature_color = new Color (31, 194, 194);
62         static final private Color dbm_color = new Color(31, 100, 100);
63         static final private Color state_color = new Color(0,0,0);
64         static final private Color accel_x_color = new Color(255, 0, 0);
65         static final private Color accel_y_color = new Color(0, 255, 0);
66         static final private Color accel_z_color = new Color(0, 0, 255);
67         static final private Color gyro_x_color = new Color(192, 0, 0);
68         static final private Color gyro_y_color = new Color(0, 192, 0);
69         static final private Color gyro_z_color = new Color(0, 0, 192);
70         static final private Color mag_x_color = new Color(128, 0, 0);
71         static final private Color mag_y_color = new Color(0, 128, 0);
72         static final private Color mag_z_color = new Color(0, 0, 128);
73         static final private Color orient_color = new Color(31, 31, 31);
74
75         static AltosNsat nsat_units = new AltosNsat();
76         static AltosDbm dbm_units = new AltosDbm();
77         static AltosOrient orient_units = new AltosOrient();
78         static AltosMagUnits mag_units = new AltosMagUnits();
79         static AltosDopUnits dop_units = new AltosDopUnits();
80
81         AltosUIFlightSeries flight_series;
82
83         AltosUITimeSeries[] setup(AltosFlightStats stats, AltosRecordSet record_set) {
84
85                 AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
86                 AltosUIAxis     distance_axis, pressure_axis, thrust_axis;
87                 AltosUIAxis     gyro_axis, orient_axis, mag_axis;
88                 AltosUIAxis     course_axis, dop_axis;
89
90                 height_axis = newAxis("Height", AltosConvert.height, height_color);
91                 pressure_axis = newAxis("Pressure", AltosConvert.pressure, pressure_color, 0);
92                 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
93                 thrust_axis = newAxis("Thrust", AltosConvert.force, thrust_color);
94                 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
95                 voltage_axis = newAxis("Voltage", AltosConvert.voltage, voltage_color);
96                 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
97                 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
98                                     AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
99                 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
100                 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
101
102                 gyro_axis = newAxis("Rotation Rate", AltosConvert.rotation_rate, gyro_z_color, 0);
103                 orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0);
104                 mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0);
105                 course_axis = newAxis("Course", orient_units, gps_course_color, 0);
106                 dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0);
107
108                 flight_series = new AltosUIFlightSeries();
109
110                 flight_series.register_extra("default",
111                                              speed_color,
112                                              false,
113                                              speed_axis);
114
115                 flight_series.register_extra(AltosUIFlightSeries.accel_name,
116                                              accel_color,
117                                              true,
118                                              accel_axis);
119
120                 flight_series.register_extra(AltosUIFlightSeries.pressure_name,
121                                              pressure_color,
122                                              true,
123                                              pressure_axis);
124
125                 flight_series.register_extra(AltosUIFlightSeries.thrust_name,
126                                              thrust_color,
127                                              true,
128                                              thrust_axis);
129
130 //              addMarker("State", AltosGraphDataPoint.data_state, state_color);
131
132                 record_set.capture_series(flight_series);
133
134                 return flight_series.series();
135 /*
136                 if (stats.has_flight_data) {
137                         addSeries("Height",
138                                   AltosGraphDataPoint.data_height,
139                                   AltosConvert.height,
140                                   height_color,
141                                   true,
142                                   height_axis);
143                         addSeries("Pressure",
144                                   AltosGraphDataPoint.data_pressure,
145                                   pressure_units,
146                                   pressure_color,
147                                   false,
148                                   pressure_axis);
149                         addSeries("Thrust",
150                                   AltosGraphDataPoint.data_thrust,
151                                   thrust_units,
152                                   thrust_color,
153                                   false,
154                                   thrust_axis);
155                         addSeries("Speed",
156                                   AltosGraphDataPoint.data_speed,
157                                   AltosConvert.speed,
158                                   speed_color,
159                                   true,
160                                   speed_axis);
161                         addSeries("Acceleration",
162                                   AltosGraphDataPoint.data_accel,
163                                   AltosConvert.accel,
164                                   accel_color,
165                                   true,
166                                   accel_axis);
167                 }
168                 if (stats.has_gps) {
169                         boolean enable_gps = false;
170
171                         if (!stats.has_flight_data)
172                                 enable_gps = true;
173
174                         addSeries("Range",
175                                   AltosGraphDataPoint.data_range,
176                                   AltosConvert.distance,
177                                   range_color,
178                                   false,
179                                   distance_axis);
180                         addSeries("Distance",
181                                   AltosGraphDataPoint.data_distance,
182                                   AltosConvert.distance,
183                                   distance_color,
184                                   enable_gps,
185                                   distance_axis);
186                         addSeries("GPS Height",
187                                   AltosGraphDataPoint.data_gps_height,
188                                   AltosConvert.height,
189                                   gps_height_color,
190                                   enable_gps,
191                                   height_axis);
192                         addSeries("GPS Altitude",
193                                   AltosGraphDataPoint.data_gps_altitude,
194                                   AltosConvert.height,
195                                   gps_height_color,
196                                   false,
197                                   height_axis);
198                         addSeries("GPS Satellites in Solution",
199                                   AltosGraphDataPoint.data_gps_nsat_solution,
200                                   nsat_units,
201                                   gps_nsat_solution_color,
202                                   false,
203                                   nsat_axis);
204                         if (stats.has_gps_sats) {
205                                 addSeries("GPS Satellites in View",
206                                           AltosGraphDataPoint.data_gps_nsat_view,
207                                           nsat_units,
208                                           gps_nsat_view_color,
209                                           false,
210                                           nsat_axis);
211                         }
212                         if (stats.has_gps_detail) {
213                                 addSeries("GPS Course",
214                                           AltosGraphDataPoint.data_gps_course,
215                                           orient_units,
216                                           gps_course_color,
217                                           false,
218                                           course_axis);
219                                 addSeries("GPS Ground Speed",
220                                           AltosGraphDataPoint.data_gps_ground_speed,
221                                           AltosConvert.speed,
222                                           gps_ground_speed_color,
223                                           enable_gps,
224                                           speed_axis);
225                                 addSeries("GPS Climb Rate",
226                                           AltosGraphDataPoint.data_gps_climb_rate,
227                                           AltosConvert.speed,
228                                           gps_climb_rate_color,
229                                           enable_gps,
230                                           speed_axis);
231                         }
232                         addSeries("GPS Position DOP",
233                                   AltosGraphDataPoint.data_gps_pdop,
234                                   dop_units,
235                                   gps_pdop_color,
236                                   false,
237                                   dop_axis);
238                         if (stats.has_gps_detail) {
239                                 addSeries("GPS Horizontal DOP",
240                                           AltosGraphDataPoint.data_gps_hdop,
241                                           dop_units,
242                                           gps_hdop_color,
243                                           false,
244                                           dop_axis);
245                                 addSeries("GPS Vertical DOP",
246                                           AltosGraphDataPoint.data_gps_vdop,
247                                           dop_units,
248                                           gps_vdop_color,
249                                           false,
250                                           dop_axis);
251                         }
252                 }
253                 if (stats.has_rssi)
254                         addSeries("Received Signal Strength",
255                                   AltosGraphDataPoint.data_rssi,
256                                   dbm_units,
257                                   dbm_color,
258                                   false,
259                                   dbm_axis);
260
261                 if (stats.has_battery)
262                         addSeries("Battery Voltage",
263                                   AltosGraphDataPoint.data_battery_voltage,
264                                   voltage_units,
265                                   battery_voltage_color,
266                                   false,
267                                   voltage_axis);
268
269                 if (stats.has_flight_adc) {
270                         addSeries("Temperature",
271                                   AltosGraphDataPoint.data_temperature,
272                                   AltosConvert.temperature,
273                                   temperature_color,
274                                   false,
275                                   temperature_axis);
276                         addSeries("Drogue Voltage",
277                                   AltosGraphDataPoint.data_drogue_voltage,
278                                   voltage_units,
279                                   drogue_voltage_color,
280                                   false,
281                                   voltage_axis);
282                         addSeries("Main Voltage",
283                                   AltosGraphDataPoint.data_main_voltage,
284                                   voltage_units,
285                                   main_voltage_color,
286                                   false,
287                                   voltage_axis);
288                 }
289
290                 if (stats.has_imu) {
291                         addSeries("Acceleration Along",
292                                   AltosGraphDataPoint.data_accel_along,
293                                   AltosConvert.accel,
294                                   accel_x_color,
295                                   false,
296                                   accel_axis);
297                         addSeries("Acceleration Across",
298                                   AltosGraphDataPoint.data_accel_across,
299                                   AltosConvert.accel,
300                                   accel_y_color,
301                                   false,
302                                   accel_axis);
303                         addSeries("Acceleration Through",
304                                   AltosGraphDataPoint.data_accel_through,
305                                   AltosConvert.accel,
306                                   accel_z_color,
307                                   false,
308                                   accel_axis);
309                         addSeries("Roll Rate",
310                                   AltosGraphDataPoint.data_gyro_roll,
311                                   gyro_units,
312                                   gyro_x_color,
313                                   false,
314                                   gyro_axis);
315                         addSeries("Pitch Rate",
316                                   AltosGraphDataPoint.data_gyro_pitch,
317                                   gyro_units,
318                                   gyro_y_color,
319                                   false,
320                                   gyro_axis);
321                         addSeries("Yaw Rate",
322                                   AltosGraphDataPoint.data_gyro_yaw,
323                                   gyro_units,
324                                   gyro_z_color,
325                                   false,
326                                   gyro_axis);
327                 }
328                 if (stats.has_mag) {
329                         addSeries("Magnetometer Along",
330                                   AltosGraphDataPoint.data_mag_along,
331                                   mag_units,
332                                   mag_x_color,
333                                   false,
334                                   mag_axis);
335                         addSeries("Magnetometer Across",
336                                   AltosGraphDataPoint.data_mag_across,
337                                   mag_units,
338                                   mag_y_color,
339                                   false,
340                                   mag_axis);
341                         addSeries("Magnetometer Through",
342                                   AltosGraphDataPoint.data_mag_through,
343                                   mag_units,
344                                   mag_z_color,
345                                   false,
346                                   mag_axis);
347                 }
348                 if (stats.has_orient)
349                         addSeries("Tilt Angle",
350                                   AltosGraphDataPoint.data_orient,
351                                   orient_units,
352                                   orient_color,
353                                   false,
354                                   orient_axis);
355                 if (stats.num_ignitor > 0) {
356                         for (int i = 0; i < stats.num_ignitor; i++)
357                                 addSeries(AltosLib.ignitor_name(i),
358                                           AltosGraphDataPoint.data_ignitor_0 + i,
359                                           voltage_units,
360                                           main_voltage_color,
361                                           false,
362                                           voltage_axis);
363                         for (int i = 0; i < stats.num_ignitor; i++)
364                                 addMarker(AltosLib.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);
365                 }
366 */
367         }
368
369         public AltosGraphNew(AltosUIEnable enable, AltosFlightStats stats, AltosRecordSet record_set) {
370                 super(enable, "Flight");
371
372                 set_series(setup(stats, record_set));
373         }
374 }