dc5b7e47d5cb6457c0bfb4897929baeb62f32361
[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 kalman_height_color = new Color(255,0,0);
42         static final private Color gps_height_color = new Color(150,31,31);
43         static final private Color pressure_color = new Color (225,31,31);
44         static final private Color range_color = new Color(100, 31, 31);
45         static final private Color distance_color = new Color(100, 31, 194);
46         static final private Color speed_color = new Color(31,194,31);
47         static final private Color kalman_speed_color = new Color(0,255,0);
48         static final private Color thrust_color = new Color(31,194,31);
49         static final private Color accel_color = new Color(31,31,194);
50         static final private Color kalman_accel_color = new Color(0,0,255);
51         static final private Color voltage_color = new Color(194, 194, 31);
52         static final private Color battery_voltage_color = new Color(194, 194, 31);
53         static final private Color drogue_voltage_color = new Color(150, 150, 31);
54         static final private Color main_voltage_color = new Color(100, 100, 31);
55         static final private Color gps_nsat_color = new Color (194, 31, 194);
56         static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
57         static final private Color gps_nsat_view_color = new Color (150, 31, 150);
58         static final private Color gps_course_color = new Color (100, 31, 112);
59         static final private Color gps_ground_speed_color = new Color (31, 112, 100);
60         static final private Color gps_speed_color = new Color (31, 112, 100);
61         static final private Color gps_climb_rate_color = new Color (31, 31, 112);
62         static final private Color gps_pdop_color = new Color(50, 194, 0);
63         static final private Color gps_hdop_color = new Color(50, 0, 194);
64         static final private Color gps_vdop_color = new Color(194, 0, 50);
65         static final private Color temperature_color = new Color (31, 194, 194);
66         static final private Color dbm_color = new Color(31, 100, 100);
67         static final private Color state_color = new Color(0,0,0);
68         static final private Color accel_x_color = new Color(255, 0, 0);
69         static final private Color accel_y_color = new Color(0, 255, 0);
70         static final private Color accel_z_color = new Color(0, 0, 255);
71         static final private Color gyro_x_color = new Color(192, 0, 0);
72         static final private Color gyro_y_color = new Color(0, 192, 0);
73         static final private Color gyro_z_color = new Color(0, 0, 192);
74         static final private Color mag_x_color = new Color(128, 0, 0);
75         static final private Color mag_y_color = new Color(0, 128, 0);
76         static final private Color mag_z_color = new Color(0, 0, 128);
77         static final private Color orient_color = new Color(31, 31, 31);
78
79 //      static AltosNsat nsat_units = new AltosNsat();
80         static AltosUnits nsat_units = null;
81 //      static AltosDbm dbm_units = new AltosDbm();
82         static AltosUnits dbm_units = null;
83         static AltosOrient orient_units = new AltosOrient();
84 //      static AltosMagUnits mag_units = new AltosMagUnits();
85         static AltosUnits mag_units = null;
86 //      static AltosDopUnits dop_units = new AltosDopUnits();
87         static AltosUnits dop_units = null;
88
89         AltosUIFlightSeries flight_series;
90
91         AltosUITimeSeries[] setup(AltosFlightStats stats, AltosUIFlightSeries flight_series, AltosCalData cal_data) {
92
93                 AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
94                 AltosUIAxis     distance_axis, pressure_axis, thrust_axis;
95                 AltosUIAxis     gyro_axis, orient_axis, mag_axis;
96                 AltosUIAxis     course_axis, dop_axis;
97
98                 height_axis = newAxis("Height", AltosConvert.height, height_color);
99                 pressure_axis = newAxis("Pressure", AltosConvert.pressure, pressure_color, 0);
100                 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
101                 thrust_axis = newAxis("Thrust", AltosConvert.force, thrust_color);
102                 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
103                 voltage_axis = newAxis("Voltage", AltosConvert.voltage, voltage_color);
104                 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
105                 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
106                                     AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
107                 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
108                 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
109
110                 gyro_axis = newAxis("Rotation Rate", AltosConvert.rotation_rate, gyro_z_color, 0);
111                 orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0);
112                 mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0);
113                 course_axis = newAxis("Course", orient_units, gps_course_color, 0);
114                 dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0);
115
116                 flight_series.register_axis("default",
117                                             speed_color,
118                                             false,
119                                             speed_axis);
120
121                 flight_series.register_marker(AltosUIFlightSeries.state_name,
122                                               state_color,
123                                               true,
124                                               plot);
125
126                 flight_series.register_axis(AltosUIFlightSeries.accel_name,
127                                             accel_color,
128                                             true,
129                                             accel_axis);
130
131                 flight_series.register_axis(AltosUIFlightSeries.kalman_accel_name,
132                                             kalman_accel_color,
133                                             false,
134                                             accel_axis);
135
136                 flight_series.register_axis(AltosUIFlightSeries.rssi_name,
137                                             dbm_color,
138                                             false,
139                                             dbm_axis);
140
141                 flight_series.register_axis(AltosUIFlightSeries.speed_name,
142                                             speed_color,
143                                             true,
144                                             speed_axis);
145
146                 flight_series.register_axis(AltosUIFlightSeries.kalman_speed_name,
147                                             kalman_speed_color,
148                                             true,
149                                             speed_axis);
150
151                 flight_series.register_axis(AltosUIFlightSeries.pressure_name,
152                                             pressure_color,
153                                             false,
154                                             pressure_axis);
155
156                 flight_series.register_axis(AltosUIFlightSeries.height_name,
157                                             height_color,
158                                             true,
159                                             height_axis);
160
161                 flight_series.register_axis(AltosUIFlightSeries.kalman_height_name,
162                                             kalman_height_color,
163                                             false,
164                                             height_axis);
165
166
167                 flight_series.register_axis(AltosUIFlightSeries.sats_in_view_name,
168                                             gps_nsat_view_color,
169                                             false,
170                                             nsat_axis);
171
172
173                 flight_series.register_axis(AltosUIFlightSeries.sats_in_soln_name,
174                                             gps_nsat_solution_color,
175                                             false,
176                                             nsat_axis);
177
178
179                 flight_series.register_axis(AltosUIFlightSeries.gps_altitude_name,
180                                             gps_height_color,
181                                             false,
182                                             height_axis);
183
184                 flight_series.register_axis(AltosUIFlightSeries.gps_height_name,
185                                             gps_height_color,
186                                             false,
187                                             height_axis);
188
189                 flight_series.register_axis(AltosUIFlightSeries.gps_ground_speed_name,
190                                             gps_ground_speed_color,
191                                             false,
192                                             speed_axis);
193
194
195                 flight_series.register_axis(AltosUIFlightSeries.gps_ascent_rate_name,
196                                             gps_climb_rate_color,
197                                             false,
198                                             speed_axis);
199
200
201                 flight_series.register_axis(AltosUIFlightSeries.gps_course_name,
202                                             gps_course_color,
203                                             false,
204                                             course_axis);
205
206                 flight_series.register_axis(AltosUIFlightSeries.gps_speed_name,
207                                             gps_speed_color,
208                                             false,
209                                             speed_axis);
210
211                 flight_series.register_axis(AltosUIFlightSeries.thrust_name,
212                                             thrust_color,
213                                             true,
214                                             thrust_axis);
215
216 //              addMarker("State", AltosGraphDataPoint.data_state, state_color);
217
218                 return flight_series.series(cal_data);
219 /*
220                 if (stats.has_flight_data) {
221                         addSeries("Height",
222                                   AltosGraphDataPoint.data_height,
223                                   AltosConvert.height,
224                                   height_color,
225                                   true,
226                                   height_axis);
227                         addSeries("Pressure",
228                                   AltosGraphDataPoint.data_pressure,
229                                   pressure_units,
230                                   pressure_color,
231                                   false,
232                                   pressure_axis);
233                         addSeries("Thrust",
234                                   AltosGraphDataPoint.data_thrust,
235                                   thrust_units,
236                                   thrust_color,
237                                   false,
238                                   thrust_axis);
239                         addSeries("Speed",
240                                   AltosGraphDataPoint.data_speed,
241                                   AltosConvert.speed,
242                                   speed_color,
243                                   true,
244                                   speed_axis);
245                         addSeries("Acceleration",
246                                   AltosGraphDataPoint.data_accel,
247                                   AltosConvert.accel,
248                                   accel_color,
249                                   true,
250                                   accel_axis);
251                 }
252                 if (stats.has_gps) {
253                         boolean enable_gps = false;
254
255                         if (!stats.has_flight_data)
256                                 enable_gps = true;
257
258                         addSeries("Range",
259                                   AltosGraphDataPoint.data_range,
260                                   AltosConvert.distance,
261                                   range_color,
262                                   false,
263                                   distance_axis);
264                         addSeries("Distance",
265                                   AltosGraphDataPoint.data_distance,
266                                   AltosConvert.distance,
267                                   distance_color,
268                                   enable_gps,
269                                   distance_axis);
270                         addSeries("GPS Height",
271                                   AltosGraphDataPoint.data_gps_height,
272                                   AltosConvert.height,
273                                   gps_height_color,
274                                   enable_gps,
275                                   height_axis);
276                         addSeries("GPS Altitude",
277                                   AltosGraphDataPoint.data_gps_altitude,
278                                   AltosConvert.height,
279                                   gps_height_color,
280                                   false,
281                                   height_axis);
282                         addSeries("GPS Satellites in Solution",
283                                   AltosGraphDataPoint.data_gps_nsat_solution,
284                                   nsat_units,
285                                   gps_nsat_solution_color,
286                                   false,
287                                   nsat_axis);
288                         if (stats.has_gps_sats) {
289                                 addSeries("GPS Satellites in View",
290                                           AltosGraphDataPoint.data_gps_nsat_view,
291                                           nsat_units,
292                                           gps_nsat_view_color,
293                                           false,
294                                           nsat_axis);
295                         }
296                         if (stats.has_gps_detail) {
297                                 addSeries("GPS Course",
298                                           AltosGraphDataPoint.data_gps_course,
299                                           orient_units,
300                                           gps_course_color,
301                                           false,
302                                           course_axis);
303                                 addSeries("GPS Ground Speed",
304                                           AltosGraphDataPoint.data_gps_ground_speed,
305                                           AltosConvert.speed,
306                                           gps_ground_speed_color,
307                                           enable_gps,
308                                           speed_axis);
309                                 addSeries("GPS Climb Rate",
310                                           AltosGraphDataPoint.data_gps_climb_rate,
311                                           AltosConvert.speed,
312                                           gps_climb_rate_color,
313                                           enable_gps,
314                                           speed_axis);
315                         }
316                         addSeries("GPS Position DOP",
317                                   AltosGraphDataPoint.data_gps_pdop,
318                                   dop_units,
319                                   gps_pdop_color,
320                                   false,
321                                   dop_axis);
322                         if (stats.has_gps_detail) {
323                                 addSeries("GPS Horizontal DOP",
324                                           AltosGraphDataPoint.data_gps_hdop,
325                                           dop_units,
326                                           gps_hdop_color,
327                                           false,
328                                           dop_axis);
329                                 addSeries("GPS Vertical DOP",
330                                           AltosGraphDataPoint.data_gps_vdop,
331                                           dop_units,
332                                           gps_vdop_color,
333                                           false,
334                                           dop_axis);
335                         }
336                 }
337                 if (stats.has_rssi)
338                         addSeries("Received Signal Strength",
339                                   AltosGraphDataPoint.data_rssi,
340                                   dbm_units,
341                                   dbm_color,
342                                   false,
343                                   dbm_axis);
344
345                 if (stats.has_battery)
346                         addSeries("Battery Voltage",
347                                   AltosGraphDataPoint.data_battery_voltage,
348                                   voltage_units,
349                                   battery_voltage_color,
350                                   false,
351                                   voltage_axis);
352
353                 if (stats.has_flight_adc) {
354                         addSeries("Temperature",
355                                   AltosGraphDataPoint.data_temperature,
356                                   AltosConvert.temperature,
357                                   temperature_color,
358                                   false,
359                                   temperature_axis);
360                         addSeries("Drogue Voltage",
361                                   AltosGraphDataPoint.data_drogue_voltage,
362                                   voltage_units,
363                                   drogue_voltage_color,
364                                   false,
365                                   voltage_axis);
366                         addSeries("Main Voltage",
367                                   AltosGraphDataPoint.data_main_voltage,
368                                   voltage_units,
369                                   main_voltage_color,
370                                   false,
371                                   voltage_axis);
372                 }
373
374                 if (stats.has_imu) {
375                         addSeries("Acceleration Along",
376                                   AltosGraphDataPoint.data_accel_along,
377                                   AltosConvert.accel,
378                                   accel_x_color,
379                                   false,
380                                   accel_axis);
381                         addSeries("Acceleration Across",
382                                   AltosGraphDataPoint.data_accel_across,
383                                   AltosConvert.accel,
384                                   accel_y_color,
385                                   false,
386                                   accel_axis);
387                         addSeries("Acceleration Through",
388                                   AltosGraphDataPoint.data_accel_through,
389                                   AltosConvert.accel,
390                                   accel_z_color,
391                                   false,
392                                   accel_axis);
393                         addSeries("Roll Rate",
394                                   AltosGraphDataPoint.data_gyro_roll,
395                                   gyro_units,
396                                   gyro_x_color,
397                                   false,
398                                   gyro_axis);
399                         addSeries("Pitch Rate",
400                                   AltosGraphDataPoint.data_gyro_pitch,
401                                   gyro_units,
402                                   gyro_y_color,
403                                   false,
404                                   gyro_axis);
405                         addSeries("Yaw Rate",
406                                   AltosGraphDataPoint.data_gyro_yaw,
407                                   gyro_units,
408                                   gyro_z_color,
409                                   false,
410                                   gyro_axis);
411                 }
412                 if (stats.has_mag) {
413                         addSeries("Magnetometer Along",
414                                   AltosGraphDataPoint.data_mag_along,
415                                   mag_units,
416                                   mag_x_color,
417                                   false,
418                                   mag_axis);
419                         addSeries("Magnetometer Across",
420                                   AltosGraphDataPoint.data_mag_across,
421                                   mag_units,
422                                   mag_y_color,
423                                   false,
424                                   mag_axis);
425                         addSeries("Magnetometer Through",
426                                   AltosGraphDataPoint.data_mag_through,
427                                   mag_units,
428                                   mag_z_color,
429                                   false,
430                                   mag_axis);
431                 }
432                 if (stats.has_orient)
433                         addSeries("Tilt Angle",
434                                   AltosGraphDataPoint.data_orient,
435                                   orient_units,
436                                   orient_color,
437                                   false,
438                                   orient_axis);
439                 if (stats.num_ignitor > 0) {
440                         for (int i = 0; i < stats.num_ignitor; i++)
441                                 addSeries(AltosLib.ignitor_name(i),
442                                           AltosGraphDataPoint.data_ignitor_0 + i,
443                                           voltage_units,
444                                           main_voltage_color,
445                                           false,
446                                           voltage_axis);
447                         for (int i = 0; i < stats.num_ignitor; i++)
448                                 addMarker(AltosLib.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);
449                 }
450 */
451         }
452
453         public AltosGraphNew(AltosUIEnable enable, AltosFlightStats stats, AltosUIFlightSeries flight_series, AltosCalData cal_data) {
454                 super(enable, "Flight");
455
456                 set_series(setup(stats, flight_series, cal_data));
457         }
458 }