From f558cfa1df77c36a459168c1953d0945ee5a7f9f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 30 Mar 2011 11:48:03 -0700 Subject: [PATCH] altosui: Only plot acceleration when present in data file Eliminates a bogus axis and data line for devices which do not have an accelerometer. Signed-off-by: Keith Packard --- altosui/AltosDataPointReader.java | 10 +++++++-- altosui/AltosEepromIterable.java | 20 +++++++++++++++-- altosui/AltosGraphUI.java | 33 +++++++++++++++++------------ altosui/AltosRecord.java | 20 +++++++++++------ altosui/AltosRecordIterable.java | 3 +++ altosui/AltosTelemetryIterable.java | 13 ++++++++++++ 6 files changed, 75 insertions(+), 24 deletions(-) diff --git a/altosui/AltosDataPointReader.java b/altosui/AltosDataPointReader.java index ee57d2ce..4335421c 100644 --- a/altosui/AltosDataPointReader.java +++ b/altosui/AltosDataPointReader.java @@ -14,12 +14,18 @@ class AltosDataPointReader implements Iterable { Iterator iter; AltosState state; AltosRecord record; + boolean has_gps; + boolean has_accel; + boolean has_ignite; final static int MISSING = AltosRecord.MISSING; - public AltosDataPointReader(Iterable reader) { + public AltosDataPointReader(AltosRecordIterable reader) { this.iter = reader.iterator(); this.state = null; + has_accel = reader.has_accel(); + has_gps = reader.has_gps(); + has_ignite = reader.has_ignite(); } private void read_next_record() @@ -46,7 +52,7 @@ class AltosDataPointReader implements Iterable { public double acceleration() { return record.acceleration(); } public double pressure() { return record.raw_pressure(); } public double altitude() { return record.raw_altitude(); } - public double height() { return record.raw_height(); } + public double height() { return record.raw_height(); } public double accel_speed() { return record.accel_speed(); } public double baro_speed() { return state.baro_speed; } public double temperature() { return record.temperature(); } diff --git a/altosui/AltosEepromIterable.java b/altosui/AltosEepromIterable.java index a7fd742f..624e1dd3 100644 --- a/altosui/AltosEepromIterable.java +++ b/altosui/AltosEepromIterable.java @@ -57,6 +57,11 @@ class AltosOrderedRecord extends AltosEepromRecord implements Comparable> Altos.AO_GPS_NUM_SAT_SHIFT; + has_gps = true; break; case Altos.AO_LOG_GPS_LAT: int lat32 = record.a | (record.b << 16); @@ -254,6 +266,10 @@ public class AltosEepromIterable extends AltosRecordIterable { return list.iterator(); } + public boolean has_gps() { return has_gps; } + public boolean has_accel() { return has_accel; } + public boolean has_ignite() { return has_ignite; } + public void write_comments(PrintStream out) { Iterator iterator = records.iterator(); out.printf("# Comments\n"); diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java index cd158651..e98c302b 100644 --- a/altosui/AltosGraphUI.java +++ b/altosui/AltosGraphUI.java @@ -96,10 +96,14 @@ public class AltosGraphUI extends JFrame public ArrayList graphs() { ArrayList graphs = new ArrayList(); - graphs.add( myAltosGraphTime("Summary") - .addElement(height) - .addElement(speed) - .addElement(acceleration) ); + graphs.add( myAltosGraphTime("Summary") + .addElement(height) + .addElement(speed) + .addElement(acceleration) ); + + graphs.add( myAltosGraphTime("Summary") + .addElement(height) + .addElement(speed)); graphs.add( myAltosGraphTime("Altitude") .addElement(height) ); @@ -107,15 +111,15 @@ public class AltosGraphUI extends JFrame graphs.add( myAltosGraphTime("Speed") .addElement(speed) ); - graphs.add( myAltosGraphTime("Acceleration") - .addElement(acceleration) ); + graphs.add( myAltosGraphTime("Acceleration") + .addElement(acceleration) ); graphs.add( myAltosGraphTime("Temperature") .addElement(temperature) ); - graphs.add( myAltosGraphTime("Continuity") - .addElement(drogue_voltage) - .addElement(main_voltage) ); + graphs.add( myAltosGraphTime("Continuity") + .addElement(drogue_voltage) + .addElement(main_voltage) ); return graphs; } @@ -154,20 +158,23 @@ public class AltosGraphUI extends JFrame public AltosGraphUI(AltosRecordIterable records) { super("Altos Graph"); - Iterable reader = new AltosDataPointReader (records); + AltosDataPointReader reader = new AltosDataPointReader (records); if (reader == null) return; - init(reader, 0); + if (reader.has_accel) + init(reader, 0); + else + init(reader, 1); } - public AltosGraphUI(Iterable data, int which) + public AltosGraphUI(AltosDataPointReader data, int which) { super("Altos Graph"); init(data, which); } - private void init(Iterable data, int which) { + private void init(AltosDataPointReader data, int which) { AltosGraph graph = createGraph(data, which); JFreeChart chart = graph.createChart(); diff --git a/altosui/AltosRecord.java b/altosui/AltosRecord.java index 46e96b95..200fffe5 100644 --- a/altosui/AltosRecord.java +++ b/altosui/AltosRecord.java @@ -139,7 +139,7 @@ public class AltosRecord { double g = ground_altitude(); if (r == MISSING || g == MISSING) - return MISSING; + return height; return r - g; } @@ -246,6 +246,9 @@ public class AltosRecord { ground_pres = old.ground_pres; accel_plus_g = old.accel_plus_g; accel_minus_g = old.accel_minus_g; + acceleration = old.acceleration; + speed = old.speed; + height = old.height; gps = new AltosGPS(old.gps); } @@ -258,12 +261,12 @@ public class AltosRecord { status = 0; state = Altos.ao_flight_startup; tick = 0; - accel = 0; - pres = 0; - temp = 0; - batt = 0; - drogue = 0; - main = 0; + accel = MISSING; + pres = MISSING; + temp = MISSING; + batt = MISSING; + drogue = MISSING; + main = MISSING; flight_accel = 0; ground_accel = 0; flight_vel = 0; @@ -271,6 +274,9 @@ public class AltosRecord { ground_pres = 0; accel_plus_g = 0; accel_minus_g = 0; + acceleration = MISSING; + speed = MISSING; + height = MISSING; gps = new AltosGPS(); } } diff --git a/altosui/AltosRecordIterable.java b/altosui/AltosRecordIterable.java index a7df92d1..45843b92 100644 --- a/altosui/AltosRecordIterable.java +++ b/altosui/AltosRecordIterable.java @@ -31,4 +31,7 @@ import java.util.concurrent.LinkedBlockingQueue; public abstract class AltosRecordIterable implements Iterable { public abstract Iterator iterator(); public void write_comments(PrintStream out) { } + public boolean has_accel() { return false; } + public boolean has_gps() { return false; } + public boolean has_ignite() { return false; }; } diff --git a/altosui/AltosTelemetryIterable.java b/altosui/AltosTelemetryIterable.java index 14b5f27f..44e5ad8f 100644 --- a/altosui/AltosTelemetryIterable.java +++ b/altosui/AltosTelemetryIterable.java @@ -28,6 +28,13 @@ public class AltosTelemetryIterable extends AltosRecordIterable { return records.iterator(); } + boolean has_gps = false; + boolean has_accel = false; + boolean has_ignite = false; + public boolean has_gps() { return has_gps; } + public boolean has_accel() { return has_accel; } + public boolean has_ignite() { return has_ignite; }; + public AltosTelemetryIterable (FileInputStream input) { boolean saw_boost = false; int current_tick = 0; @@ -59,6 +66,12 @@ public class AltosTelemetryIterable extends AltosRecordIterable { saw_boost = true; boost_tick = record.tick; } + if (record.accel != AltosRecord.MISSING) + has_accel = true; + if (record.gps != null) + has_gps = true; + if (record.main != AltosRecord.MISSING) + has_ignite = true; records.add(record); } catch (ParseException pe) { System.out.printf("parse exception %s\n", pe.getMessage()); -- 2.30.2