altos: Use factory calibration for all acceleration computations
[fw/altos] / altoslib / AltosState.java
index a01cddb774d1a5a567d10869a80ee669fe783938..08dafbb4c8ad6d12333e458638e6732abc04aede 100644 (file)
@@ -19,7 +19,7 @@
  * Track flight state from telemetry or eeprom data stream
  */
 
-package org.altusmetrum.altoslib_2;
+package org.altusmetrum.altoslib_3;
 
 public class AltosState implements Cloneable {
 
@@ -464,6 +464,20 @@ public class AltosState implements Cloneable {
                return acceleration.max();
        }
 
+       public AltosValue       orient;
+
+       public void set_orient(double new_orient) {
+               orient.set(new_orient, time);
+       }
+
+       public double orient() {
+               return orient.value();
+       }
+
+       public double max_orient() {
+               return orient.max();
+       }
+
        public AltosValue       kalman_height, kalman_speed, kalman_acceleration;
 
        public void set_kalman(double height, double speed, double acceleration) {
@@ -560,6 +574,7 @@ public class AltosState implements Cloneable {
                pressure = new AltosPressure();
                speed = new AltosSpeed();
                acceleration = new AltosAccel();
+               orient = new AltosValue();
 
                temperature = AltosLib.MISSING;
                battery_voltage = AltosLib.MISSING;
@@ -621,6 +636,7 @@ public class AltosState implements Cloneable {
                pressure.finish_update();
                speed.finish_update();
                acceleration.finish_update();
+               orient.finish_update();
 
                kalman_height.finish_update();
                kalman_speed.finish_update();
@@ -665,6 +681,7 @@ public class AltosState implements Cloneable {
                pressure.copy(old.pressure);
                speed.copy(old.speed);
                acceleration.copy(old.acceleration);
+               orient.copy(old.orient);
 
                battery_voltage = old.battery_voltage;
                pyro_voltage = old.pyro_voltage;
@@ -836,7 +853,9 @@ public class AltosState implements Cloneable {
                if (flight != AltosLib.MISSING && flight != 0) {
                        if (this.flight != AltosLib.MISSING &&
                            this.flight != flight) {
+                               int bt = boost_tick;
                                init();
+                               boost_tick = bt;
                        }
                        this.flight = flight;
                }
@@ -847,7 +866,9 @@ public class AltosState implements Cloneable {
                if (serial != AltosLib.MISSING) {
                        if (this.serial != AltosLib.MISSING &&
                            this.serial != serial) {
+                               int bt = boost_tick;
                                init();
+                               boost_tick = bt;
                        }
                        this.serial = serial;
                }
@@ -928,14 +949,8 @@ public class AltosState implements Cloneable {
        }
 
        void update_accel() {
-               double  ground = ground_accel;
-
-               if (ground == AltosLib.MISSING)
-                       ground = ground_accel_avg;
                if (accel == AltosLib.MISSING)
                        return;
-               if (ground == AltosLib.MISSING)
-                       return;
                if (accel_plus_g == AltosLib.MISSING)
                        return;
                if (accel_minus_g == AltosLib.MISSING)
@@ -943,7 +958,7 @@ public class AltosState implements Cloneable {
 
                double counts_per_g = (accel_minus_g - accel_plus_g) / 2.0;
                double counts_per_mss = counts_per_g / 9.80665;
-               acceleration.set_measured((ground - accel) / counts_per_mss, time);
+               acceleration.set_measured((accel_plus_g - accel) / counts_per_mss, time);
        }
 
        public void set_accel_g(double accel_plus_g, double accel_minus_g) {
@@ -955,10 +970,8 @@ public class AltosState implements Cloneable {
        }
 
        public void set_ground_accel(double ground_accel) {
-               if (ground_accel != AltosLib.MISSING) {
+               if (ground_accel != AltosLib.MISSING)
                        this.ground_accel = ground_accel;
-                       update_accel();
-               }
        }
 
        public void set_accel(double accel) {
@@ -1017,10 +1030,9 @@ public class AltosState implements Cloneable {
                if (tick == AltosLib.MISSING)
                        return 0.0;
 
-               if (boost_tick != AltosLib.MISSING) {
-                       return (tick - boost_tick) / 100.0;
-               }
-               return tick / 100.0;
+               if (boost_tick == AltosLib.MISSING)
+                       return tick / 100.0;
+               return (tick - boost_tick) / 100.0;
        }
 
        public boolean valid() {