altos/lisp: Fix uninitialized values in ao_lisp_make_const
[fw/altos] / altoslib / AltosState.java
index 830e95f311c19d6af0c0ef78821aa565bff55ef2..fd2684db4c0ce6b06aa9392476b294a97ceb692d 100644 (file)
@@ -3,7 +3,8 @@
  *
  * 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.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,7 +20,9 @@
  * Track flight state from telemetry or eeprom data stream
  */
 
-package org.altusmetrum.altoslib_5;
+package org.altusmetrum.altoslib_11;
+
+import java.io.*;
 
 public class AltosState implements Cloneable {
 
@@ -29,8 +32,9 @@ public class AltosState implements Cloneable {
 
        public int set;
 
+       static final double filter_len = 2.0;
        static final double ascent_filter_len = 0.5;
-       static final double descent_filter_len = 0.5;
+       static final double descent_filter_len = 5.0;
 
        /* derived data */
 
@@ -62,8 +66,10 @@ public class AltosState implements Cloneable {
                }
 
                void set_filtered(double new_value, double time) {
-                       if (prev_value != AltosLib.MISSING)
-                               new_value = (prev_value * 15.0 + new_value) / 16.0;
+                       if (prev_value != AltosLib.MISSING) {
+                               double f = 1/Math.exp((time - prev_set_time) / filter_len);
+                               new_value = f * new_value + (1-f) * prev_value;
+                       }
                        set(new_value, time);
                }
 
@@ -177,6 +183,7 @@ public class AltosState implements Cloneable {
                        prev_value = AltosLib.MISSING;
                        max_value = AltosLib.MISSING;
                }
+
        }
 
        class AltosCValue {
@@ -185,6 +192,10 @@ public class AltosState implements Cloneable {
                        boolean can_max() {
                                return c_can_max();
                        }
+
+                       AltosIValue() {
+                               super();
+                       }
                };
 
                public AltosIValue      measured;
@@ -273,13 +284,13 @@ public class AltosState implements Cloneable {
                        computed.finish_update();
                }
 
-               AltosCValue() {
+               public AltosCValue() {
                        measured = new AltosIValue();
                        computed = new AltosIValue();
                }
        }
 
-       public int      state;
+       private int     state;
        public int      flight;
        public int      serial;
        public int      altitude_32;
@@ -324,6 +335,10 @@ public class AltosState implements Cloneable {
                        pad_alt = value();
                        gps_altitude.set_gps_height();
                }
+
+               AltosGpsGroundAltitude() {
+                       super();
+               }
        }
 
        private AltosGpsGroundAltitude gps_ground_altitude;
@@ -347,6 +362,10 @@ public class AltosState implements Cloneable {
                        super.set_measured(p, time);
                        ground_altitude.set_computed(pressure_to_altitude(p), time);
                }
+
+               AltosGroundPressure () {
+                       super();
+               }
        }
 
        private AltosGroundPressure ground_pressure;
@@ -377,6 +396,10 @@ public class AltosState implements Cloneable {
                        set_speed(measured);
                        set |= set_position;
                }
+
+               AltosAltitude() {
+                       super();
+               }
        }
 
        private AltosAltitude   altitude;
@@ -397,6 +420,10 @@ public class AltosState implements Cloneable {
                        super.set(a, t);
                        set_gps_height();
                }
+
+               AltosGpsAltitude() {
+                       super();
+               }
        }
 
        private AltosGpsAltitude        gps_altitude;
@@ -472,6 +499,10 @@ public class AltosState implements Cloneable {
                        double a = pressure_to_altitude(p);
                        altitude.set_computed(a, time);
                }
+
+               AltosPressure() {
+                       super();
+               }
        }
 
        private AltosPressure   pressure;
@@ -558,6 +589,10 @@ public class AltosState implements Cloneable {
                        super.set_measured(new_value, time);
                        set_accel();
                }
+
+               AltosSpeed() {
+                       super();
+               }
        }
 
        private AltosSpeed speed;
@@ -599,6 +634,10 @@ public class AltosState implements Cloneable {
                        if (ascent)
                                speed.set_integral(this.measured);
                }
+
+               AltosAccel() {
+                       super();
+               }
        }
 
        AltosAccel acceleration;
@@ -679,6 +718,7 @@ public class AltosState implements Cloneable {
        public double   ground_accel_avg;
 
        public int      log_format;
+       public int      log_space;
        public String   product;
 
        public AltosMs5607      baro;
@@ -796,6 +836,7 @@ public class AltosState implements Cloneable {
                ground_accel_avg = AltosLib.MISSING;
 
                log_format = AltosLib.MISSING;
+               log_space = AltosLib.MISSING;
                product = null;
                serial = AltosLib.MISSING;
                receiver_serial = AltosLib.MISSING;
@@ -955,6 +996,7 @@ public class AltosState implements Cloneable {
                ground_accel_avg = old.ground_accel_avg;
 
                log_format = old.log_format;
+               log_space = old.log_space;
                product = old.product;
                serial = old.serial;
                receiver_serial = old.receiver_serial;
@@ -1038,6 +1080,10 @@ public class AltosState implements Cloneable {
                return AltosLib.state_name(state);
        }
 
+       public void set_product(String product) {
+               this.product = product;
+       }
+
        public void set_state(int state) {
                if (state != AltosLib.ao_flight_invalid) {
                        this.state = state;
@@ -1047,6 +1093,10 @@ public class AltosState implements Cloneable {
                }
        }
 
+       public int state() {
+               return state;
+       }
+
        public void set_device_type(int device_type) {
                this.device_type = device_type;
                switch (device_type) {
@@ -1065,6 +1115,10 @@ public class AltosState implements Cloneable {
                }
        }
 
+       public void set_log_space(int log_space) {
+               this.log_space = log_space;
+       }
+
        public void set_flight_params(int apogee_delay, int main_deploy) {
                this.apogee_delay = apogee_delay;
                this.main_deploy = main_deploy;
@@ -1349,11 +1403,6 @@ public class AltosState implements Cloneable {
                }
        }
 
-       public void make_companion (int nchannels) {
-               if (companion == null)
-                       companion = new AltosCompanion(nchannels);
-       }
-
        public void set_companion(AltosCompanion companion) {
                this.companion = companion;
        }
@@ -1475,6 +1524,31 @@ public class AltosState implements Cloneable {
        public AltosState clone() {
                AltosState s = new AltosState();
                s.copy(this);
+
+               /* Code to test state save/restore. Enable only for that purpose
+                */
+               if (false) {
+                       AltosJson       json = new AltosJson(this);
+                       String          onetrip = json.toPrettyString();
+                       AltosJson       back = AltosJson.fromString(onetrip);
+                       AltosState      tripstate = (AltosState) back.make(this.getClass());
+                       AltosJson       tripjson = new AltosJson(tripstate);
+                       String          twotrip = tripjson.toPrettyString();
+
+                       if (!onetrip.equals(twotrip)) {
+                               try {
+                                       FileWriter one_file = new FileWriter("one.json", true);
+                                       one_file.write(onetrip);
+                                       one_file.flush();
+                                       FileWriter two_file = new FileWriter("two.json", true);
+                                       two_file.write(twotrip);
+                                       two_file.flush();
+                               } catch (Exception e) {
+                               }
+                               System.out.printf("json error\n");
+                               System.exit(1);
+                       }
+               }
                return s;
        }