+ public void set_ground_pressure (double pressure) {
+ ground_pressure.set_measured(pressure, time);
+ }
+
+ class AltosAltitude extends AltosCValue {
+
+ private void set_speed(AltosValue v) {
+ if (!acceleration.is_measured() || !ascent)
+ speed.set_derivative(this);
+ }
+
+ void set_computed(double a, double time) {
+ super.set_computed(a,time);
+ set_speed(computed);
+ set |= set_position;
+ }
+
+ void set_measured(double a, double time) {
+ super.set_measured(a,time);
+ set_speed(measured);
+ set |= set_position;
+ }
+ }
+
+ private AltosAltitude altitude;
+
+ class AltosGpsAltitude extends AltosValue {
+
+ private void set_gps_height() {
+ double a = value();
+ double g = gps_ground_altitude.value();
+
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ gps_height = a - g;
+ else
+ gps_height = AltosLib.MISSING;
+ }
+
+ void set(double a, double t) {
+ super.set(a, t);
+ set_gps_height();
+ }
+ }
+
+ private AltosGpsAltitude gps_altitude;
+
+ private AltosValue gps_ground_speed;
+ private AltosValue gps_ascent_rate;
+ private AltosValue gps_course;
+ private AltosValue gps_speed;
+
+ public double altitude() {
+ double a = altitude.value();
+ if (a != AltosLib.MISSING)
+ return a;
+ return gps_altitude.value();
+ }
+
+ public double max_altitude() {
+ double a = altitude.max();
+ if (a != AltosLib.MISSING)
+ return a;
+ return gps_altitude.max();
+ }
+
+ public void set_altitude(double new_altitude) {
+ altitude.set_measured(new_altitude, time);
+ }
+
+ public double gps_altitude() {
+ return gps_altitude.value();
+ }
+
+ public double max_gps_altitude() {
+ return gps_altitude.max();
+ }
+
+ public void set_gps_altitude(double new_gps_altitude) {
+ gps_altitude.set(new_gps_altitude, time);
+ }
+
+ public double gps_ground_speed() {
+ return gps_ground_speed.value();
+ }
+
+ public double max_gps_ground_speed() {
+ return gps_ground_speed.max();
+ }
+
+ public double gps_ascent_rate() {
+ return gps_ascent_rate.value();
+ }
+
+ public double max_gps_ascent_rate() {
+ return gps_ascent_rate.max();
+ }
+
+ public double gps_course() {
+ return gps_course.value();
+ }
+
+ public double gps_speed() {
+ return gps_speed.value();
+ }
+
+ public double max_gps_speed() {
+ return gps_speed.max();
+ }
+
+ class AltosPressure extends AltosValue {
+ void set(double p, double time) {
+ super.set(p, time);
+ if (state == AltosLib.ao_flight_pad)
+ ground_pressure.set_filtered(p, time);
+ double a = pressure_to_altitude(p);
+ altitude.set_computed(a, time);
+ }
+ }
+
+ private AltosPressure pressure;
+
+ public double pressure() {
+ return pressure.value();
+ }
+
+ public void set_pressure(double p) {
+ pressure.set(p, time);
+ }
+
+ public double baro_height() {
+ double a = altitude();
+ double g = ground_altitude();
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ return a - g;
+ return AltosLib.MISSING;
+ }
+
+ public double height() {
+ double k = kalman_height.value();
+ if (k != AltosLib.MISSING)
+ return k;
+
+ double b = baro_height();
+ if (b != AltosLib.MISSING)
+ return b;
+
+ return gps_height();
+ }
+
+ public double max_height() {
+ double k = kalman_height.max();
+ if (k != AltosLib.MISSING)
+ return k;
+
+ double a = altitude.max();
+ double g = ground_altitude();
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ return a - g;
+ return max_gps_height();
+ }
+
+ public double gps_height() {
+ double a = gps_altitude();
+ double g = gps_ground_altitude();
+
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ return a - g;
+ return AltosLib.MISSING;
+ }
+
+ public double max_gps_height() {
+ double a = gps_altitude.max();
+ double g = gps_ground_altitude();
+
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ return a - g;
+ return AltosLib.MISSING;
+ }
+
+ class AltosSpeed extends AltosCValue {
+
+ boolean can_max() {
+ return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
+ }
+
+ void set_accel() {
+ acceleration.set_derivative(this);
+ }
+
+ void set_derivative(AltosCValue in) {
+ super.set_derivative(in);
+ set_accel();
+ }
+
+ void set_computed(double new_value, double time) {
+ super.set_computed(new_value, time);
+ set_accel();
+ }
+
+ void set_measured(double new_value, double time) {
+ super.set_measured(new_value, time);
+ set_accel();
+ }
+ }
+
+ private AltosSpeed speed;
+
+ public double speed() {
+ double v = kalman_speed.value();
+ if (v != AltosLib.MISSING)
+ return v;
+ v = speed.value();
+ if (v != AltosLib.MISSING)
+ return v;
+ v = gps_speed();
+ if (v != AltosLib.MISSING)
+ return v;
+ return AltosLib.MISSING;
+ }
+
+ public double max_speed() {
+ double v = kalman_speed.max();
+ if (v != AltosLib.MISSING)
+ return v;
+ v = speed.max();
+ if (v != AltosLib.MISSING)
+ return v;
+ v = max_gps_speed();
+ if (v != AltosLib.MISSING)
+ return v;
+ return AltosLib.MISSING;
+ }
+
+ class AltosAccel extends AltosCValue {
+
+ boolean can_max() {
+ return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
+ }
+
+ void set_measured(double a, double time) {
+ super.set_measured(a, time);
+ if (ascent)
+ speed.set_integral(this.measured);
+ }
+ }
+
+ AltosAccel acceleration;
+
+ public double acceleration() {
+ return acceleration.value();
+ }
+
+ public double max_acceleration() {
+ return acceleration.max();
+ }
+
+ public AltosCValue orient;
+
+ public void set_orient(double new_orient) {
+ orient.set_measured(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) {
+ kalman_height.set(height, time);
+ kalman_speed.set(speed, time);
+ kalman_acceleration.set(acceleration, time);
+ }
+
+ public double battery_voltage;
+ public double pyro_voltage;