2 // Copyright (c) 2010 Anthony Towns
8 import java.util.ArrayList;
11 import java.awt.event.*;
13 import javax.swing.filechooser.FileNameExtensionFilter;
14 import javax.swing.table.*;
15 import org.altusmetrum.AltosLib.*;
17 import org.jfree.chart.ChartPanel;
18 import org.jfree.chart.ChartUtilities;
19 import org.jfree.chart.JFreeChart;
20 import org.jfree.chart.axis.AxisLocation;
21 import org.jfree.ui.ApplicationFrame;
22 import org.jfree.ui.RefineryUtilities;
24 public class AltosGraphUI extends AltosFrame
28 static final private Color red = new Color(194,31,31);
29 static final private Color green = new Color(31,194,31);
30 static final private Color blue = new Color(31,31,194);
31 static final private Color black = new Color(31,31,31);
32 static final private Color yellow = new Color(194,194,31);
33 static final private Color cyan = new Color(31,194,194);
34 static final private Color magenta = new Color(194,31,194);
36 static private class OverallGraphs {
37 AltosGraphTime.Element height =
38 new AltosGraphTime.TimeSeries(String.format("Height (%s)", AltosConvert.height.show_units()), "Height (AGL)", red) {
39 public void gotTimeData(double time, AltosDataPoint d) {
40 double height = d.height();
41 if (height != AltosRecord.MISSING)
42 series.add(time, AltosConvert.height.value(height));
46 AltosGraphTime.Element speed =
47 new AltosGraphTime.TimeSeries(String.format("Speed (%s)", AltosConvert.speed.show_units()), "Vertical Speed", green) {
48 public void gotTimeData(double time, AltosDataPoint d) {
50 if (d.state() < Altos.ao_flight_drogue && d.has_accel()) {
51 speed = d.accel_speed();
53 speed = d.baro_speed();
55 if (speed != AltosRecord.MISSING)
56 series.add(time, AltosConvert.speed.value(speed));
60 AltosGraphTime.Element acceleration =
61 new AltosGraphTime.TimeSeries(String.format("Acceleration (%s)",
62 AltosConvert.accel.show_units()),
63 "Axial Acceleration", blue)
65 public void gotTimeData(double time, AltosDataPoint d) {
66 double acceleration = d.acceleration();
67 if (acceleration != AltosRecord.MISSING)
68 series.add(time, AltosConvert.accel.value(acceleration));
72 AltosGraphTime.Element temperature =
73 new AltosGraphTime.TimeSeries("Temperature (\u00B0C)",
74 "Board temperature", red)
76 public void gotTimeData(double time, AltosDataPoint d) {
77 double temp = d.temperature();
78 if (temp != AltosRecord.MISSING)
79 series.add(time, d.temperature());
83 AltosGraphTime.Element drogue_voltage =
84 new AltosGraphTime.TimeSeries("Voltage (V)", "Drogue Continuity", yellow)
86 public void gotTimeData(double time, AltosDataPoint d) {
87 double v = d.drogue_voltage();
88 if (v != AltosRecord.MISSING)
93 AltosGraphTime.Element main_voltage =
94 new AltosGraphTime.TimeSeries("Voltage (V)", "Main Continuity", magenta)
96 public void gotTimeData(double time, AltosDataPoint d) {
97 double v = d.main_voltage();
98 if (v != AltosRecord.MISSING)
103 AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad");
104 AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost");
105 AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast");
106 AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast");
107 AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(Altos.ao_flight_drogue, "Drogue");
108 AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(Altos.ao_flight_main, "Main");
109 AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(Altos.ao_flight_landed, "Landed");
111 protected AltosGraphTime myAltosGraphTime(String suffix) {
112 return (new AltosGraphTime("Overall " + suffix))
116 .addElement(e_drogue)
118 .addElement(e_landed);
121 public ArrayList<AltosGraph> graphs() {
122 ArrayList<AltosGraph> graphs = new ArrayList<AltosGraph>();
124 graphs.add( myAltosGraphTime("Summary")
127 .addElement(acceleration) );
129 graphs.add( myAltosGraphTime("Summary")
133 graphs.add( myAltosGraphTime("Altitude")
134 .addElement(height) );
136 graphs.add( myAltosGraphTime("Speed")
137 .addElement(speed) );
139 graphs.add( myAltosGraphTime("Acceleration")
140 .addElement(acceleration) );
142 graphs.add( myAltosGraphTime("Temperature")
143 .addElement(temperature) );
145 graphs.add( myAltosGraphTime("Continuity")
146 .addElement(drogue_voltage)
147 .addElement(main_voltage) );
153 static private class AscentGraphs extends OverallGraphs {
154 protected AltosGraphTime myAltosGraphTime(String suffix) {
155 return (new AltosGraphTime("Ascent " + suffix) {
156 public void addData(AltosDataPoint d) {
157 int state = d.state();
158 if (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast) {
162 }).addElement(e_boost)
164 .addElement(e_coast);
168 static private class DescentGraphs extends OverallGraphs {
169 protected AltosGraphTime myAltosGraphTime(String suffix) {
170 return (new AltosGraphTime("Descent " + suffix) {
171 public void addData(AltosDataPoint d) {
172 int state = d.state();
173 if (Altos.ao_flight_drogue <= state && state <= Altos.ao_flight_main) {
177 }).addElement(e_drogue)
179 // ((XYGraph)graph[8]).ymin = new Double(-50);
183 public AltosGraphUI(AltosRecordIterable records, String name) throws InterruptedException, IOException {
184 super(String.format("Altos Graph %s", name));
186 AltosDataPointReader reader = new AltosDataPointReader (records);
190 if (reader.has_accel)
191 init(reader, records, 0);
193 init(reader, records, 1);
196 // public AltosGraphUI(AltosDataPointReader data, int which)
198 // super("Altos Graph");
199 // init(data, which);
202 private void init(AltosDataPointReader data, AltosRecordIterable records, int which) throws InterruptedException, IOException {
203 pane = new JTabbedPane();
205 AltosGraph graph = createGraph(data, which);
207 JFreeChart chart = graph.createChart();
208 ChartPanel chartPanel = new ChartPanel(chart);
209 chartPanel.setMouseWheelEnabled(true);
210 chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
211 pane.add(graph.title, chartPanel);
213 AltosFlightStatsTable stats = new AltosFlightStatsTable(new AltosFlightStats(records));
214 pane.add("Flight Statistics", stats);
216 setContentPane (pane);
220 RefineryUtilities.centerFrameOnScreen(this);
222 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
226 private static AltosGraph createGraph(Iterable<AltosDataPoint> data,
229 return createGraphsWhich(data, which).get(0);
232 private static ArrayList<AltosGraph> createGraphs(
233 Iterable<AltosDataPoint> data)
235 return createGraphsWhich(data, -1);
238 private static ArrayList<AltosGraph> createGraphsWhich(
239 Iterable<AltosDataPoint> data, int which)
241 ArrayList<AltosGraph> graph = new ArrayList<AltosGraph>();
242 graph.addAll((new OverallGraphs()).graphs());
243 // graph.addAll((new AscentGraphs()).graphs());
244 // graph.addAll((new DescentGraphs()).graphs());
247 if (which >= graph.size()) {
250 AltosGraph g = graph.get(which);
251 graph = new ArrayList<AltosGraph>();
255 for (AltosDataPoint dp : data) {
256 for (AltosGraph g : graph) {
269 --------------------------------------------------------
272 "ascent-gps-accuracy.png" "Vertical error margin to apogee - GPS v Baro (m)"
273 5:($7 < 6 ? $24-$11 : 1/0)
274 "descent-gps-accuracy.png" "Vertical error margin during descent - GPS v Baro (m)"
275 5:($7 < 6 ? 1/0 : $24-$11)
277 set output "overall-gps-accuracy.png"
278 set ylabel "distance above sea level (m)"
279 plot "telemetry.csv" using 5:11 with lines ti "baro altitude" axis x1y1, \
280 "telemetry.csv" using 5:24 with lines ti "gps altitude" axis x1y1
282 set term png tiny size 700,700 enhanced
290 set output "overall-gps-path.png"
291 #:30 with yerrorlines
292 plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0) with lines ti "pad", \
293 "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0) with lines ti "boost", \
294 "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0) with lines ti "fast", \
295 "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0) with lines ti "coast", \
296 "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \
297 "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \
298 "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed"
300 set output "ascent-gps-path.png"
301 plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0):30 with lines ti "pad", \
302 "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0):20 with lines ti "boost", \
303 "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0):10 with lines ti "fast", \
304 "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0):5 with lines ti "coast"
306 set output "descent-gps-path.png"
307 plot "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \
308 "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \
309 "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed"