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("Height (m)", "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, d.height());
46 AltosGraphTime.Element speed =
47 new AltosGraphTime.TimeSeries("Speed (m/s)", "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, speed);
60 AltosGraphTime.Element acceleration =
61 new AltosGraphTime.TimeSeries("Acceleration (m/s\u00B2)",
62 "Axial Acceleration", blue)
64 public void gotTimeData(double time, AltosDataPoint d) {
65 double acceleration = d.acceleration();
66 if (acceleration != AltosRecord.MISSING)
67 series.add(time, acceleration);
71 AltosGraphTime.Element temperature =
72 new AltosGraphTime.TimeSeries("Temperature (\u00B0C)",
73 "Board temperature", red)
75 public void gotTimeData(double time, AltosDataPoint d) {
76 double temp = d.temperature();
77 if (temp != AltosRecord.MISSING)
78 series.add(time, d.temperature());
82 AltosGraphTime.Element drogue_voltage =
83 new AltosGraphTime.TimeSeries("Voltage (V)", "Drogue Continuity", yellow)
85 public void gotTimeData(double time, AltosDataPoint d) {
86 double v = d.drogue_voltage();
87 if (v != AltosRecord.MISSING)
92 AltosGraphTime.Element main_voltage =
93 new AltosGraphTime.TimeSeries("Voltage (V)", "Main Continuity", magenta)
95 public void gotTimeData(double time, AltosDataPoint d) {
96 double v = d.main_voltage();
97 if (v != AltosRecord.MISSING)
102 AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad");
103 AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost");
104 AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast");
105 AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast");
106 AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(Altos.ao_flight_drogue, "Drogue");
107 AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(Altos.ao_flight_main, "Main");
108 AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(Altos.ao_flight_landed, "Landed");
110 protected AltosGraphTime myAltosGraphTime(String suffix) {
111 return (new AltosGraphTime("Overall " + suffix))
115 .addElement(e_drogue)
117 .addElement(e_landed);
120 public ArrayList<AltosGraph> graphs() {
121 ArrayList<AltosGraph> graphs = new ArrayList<AltosGraph>();
123 graphs.add( myAltosGraphTime("Summary")
126 .addElement(acceleration) );
128 graphs.add( myAltosGraphTime("Summary")
132 graphs.add( myAltosGraphTime("Altitude")
133 .addElement(height) );
135 graphs.add( myAltosGraphTime("Speed")
136 .addElement(speed) );
138 graphs.add( myAltosGraphTime("Acceleration")
139 .addElement(acceleration) );
141 graphs.add( myAltosGraphTime("Temperature")
142 .addElement(temperature) );
144 graphs.add( myAltosGraphTime("Continuity")
145 .addElement(drogue_voltage)
146 .addElement(main_voltage) );
152 static private class AscentGraphs extends OverallGraphs {
153 protected AltosGraphTime myAltosGraphTime(String suffix) {
154 return (new AltosGraphTime("Ascent " + suffix) {
155 public void addData(AltosDataPoint d) {
156 int state = d.state();
157 if (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast) {
161 }).addElement(e_boost)
163 .addElement(e_coast);
167 static private class DescentGraphs extends OverallGraphs {
168 protected AltosGraphTime myAltosGraphTime(String suffix) {
169 return (new AltosGraphTime("Descent " + suffix) {
170 public void addData(AltosDataPoint d) {
171 int state = d.state();
172 if (Altos.ao_flight_drogue <= state && state <= Altos.ao_flight_main) {
176 }).addElement(e_drogue)
178 // ((XYGraph)graph[8]).ymin = new Double(-50);
182 public AltosGraphUI(AltosRecordIterable records, String name) throws InterruptedException, IOException {
183 super(String.format("Altos Graph %s", name));
185 AltosDataPointReader reader = new AltosDataPointReader (records);
189 if (reader.has_accel)
190 init(reader, records, 0);
192 init(reader, records, 1);
195 // public AltosGraphUI(AltosDataPointReader data, int which)
197 // super("Altos Graph");
198 // init(data, which);
201 private void init(AltosDataPointReader data, AltosRecordIterable records, int which) throws InterruptedException, IOException {
202 pane = new JTabbedPane();
204 AltosGraph graph = createGraph(data, which);
206 JFreeChart chart = graph.createChart();
207 ChartPanel chartPanel = new ChartPanel(chart);
208 chartPanel.setMouseWheelEnabled(true);
209 chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
210 pane.add(graph.title, chartPanel);
212 AltosFlightStatsTable stats = new AltosFlightStatsTable(new AltosFlightStats(records));
213 pane.add("Flight Statistics", stats);
215 setContentPane (pane);
219 RefineryUtilities.centerFrameOnScreen(this);
221 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
225 private static AltosGraph createGraph(Iterable<AltosDataPoint> data,
228 return createGraphsWhich(data, which).get(0);
231 private static ArrayList<AltosGraph> createGraphs(
232 Iterable<AltosDataPoint> data)
234 return createGraphsWhich(data, -1);
237 private static ArrayList<AltosGraph> createGraphsWhich(
238 Iterable<AltosDataPoint> data, int which)
240 ArrayList<AltosGraph> graph = new ArrayList<AltosGraph>();
241 graph.addAll((new OverallGraphs()).graphs());
242 // graph.addAll((new AscentGraphs()).graphs());
243 // graph.addAll((new DescentGraphs()).graphs());
246 if (which >= graph.size()) {
249 AltosGraph g = graph.get(which);
250 graph = new ArrayList<AltosGraph>();
254 for (AltosDataPoint dp : data) {
255 for (AltosGraph g : graph) {
268 --------------------------------------------------------
271 "ascent-gps-accuracy.png" "Vertical error margin to apogee - GPS v Baro (m)"
272 5:($7 < 6 ? $24-$11 : 1/0)
273 "descent-gps-accuracy.png" "Vertical error margin during descent - GPS v Baro (m)"
274 5:($7 < 6 ? 1/0 : $24-$11)
276 set output "overall-gps-accuracy.png"
277 set ylabel "distance above sea level (m)"
278 plot "telemetry.csv" using 5:11 with lines ti "baro altitude" axis x1y1, \
279 "telemetry.csv" using 5:24 with lines ti "gps altitude" axis x1y1
281 set term png tiny size 700,700 enhanced
289 set output "overall-gps-path.png"
290 #:30 with yerrorlines
291 plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0) with lines ti "pad", \
292 "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0) with lines ti "boost", \
293 "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0) with lines ti "fast", \
294 "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0) with lines ti "coast", \
295 "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \
296 "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \
297 "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed"
299 set output "ascent-gps-path.png"
300 plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0):30 with lines ti "pad", \
301 "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0):20 with lines ti "boost", \
302 "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0):10 with lines ti "fast", \
303 "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0):5 with lines ti "coast"
305 set output "descent-gps-path.png"
306 plot "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \
307 "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \
308 "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed"