X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=micropeak%2FMicroStats.java;h=3fc05bd6cc85aa2c5c388627dfd779afdca021fb;hp=6ae8a2b28a11101e78f6b076cb2d7808558a0345;hb=c8078d352a7f54a4a97d25af080155d3f875536a;hpb=2bd6aca54fc465995d6985c8799cd0d016c9a543 diff --git a/micropeak/MicroStats.java b/micropeak/MicroStats.java index 6ae8a2b2..3fc05bd6 100644 --- a/micropeak/MicroStats.java +++ b/micropeak/MicroStats.java @@ -18,8 +18,8 @@ package org.altusmetrum.micropeak; import java.io.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_5.*; +import org.altusmetrum.altosuilib_3.*; public class MicroStats { double coast_height; @@ -39,39 +39,38 @@ 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++; } } void find_apogee() { - apogee_height = 0; + apogee_height = data.apogee_height(); + double searched_apogee = 0; apogee_time = 0; - int t = 0; - for (double height : data.heights()) { - if (height > apogee_height) { - apogee_height = height; - apogee_time = data.time(t); + /* 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 > searched_apogee) { + searched_apogee = point.height; + apogee_time = point.time; } - t++; } } @@ -79,47 +78,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; } } @@ -167,6 +150,43 @@ public class MicroStats { return descent_height() / descent_duration(); } + public static final int state_startup = -1; + public static final int state_pad = 0; + public static final int state_boost = 1; + public static final int state_coast = 2; + public static final int state_descent = 3; + public static final int state_landed = 4; + + static final String state_names[] = { + "pad", + "boost", + "coast", + "descent", + "landed" + }; + + public int state(double t) { + if (t >= landed_time) + return state_landed; + if (t >= apogee_time) + return state_descent; + if (t >= coast_time) + return state_coast; + if (t >= 0) + return state_boost; + return state_pad; + } + + public static String state_name(int state) { + if (state < 0 || state > state_landed) + return "unknown"; + return state_names[state]; + } + + public String state_name(double t) { + return state_name(state(t)); + } + public MicroStats(MicroData data) { this.data = data;