2 // Copyright (c) 2010 Anthony Towns
8 import java.util.ArrayList;
10 import javax.swing.JFrame;
11 import java.awt.Color;
13 import org.jfree.chart.ChartPanel;
14 import org.jfree.chart.ChartUtilities;
15 import org.jfree.chart.JFreeChart;
16 import org.jfree.chart.axis.AxisLocation;
17 import org.jfree.ui.ApplicationFrame;
18 import org.jfree.ui.RefineryUtilities;
20 public class AltosGraphUI extends JFrame
22 static final private Color red = new Color(194,31,31);
23 static final private Color green = new Color(31,194,31);
24 static final private Color blue = new Color(31,31,194);
25 static final private Color black = new Color(31,31,31);
27 static private class OverallGraphs {
28 AltosGraphTime.Element height =
29 new AltosGraphTime.TimeSeries("Height (m)", "Height (AGL)", red) {
30 public void gotTimeData(double time, AltosDataPoint d) {
31 series.add(time, d.height());
35 AltosGraphTime.Element speed =
36 new AltosGraphTime.TimeSeries("Speed (m/s)", "Vertical Speed", green) {
37 public void gotTimeData(double time, AltosDataPoint d) {
38 if (d.state() < Altos.ao_flight_drogue) {
39 series.add(time, d.accel_speed());
41 series.add(time, d.baro_speed());
46 AltosGraphTime.Element acceleration =
47 new AltosGraphTime.TimeSeries("Acceleration (m/s\u00B2)",
48 "Axial Acceleration", blue)
50 public void gotTimeData(double time, AltosDataPoint d) {
51 series.add(time, d.acceleration());
55 AltosGraphTime.Element temperature =
56 new AltosGraphTime.TimeSeries("Temperature (\u00B0C)",
57 "Board temperature", red)
59 public void gotTimeData(double time, AltosDataPoint d) {
60 series.add(time, d.temperature());
64 AltosGraphTime.Element drogue_voltage =
65 new AltosGraphTime.TimeSeries("Voltage (V)", "Drogue Continuity", blue)
67 public void gotTimeData(double time, AltosDataPoint d) {
68 series.add(time, d.drogue_voltage());
72 AltosGraphTime.Element main_voltage =
73 new AltosGraphTime.TimeSeries("Voltage (V)", "Main Continuity", green)
75 public void gotTimeData(double time, AltosDataPoint d) {
76 series.add(time, d.main_voltage());
80 AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad");
81 AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost");
82 AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast");
83 AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast");
84 AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(Altos.ao_flight_drogue, "Drogue");
85 AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(Altos.ao_flight_main, "Main");
86 AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(Altos.ao_flight_landed, "Landed");
88 protected AltosGraphTime myAltosGraphTime(String suffix) {
89 return (new AltosGraphTime("Overall " + suffix))
93 .addElement(e_landed);
96 public ArrayList<AltosGraph> graphs() {
97 ArrayList<AltosGraph> graphs = new ArrayList<AltosGraph>();
99 graphs.add( myAltosGraphTime("Summary")
102 .addElement(acceleration) );
104 graphs.add( myAltosGraphTime("Altitude")
105 .addElement(height) );
107 graphs.add( myAltosGraphTime("Speed")
108 .addElement(speed) );
110 graphs.add( myAltosGraphTime("Acceleration")
111 .addElement(acceleration) );
113 graphs.add( myAltosGraphTime("Temperature")
114 .addElement(temperature) );
116 graphs.add( myAltosGraphTime("Continuity")
117 .addElement(drogue_voltage)
118 .addElement(main_voltage) );
124 static private class AscentGraphs extends OverallGraphs {
125 protected AltosGraphTime myAltosGraphTime(String suffix) {
126 return (new AltosGraphTime("Ascent " + suffix) {
127 public void addData(AltosDataPoint d) {
128 int state = d.state();
129 if (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast) {
133 }).addElement(e_boost)
135 .addElement(e_coast);
139 static private class DescentGraphs extends OverallGraphs {
140 protected AltosGraphTime myAltosGraphTime(String suffix) {
141 return (new AltosGraphTime("Descent " + suffix) {
142 public void addData(AltosDataPoint d) {
143 int state = d.state();
144 if (Altos.ao_flight_drogue <= state && state <= Altos.ao_flight_main) {
148 }).addElement(e_drogue)
150 // ((XYGraph)graph[8]).ymin = new Double(-50);
154 public AltosGraphUI(AltosRecordIterable records) {
155 super("Altos Graph");
157 Iterable<AltosDataPoint> reader = new AltosDataPointReader (records);
164 public AltosGraphUI(Iterable<AltosDataPoint> data, int which)
166 super("Altos Graph");
170 private void init(Iterable<AltosDataPoint> data, int which) {
171 AltosGraph graph = createGraph(data, which);
173 JFreeChart chart = graph.createChart();
174 ChartPanel chartPanel = new ChartPanel(chart);
175 chartPanel.setMouseWheelEnabled(true);
176 chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
177 setContentPane(chartPanel);
181 RefineryUtilities.centerFrameOnScreen(this);
183 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
187 private static AltosGraph createGraph(Iterable<AltosDataPoint> data,
190 return createGraphsWhich(data, which).get(0);
193 private static ArrayList<AltosGraph> createGraphs(
194 Iterable<AltosDataPoint> data)
196 return createGraphsWhich(data, -1);
199 private static ArrayList<AltosGraph> createGraphsWhich(
200 Iterable<AltosDataPoint> data, int which)
202 ArrayList<AltosGraph> graph = new ArrayList<AltosGraph>();
203 graph.addAll((new OverallGraphs()).graphs());
204 graph.addAll((new AscentGraphs()).graphs());
205 graph.addAll((new DescentGraphs()).graphs());
208 if (which >= graph.size()) {
211 AltosGraph g = graph.get(which);
212 graph = new ArrayList<AltosGraph>();
216 for (AltosDataPoint dp : data) {
217 for (AltosGraph g : graph) {
230 --------------------------------------------------------
233 "ascent-gps-accuracy.png" "Vertical error margin to apogee - GPS v Baro (m)"
234 5:($7 < 6 ? $24-$11 : 1/0)
235 "descent-gps-accuracy.png" "Vertical error margin during descent - GPS v Baro (m)"
236 5:($7 < 6 ? 1/0 : $24-$11)
238 set output "overall-gps-accuracy.png"
239 set ylabel "distance above sea level (m)"
240 plot "telemetry.csv" using 5:11 with lines ti "baro altitude" axis x1y1, \
241 "telemetry.csv" using 5:24 with lines ti "gps altitude" axis x1y1
243 set term png tiny size 700,700 enhanced
251 set output "overall-gps-path.png"
252 #:30 with yerrorlines
253 plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0) with lines ti "pad", \
254 "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0) with lines ti "boost", \
255 "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0) with lines ti "fast", \
256 "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0) with lines ti "coast", \
257 "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \
258 "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \
259 "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed"
261 set output "ascent-gps-path.png"
262 plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0):30 with lines ti "pad", \
263 "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0):20 with lines ti "boost", \
264 "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0):10 with lines ti "fast", \
265 "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0):5 with lines ti "coast"
267 set output "descent-gps-path.png"
268 plot "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \
269 "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \
270 "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed"