X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosState.java;h=403c74be16a70eccbdbf3f9ef34d28da44e000f7;hp=ec499d5acf2110e776e2096decf83e8b088a69e8;hb=3c2f601139d36761de6a8a2210545d082ef16133;hpb=f01096c4b42f9a4720ed0414826c2a283a992545 diff --git a/altosui/AltosState.java b/altosui/AltosState.java index ec499d5a..403c74be 100644 --- a/altosui/AltosState.java +++ b/altosui/AltosState.java @@ -21,6 +21,8 @@ package altosui; +import org.altusmetrum.AltosLib.*; + public class AltosState { AltosRecord data; @@ -28,12 +30,14 @@ public class AltosState { long report_time; + double time; double time_change; int tick; int state; boolean landed; boolean ascent; /* going up? */ + boolean boost; /* under power */ double ground_altitude; double height; @@ -48,9 +52,13 @@ public class AltosState { double max_height; double max_acceleration; double max_speed; + double max_baro_speed; AltosGPS gps; + AltosIMU imu; + AltosMag mag; + double pad_lat; double pad_lon; double pad_alt; @@ -71,7 +79,6 @@ public class AltosState { int speak_tick; double speak_altitude; - void init (AltosRecord cur, AltosState prev_state) { int i; AltosRecord prev; @@ -79,7 +86,7 @@ public class AltosState { data = cur; ground_altitude = data.ground_altitude(); - height = data.filtered_altitude() - ground_altitude; + height = data.filtered_height(); report_time = System.currentTimeMillis(); @@ -104,6 +111,9 @@ public class AltosState { max_height = prev_state.max_height; max_acceleration = prev_state.max_acceleration; max_speed = prev_state.max_speed; + max_baro_speed = prev_state.max_baro_speed; + imu = prev_state.imu; + mag = prev_state.mag; /* make sure the clock is monotonic */ while (tick < prev_state.tick) @@ -114,10 +124,14 @@ public class AltosState { /* compute barometric speed */ double height_change = height - prev_state.height; - if (time_change > 0) - baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0; - else - baro_speed = prev_state.baro_speed; + if (data.speed != AltosRecord.MISSING) + baro_speed = data.speed; + else { + if (time_change > 0) + baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0; + else + baro_speed = prev_state.baro_speed; + } } else { npad = 0; ngps = 0; @@ -126,7 +140,9 @@ public class AltosState { time_change = 0; } - if (state == Altos.ao_flight_pad) { + time = tick / 100.0; + + if (cur.new_gps && (state == Altos.ao_flight_pad || state == Altos.ao_flight_idle)) { /* Track consecutive 'good' gps reports, waiting for 10 of them */ if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) @@ -158,12 +174,15 @@ public class AltosState { ascent = (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast); + boost = (Altos.ao_flight_boost == state); - /* Only look at accelerometer data on the way up */ - if (ascent && acceleration > max_acceleration) + /* Only look at accelerometer data under boost */ + if (boost && acceleration > max_acceleration) max_acceleration = acceleration; - if (ascent && speed > max_speed) + if (boost && speed > max_speed) max_speed = speed; + if (boost && baro_speed > max_baro_speed) + max_baro_speed = baro_speed; if (height > max_height) max_height = height;