From 2bd6aca54fc465995d6985c8799cd0d016c9a543 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 31 Dec 2012 14:17:26 -0800 Subject: micropeak: Add flight stats pane Shows graph or stats in alternate panes Signed-off-by: Keith Packard --- micropeak/MicroStats.java | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 micropeak/MicroStats.java (limited to 'micropeak/MicroStats.java') diff --git a/micropeak/MicroStats.java b/micropeak/MicroStats.java new file mode 100644 index 00000000..6ae8a2b2 --- /dev/null +++ b/micropeak/MicroStats.java @@ -0,0 +1,184 @@ +/* + * Copyright © 2011 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.micropeak; + +import java.io.*; +import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; + +public class MicroStats { + double coast_height; + double coast_time; + + double apogee_height; + double apogee_time; + + double landed_height; + double landed_time; + + double max_speed; + double max_accel; + + MicroData data; + + void find_landing() { + landed_height = 0; + + int t = 0; + for (double height : data.heights()) { + landed_height = height; + t++; + } + landed_time = data.time(t); + + t = 0; + boolean above = false; + for (double height : data.heights()) { + if (height > landed_height + 10) { + above = true; + } else { + if (above && height < landed_height + 2) { + above = false; + landed_time = data.time(t); + } + } + t++; + } + } + + void find_apogee() { + apogee_height = 0; + apogee_time = 0; + + int t = 0; + for (double height : data.heights()) { + if (height > apogee_height) { + apogee_height = height; + apogee_time = data.time(t); + } + t++; + } + } + + void find_coast() { + coast_height = 0; + coast_time = 0; + + int t = 0; + for (double accel : data.accels()) { + if (accel < -9.8) + break; + t++; + } + coast_time = data.time(t); + + int coast_t = t; + t = 0; + for (double height : data.heights()) { + if (t >= coast_t) { + coast_height = height; + break; + } + t++; + } + } + + void find_max_speed() { + max_speed = 0; + int t = 0; + for (double speed : data.speeds()) { + if (data.time(t) > apogee_time) + break; + if (speed > max_speed) + max_speed = speed; + t++; + } + } + + void find_max_accel() { + max_accel = 0; + + int t = 0; + for (double accel : data.accels()) { + if (data.time(t) > apogee_time) + break; + if (accel > max_accel) + max_accel = accel; + t++; + } + } + + double boost_duration() { + return coast_time; + } + + double boost_height() { + return coast_height; + } + + double boost_speed() { + return coast_height / coast_time; + } + + double boost_accel() { + return boost_speed() / boost_duration(); + } + + double coast_duration() { + return apogee_time - coast_time; + } + + double coast_height() { + return apogee_height - coast_height; + } + + double coast_speed() { + return coast_height() / coast_duration(); + } + + double coast_accel() { + return coast_speed() / coast_duration(); + } + + double descent_duration() { + return landed_time - apogee_time; + } + + double descent_height() { + return apogee_height - landed_height; + } + + double descent_speed() { + return descent_height() / descent_duration(); + } + + public MicroStats(MicroData data) { + + this.data = data; + + find_coast(); + find_apogee(); + find_landing(); + find_max_speed(); + find_max_accel(); + } + + public MicroStats() { + this(new MicroData()); + } +} -- cgit v1.2.3 From 93d640de65a1ecedfef89c96521c21632f96f372 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 2 Jan 2013 11:22:11 -0800 Subject: micropoint: Add MicroDataPoint This holds height/speed/accel data all in one place Signed-off-by: Keith Packard --- micropeak/Makefile.am | 1 + micropeak/MicroData.java | 77 +++++++------------------------------------ micropeak/MicroDataPoint.java | 39 ++++++++++++++++++++++ micropeak/MicroGraph.java | 9 +++-- micropeak/MicroStats.java | 68 +++++++++++++------------------------- 5 files changed, 78 insertions(+), 116 deletions(-) create mode 100644 micropeak/MicroDataPoint.java (limited to 'micropeak/MicroStats.java') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 2dd9c69c..26431bd5 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -10,6 +10,7 @@ micropeakdir=$(datadir)/java micropeak_JAVA= \ MicroPeak.java \ MicroData.java \ + MicroDataPoint.java \ MicroDownload.java \ MicroFrame.java \ MicroGraph.java \ diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index 8ccd5fd8..2afd3cd7 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -22,7 +22,7 @@ import java.io.*; import java.util.*; import org.altusmetrum.AltosLib.*; -abstract class MicroIterator implements Iterator { +class MicroIterator implements Iterator { int i; MicroData data; @@ -30,6 +30,10 @@ abstract class MicroIterator implements Iterator { return i < data.pressures.length; } + public MicroDataPoint next() { + return new MicroDataPoint(data, i++); + } + public MicroIterator (MicroData data) { this.data = data; i = 0; @@ -39,66 +43,15 @@ abstract class MicroIterator implements Iterator { } } -class MicroHeightIterator extends MicroIterator { - public Double next() { - return data.height(i++); - } - - public MicroHeightIterator(MicroData data) { - super(data); - } -} - -class MicroHeightIterable implements Iterable { - MicroData data; - - public Iterator iterator() { - return new MicroHeightIterator(data); - } - - public MicroHeightIterable(MicroData data) { - this.data = data; - } -} - -class MicroSpeedIterator extends MicroIterator { - public Double next() { - return data.speed(i++); - } - public MicroSpeedIterator(MicroData data) { - super(data); - } -} - -class MicroSpeedIterable implements Iterable { - MicroData data; - - public Iterator iterator() { - return new MicroSpeedIterator(data); - } - - public MicroSpeedIterable(MicroData data) { - this.data = data; - } -} +class MicroIterable implements Iterable { -class MicroAccelIterator extends MicroIterator { - public Double next() { - return data.acceleration(i++); - } - public MicroAccelIterator(MicroData data) { - super(data); - } -} - -class MicroAccelIterable implements Iterable { MicroData data; - public Iterator iterator() { - return new MicroAccelIterator(data); + public Iterator iterator() { + return new MicroIterator(data); } - public MicroAccelIterable(MicroData data) { + public MicroIterable(MicroData data) { this.data = data; } } @@ -225,16 +178,8 @@ public class MicroData { return AltosConvert.pressure_to_altitude(pressures[i]); } - public Iterable heights() { - return new MicroHeightIterable(this); - } - - public Iterable speeds() { - return new MicroSpeedIterable(this); - } - - public Iterable accels() { - return new MicroAccelIterable(this); + public Iterable points() { + return new MicroIterable(this); } int fact(int n) { diff --git a/micropeak/MicroDataPoint.java b/micropeak/MicroDataPoint.java new file mode 100644 index 00000000..3fd1e641 --- /dev/null +++ b/micropeak/MicroDataPoint.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2012 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.micropeak; + +public class MicroDataPoint { + public double time; + public double height; + public double speed; + public double accel; + + public MicroDataPoint (double height, double speed, double accel, double time) { + this.height = height; + this.speed = speed; + this.accel = accel; + this.time = time; + } + + public MicroDataPoint(MicroData data, int i) { + this(data.height(i), + data.speed(i), + data.acceleration(i), + data.time(i)); + } +} \ No newline at end of file diff --git a/micropeak/MicroGraph.java b/micropeak/MicroGraph.java index c5580634..8330a67b 100644 --- a/micropeak/MicroGraph.java +++ b/micropeak/MicroGraph.java @@ -106,11 +106,10 @@ public class MicroGraph implements AltosUnitsListener { heightSeries.clear(); speedSeries.clear(); accelSeries.clear(); - for (int i = 0; i < data.pressures.length; i++) { - double x = data.time(i); - heightSeries.add(x, AltosConvert.height.value(data.height(i))); - speedSeries.add(x, AltosConvert.speed.value(data.speed(i))); - accelSeries.add(x, AltosConvert.accel.value(data.acceleration(i))); + for (MicroDataPoint point : data.points()) { + heightSeries.add(point.time, AltosConvert.height.value(point.height)); + speedSeries.add(point.time, AltosConvert.speed.value(point.speed)); + accelSeries.add(point.time, AltosConvert.accel.value(point.accel)); } } diff --git a/micropeak/MicroStats.java b/micropeak/MicroStats.java index 6ae8a2b2..056fac7d 100644 --- a/micropeak/MicroStats.java +++ b/micropeak/MicroStats.java @@ -39,25 +39,21 @@ public class MicroStats { void find_landing() { landed_height = 0; - int t = 0; - for (double height : data.heights()) { - landed_height = height; - t++; + for (MicroDataPoint point : data.points()) { + landed_height = point.height; + landed_time = point.time; } - landed_time = data.time(t); - t = 0; boolean above = false; - for (double height : data.heights()) { - if (height > landed_height + 10) { + for (MicroDataPoint point : data.points()) { + if (point.height > landed_height + 10) { above = true; } else { - if (above && height < landed_height + 2) { + if (above && point.height < landed_height + 2) { above = false; - landed_time = data.time(t); + landed_time = point.time; } } - t++; } } @@ -65,13 +61,11 @@ public class MicroStats { apogee_height = 0; apogee_time = 0; - int t = 0; - for (double height : data.heights()) { - if (height > apogee_height) { - apogee_height = height; - apogee_time = data.time(t); + for (MicroDataPoint point : data.points()) { + if (point.height > apogee_height) { + apogee_height = point.height; + apogee_time = point.time; } - t++; } } @@ -79,47 +73,31 @@ public class MicroStats { coast_height = 0; coast_time = 0; - int t = 0; - for (double accel : data.accels()) { - if (accel < -9.8) + for (MicroDataPoint point : data.points()) { + if (point.accel < -9.8) break; - t++; - } - coast_time = data.time(t); - - int coast_t = t; - t = 0; - for (double height : data.heights()) { - if (t >= coast_t) { - coast_height = height; - break; - } - t++; + coast_time = point.time; + coast_height = point.height; } } void find_max_speed() { max_speed = 0; - int t = 0; - for (double speed : data.speeds()) { - if (data.time(t) > apogee_time) + for (MicroDataPoint point : data.points()) { + if (point.time > apogee_time) break; - if (speed > max_speed) - max_speed = speed; - t++; + if (point.speed > max_speed) + max_speed = point.speed; } } void find_max_accel() { max_accel = 0; - - int t = 0; - for (double accel : data.accels()) { - if (data.time(t) > apogee_time) + for (MicroDataPoint point : data.points()) { + if (point.time > apogee_time) break; - if (accel > max_accel) - max_accel = accel; - t++; + if (point.accel > max_accel) + max_accel = point.accel; } } -- cgit v1.2.3 From 505ef49a041740fe7cbb5c537b68d22e5fb6c0be Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 10 Jan 2013 21:37:18 -0800 Subject: micropeak: Report recorded apogee instead of searching flight data This makes sure we report the true apogee value instead of looking for the maximum height value in the flight data, in case the flight recording ended before the apogee was reached. Signed-off-by: Keith Packard --- micropeak/MicroData.java | 12 ++++++++++++ micropeak/MicroStats.java | 11 ++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'micropeak/MicroStats.java') diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index f1204e11..71919ddb 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -229,6 +229,18 @@ public class MicroData { return altitude(i) - ground_altitude; } + public double apogee_pressure() { + return min_pressure; + } + + public double apogee_altitude() { + return AltosConvert.pressure_to_altitude(apogee_pressure()); + } + + public double apogee_height() { + return apogee_altitude() - ground_altitude; + } + static final int speed_avg = 3; static final int accel_avg = 5; diff --git a/micropeak/MicroStats.java b/micropeak/MicroStats.java index 056fac7d..90e9dd1f 100644 --- a/micropeak/MicroStats.java +++ b/micropeak/MicroStats.java @@ -58,12 +58,17 @@ public class MicroStats { } void find_apogee() { - apogee_height = 0; + apogee_height = data.apogee_height(); + double searched_apogee = 0; apogee_time = 0; + /* This just finds the apogee time -- we've recorded the + * peak altitude separately in eeprom, and that could + * have occurred after the eeprom was full. + */ for (MicroDataPoint point : data.points()) { - if (point.height > apogee_height) { - apogee_height = point.height; + if (point.height > searched_apogee) { + searched_apogee = point.height; apogee_time = point.time; } } -- cgit v1.2.3