altosui: Only plot acceleration when present in data file
authorKeith Packard <keithp@keithp.com>
Wed, 30 Mar 2011 18:48:03 +0000 (11:48 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 30 Mar 2011 18:48:03 +0000 (11:48 -0700)
Eliminates a bogus axis and data line for devices which do not have an
accelerometer.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosDataPointReader.java
altosui/AltosEepromIterable.java
altosui/AltosGraphUI.java
altosui/AltosRecord.java
altosui/AltosRecordIterable.java
altosui/AltosTelemetryIterable.java

index ee57d2ce811ef14116c7b73d6db4b84fb34afc31..4335421c21a96922e0ef0f3bf6f3026efcdcfb3f 100644 (file)
@@ -14,12 +14,18 @@ class AltosDataPointReader implements Iterable<AltosDataPoint> {
     Iterator<AltosRecord> iter;
     AltosState state;
     AltosRecord record;
+    boolean has_gps;
+    boolean has_accel;
+    boolean has_ignite;
 
     final static int MISSING = AltosRecord.MISSING;
 
-    public AltosDataPointReader(Iterable<AltosRecord> 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<AltosDataPoint> {
             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(); }
index a7fd742fc4e6424000de703387a4101ae13f5ea3..624e1dd31bb7c1645a4f3d8f098db2df6f2e0edd 100644 (file)
@@ -57,6 +57,11 @@ class AltosOrderedRecord extends AltosEepromRecord implements Comparable<AltosOr
                index = in_index;
        }
 
+       public String toString() {
+               return String.format("%d.%d %04x %04x %04x",
+                                    cmd, index, tick, a, b);
+       }
+
        public int compareTo(AltosOrderedRecord o) {
                int     tick_diff = tick - o.tick;
                if (tick_diff != 0)
@@ -75,7 +80,11 @@ public class AltosEepromIterable extends AltosRecordIterable {
        static final int        seen_gps_lat = 32;
        static final int        seen_gps_lon = 64;
 
-       static final int        seen_basic = seen_flight|seen_sensor|seen_temp_volt|seen_deploy;
+       static final int        seen_basic = seen_flight|seen_sensor;
+
+       boolean                 has_accel;
+       boolean                 has_gps;
+       boolean                 has_ignite;
 
        AltosEepromRecord       flight_record;
        AltosEepromRecord       gps_date_record;
@@ -123,9 +132,10 @@ public class AltosEepromIterable extends AltosRecordIterable {
                                state.flight_vel += (state.accel_plus_g - state.accel);
                        }
                        eeprom.seen |= seen_sensor;
+                       has_accel = true;
                        break;
                case Altos.AO_LOG_HEIGHT:
-                       state.height = record.a;
+                       state.height = (short) record.a;
                        eeprom.seen |= seen_sensor;
                        break;
                case Altos.AO_LOG_TEMP_VOLT:
@@ -137,6 +147,7 @@ public class AltosEepromIterable extends AltosRecordIterable {
                        state.drogue = record.a;
                        state.main = record.b;
                        eeprom.seen |= seen_deploy;
+                       has_ignite = true;
                        break;
                case Altos.AO_LOG_STATE:
                        state.state = record.a;
@@ -161,6 +172,7 @@ public class AltosEepromIterable extends AltosRecordIterable {
                        state.gps.locked = (flags & Altos.AO_GPS_VALID) != 0;
                        state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >>
                                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<AltosOrderedRecord>    iterator = records.iterator();
                out.printf("# Comments\n");
index cd158651402d2634e4763015c1d36214b7899fb4..e98c302bf9af1c4863dd50cbf52390fd359d0a28 100644 (file)
@@ -96,10 +96,14 @@ public class AltosGraphUI extends JFrame
         public ArrayList<AltosGraph> graphs() {
             ArrayList<AltosGraph> graphs = new ArrayList<AltosGraph>();
     
-            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<AltosDataPoint> 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<AltosDataPoint> data, int which) 
+    public AltosGraphUI(AltosDataPointReader data, int which)
     {
         super("Altos Graph");
         init(data, which);
     }
 
-    private void init(Iterable<AltosDataPoint> data, int which) {
+    private void init(AltosDataPointReader data, int which) {
         AltosGraph graph = createGraph(data, which);
 
         JFreeChart chart = graph.createChart();
index 46e96b95de6e660a4a4350cce140660cc5615ba7..200fffe5db993e1a7336fe2add88ff412dcb4482 100644 (file)
@@ -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();
        }
 }
index a7df92d11eb830dc4405b6e42fa56571a89f53ee..45843b92973f8a500bf2d69a0bde3ed11a421c80 100644 (file)
@@ -31,4 +31,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 public abstract class AltosRecordIterable implements Iterable<AltosRecord> {
        public abstract Iterator<AltosRecord> 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; };
 }
index 14b5f27fc2c39e4ef142b82bdc09d604cc5fb7ca..44e5ad8f8d9c2fe9977cd0550abf8ab67c8d9dc0 100644 (file)
@@ -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());