diff options
author | Keith Packard <keithp@keithp.com> | 2012-10-21 16:13:14 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-10-21 16:13:14 -0700 |
commit | 7894c27b2b2c3c46a7c107c8acd5977830f006cf (patch) | |
tree | f05c9d5c6bc06c1764118d1f5596a95f0016178d /altosui | |
parent | dec2e455935a71dec13b84bb886252b7f4a1a641 (diff) |
altoslib: Move computed state from AltosRecord to AltosState
Make AltosRecord simply track the raw data and have AltosState hold
all computed values, including cross-packet averages and computed speeds.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui')
-rw-r--r-- | altosui/AltosAscent.java | 2 | ||||
-rw-r--r-- | altosui/AltosCSV.java | 8 | ||||
-rw-r--r-- | altosui/AltosDataPoint.java | 5 | ||||
-rw-r--r-- | altosui/AltosDataPointReader.java | 47 | ||||
-rw-r--r-- | altosui/AltosDescent.java | 2 | ||||
-rw-r--r-- | altosui/AltosDisplayThread.java | 2 | ||||
-rw-r--r-- | altosui/AltosFlightStats.java | 10 | ||||
-rw-r--r-- | altosui/AltosGraphUI.java | 7 | ||||
-rw-r--r-- | altosui/AltosInfoTable.java | 4 | ||||
-rw-r--r-- | altosui/AltosKML.java | 2 | ||||
-rw-r--r-- | altosui/AltosLanded.java | 2 |
11 files changed, 39 insertions, 52 deletions
diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index 007c74ec..a05c4404 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -251,7 +251,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Speed extends AscentValueHold { void show (AltosState state, int crc_errors) { - double speed = state.speed; + double speed = state.accel_speed; if (!state.ascent) speed = state.baro_speed; show(AltosConvert.speed, speed); diff --git a/altosui/AltosCSV.java b/altosui/AltosCSV.java index f8cc1ed6..1c929a7c 100644 --- a/altosui/AltosCSV.java +++ b/altosui/AltosCSV.java @@ -128,10 +128,10 @@ public class AltosCSV implements AltosWriter { void write_basic(AltosRecord record) { out.printf("%8.2f,%10.2f,%8.2f,%8.2f,%8.2f,%8.2f,%5.1f,%5.2f,%5.2f,%5.2f", record.acceleration(), - record.raw_pressure(), - record.raw_altitude(), - record.raw_height(), - record.accel_speed(), + record.pressure(), + record.altitude(), + record.height(), + state.accel_speed, state.baro_speed, record.temperature(), record.battery_voltage(), diff --git a/altosui/AltosDataPoint.java b/altosui/AltosDataPoint.java index 5e077320..4956e9f3 100644 --- a/altosui/AltosDataPoint.java +++ b/altosui/AltosDataPoint.java @@ -16,11 +16,8 @@ interface AltosDataPoint { String state_name(); double acceleration(); - double pressure(); - double altitude(); double height(); - double accel_speed(); - double baro_speed(); + double speed(); double temperature(); double battery_voltage(); double drogue_voltage(); diff --git a/altosui/AltosDataPointReader.java b/altosui/AltosDataPointReader.java index 2316cf97..88df081f 100644 --- a/altosui/AltosDataPointReader.java +++ b/altosui/AltosDataPointReader.java @@ -12,7 +12,6 @@ import org.altusmetrum.AltosLib.*; class AltosDataPointReader implements Iterable<AltosDataPoint> { Iterator<AltosRecord> iter; AltosState state; - AltosRecord record; boolean has_gps; boolean has_accel; boolean has_ignite; @@ -22,7 +21,7 @@ class AltosDataPointReader implements Iterable<AltosDataPoint> { public AltosDataPointReader(AltosRecordIterable reader) { this.iter = reader.iterator(); this.state = null; - has_accel = reader.has_accel(); + has_accel = true; has_gps = reader.has_gps(); has_ignite = reader.has_ignite(); } @@ -30,35 +29,31 @@ class AltosDataPointReader implements Iterable<AltosDataPoint> { private void read_next_record() throws NoSuchElementException { - record = iter.next(); - state = new AltosState(record, state); + state = new AltosState(iter.next(), state); } private AltosDataPoint current_dp() { - assert this.record != null; + assert this.state != null; return new AltosDataPoint() { - public int version() { return record.version; } - public int serial() { return record.serial; } - public int flight() { return record.flight; } - public String callsign() { return record.callsign; } - public double time() { return record.time; } - public double rssi() { return record.rssi; } + public int version() { return state.data.version; } + public int serial() { return state.data.serial; } + public int flight() { return state.data.flight; } + public String callsign() { return state.data.callsign; } + public double time() { return state.data.time; } + public double rssi() { return state.data.rssi; } - public int state() { return record.state; } - public String state_name() { return record.state(); } + public int state() { return state.state; } + public String state_name() { return state.data.state(); } - 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 accel_speed() { return record.accel_speed(); } - public double baro_speed() { return state.baro_speed; } - public double temperature() { return record.temperature(); } - public double battery_voltage() { return record.battery_voltage(); } - public double drogue_voltage() { return record.drogue_voltage(); } - public double main_voltage() { return record.main_voltage(); } - public boolean has_accel() { return has_accel; } + public double acceleration() { return state.acceleration; } + public double height() { return state.height; } + public double speed() { return state.speed(); } + public double temperature() { return state.temperature; } + public double battery_voltage() { return state.battery; } + public double drogue_voltage() { return state.drogue_sense; } + public double main_voltage() { return state.main_sense; } + public boolean has_accel() { return true; } // return state.acceleration != AltosRecord.MISSING; } }; } @@ -68,14 +63,14 @@ class AltosDataPointReader implements Iterable<AltosDataPoint> { throw new UnsupportedOperationException(); } public boolean hasNext() { - if (record != null && record.state == Altos.ao_flight_landed) + if (state != null && state.state == Altos.ao_flight_landed) return false; return iter.hasNext(); } public AltosDataPoint next() { do { read_next_record(); - } while (record.time < -1.0 && hasNext()); + } while (state.data.time < -1.0 && hasNext()); return current_dp(); } }; diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index a71cdc10..2ea7cbfa 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -256,7 +256,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Speed extends DescentValue { void show (AltosState state, int crc_errors) { - double speed = state.speed; + double speed = state.accel_speed; if (!state.ascent) speed = state.baro_speed; show(AltosConvert.speed, speed); diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index f7a1d03e..1ba70c7e 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -197,7 +197,7 @@ public class AltosDisplayThread extends Thread { if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && state.state > Altos.ao_flight_boost) { voice.speak("max speed: %s.", - AltosConvert.speed.say_units(state.max_speed + 0.5)); + AltosConvert.speed.say_units(state.max_accel_speed + 0.5)); ret = true; } else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) && state.state >= Altos.ao_flight_drogue) { diff --git a/altosui/AltosFlightStats.java b/altosui/AltosFlightStats.java index e48cb608..1653ca57 100644 --- a/altosui/AltosFlightStats.java +++ b/altosui/AltosFlightStats.java @@ -24,7 +24,7 @@ public class AltosFlightStats { double max_height; double max_speed; double max_acceleration; - double[] state_speed = new double[Altos.ao_flight_invalid + 1]; + double[] state_accel_speed = new double[Altos.ao_flight_invalid + 1]; double[] state_baro_speed = new double[Altos.ao_flight_invalid + 1]; double[] state_accel = new double[Altos.ao_flight_invalid + 1]; int[] state_count = new int[Altos.ao_flight_invalid + 1]; @@ -123,7 +123,7 @@ public class AltosFlightStats { } } state_accel[state.state] += state.acceleration; - state_speed[state.state] += state.speed; + state_accel_speed[state.state] += state.accel_speed; state_baro_speed[state.state] += state.baro_speed; state_count[state.state]++; if (state_start[state.state] == 0.0) @@ -131,8 +131,8 @@ public class AltosFlightStats { if (state_end[state.state] < state.time) state_end[state.state] = state.time; max_height = state.max_height; - if (state.max_speed != 0) - max_speed = state.max_speed; + if (state.max_accel_speed != 0) + max_speed = state.max_accel_speed; else max_speed = state.max_baro_speed; max_acceleration = state.max_acceleration; @@ -140,7 +140,7 @@ public class AltosFlightStats { } for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) { if (state_count[s] > 0) { - state_speed[s] /= state_count[s]; + state_accel_speed[s] /= state_count[s]; state_baro_speed[s] /= state_count[s]; state_accel[s] /= state_count[s]; } diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java index cb8e3d20..f59f70ba 100644 --- a/altosui/AltosGraphUI.java +++ b/altosui/AltosGraphUI.java @@ -40,12 +40,7 @@ public class AltosGraphUI extends AltosFrame AltosGraphTime.Element speed = new AltosGraphTime.TimeSeries(String.format("Speed (%s)", AltosConvert.speed.show_units()), "Vertical Speed", green) { public void gotTimeData(double time, AltosDataPoint d) { - double speed; - if (d.state() < Altos.ao_flight_drogue && d.has_accel()) { - speed = d.accel_speed(); - } else { - speed = d.baro_speed(); - } + double speed = d.speed(); if (speed != AltosRecord.MISSING) series.add(time, AltosConvert.speed.value(speed)); } diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java index 86e02ab1..11d1b0c1 100644 --- a/altosui/AltosInfoTable.java +++ b/altosui/AltosInfoTable.java @@ -114,8 +114,8 @@ public class AltosInfoTable extends JTable { info_add_row(0, "Max height", "%6.0f m", state.max_height); info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration); - info_add_row(0, "Speed", "%8.1f m/s", state.ascent ? state.speed : state.baro_speed); - info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed); + info_add_row(0, "Speed", "%8.1f m/s", state.speed()); + info_add_row(0, "Max Speed", "%8.1f m/s", state.max_accel_speed); info_add_row(0, "Temperature", "%9.2f °C", state.temperature); info_add_row(0, "Battery", "%9.2f V", state.battery); if (state.drogue_sense != AltosRecord.MISSING) diff --git a/altosui/AltosKML.java b/altosui/AltosKML.java index 57339b19..281638bf 100644 --- a/altosui/AltosKML.java +++ b/altosui/AltosKML.java @@ -109,7 +109,7 @@ public class AltosKML implements AltosWriter { AltosGPS gps = record.gps; out.printf(kml_coord_fmt, gps.lon, gps.lat, - record.filtered_altitude(), (double) gps.alt, + record.altitude(), (double) gps.alt, record.time, gps.nsat); } diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 57c2d476..0111a08a 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -173,7 +173,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Speed extends LandedValue { void show (AltosState state, int crc_errors) { - show(AltosConvert.speed, state.max_speed); + show(AltosConvert.speed, state.max_speed()); } public Speed (GridBagLayout layout, int y) { super (layout, y, "Maximum Speed"); |