+ if (altitude_series == null)
+ altitude_series = add_series(altitude_name, AltosConvert.height);
+
+ if (cal_data().ground_pressure == AltosLib.MISSING)
+ cal_data().set_ground_pressure(pa);
+
+ double altitude = AltosConvert.pressure_to_altitude(pa);
+ altitude_series.add(time(), altitude);
+ }
+
+ private void compute_height() {
+ double ground_altitude = cal_data().ground_altitude;
+ if (height_series == null && ground_altitude != AltosLib.MISSING && altitude_series != null) {
+ height_series = add_series(height_name, AltosConvert.height);
+ for (AltosTimeValue alt : altitude_series)
+ height_series.add(alt.time, alt.value - ground_altitude);
+ }
+
+ if (gps_height == null && cal_data().gps_pad != null && cal_data().gps_pad.alt != AltosLib.MISSING && gps_altitude != null) {
+ double gps_ground_altitude = cal_data().gps_pad.alt;
+ gps_height = add_series(gps_height_name, AltosConvert.height);
+ for (AltosTimeValue gps_alt : gps_altitude)
+ gps_height.add(gps_alt.time, gps_alt.value - gps_ground_altitude);
+ }
+ }
+
+ public AltosTimeSeries speed_series;
+
+ public static final String speed_name = "Speed";
+
+ private AltosTimeSeries compute_speed() {
+ AltosTimeSeries new_speed_series = null;
+ AltosTimeSeries alt_speed_series = null;
+ AltosTimeSeries accel_speed_series = null;
+
+ if (altitude_series != null) {
+ AltosTimeSeries temp_series;
+
+ if (speed_filter_width > 0) {
+ temp_series = make_series(speed_name, AltosConvert.height);
+ altitude_series.filter(temp_series, speed_filter_width);
+ } else
+ temp_series = altitude_series;
+
+ alt_speed_series = make_series(speed_name, AltosConvert.speed);
+ temp_series.differentiate(alt_speed_series);
+ }
+ if (accel_series != null && !accel_computed) {
+
+ if (orient_series != null) {
+ vert_accel_series = add_series(vert_accel_name, AltosConvert.accel);
+
+ for (AltosTimeValue a : accel_series) {
+ double orient = orient_series.value(a.time);
+ double a_abs = a.value + AltosConvert.gravity;
+ double v_a = a_abs * Math.cos(AltosConvert.degrees_to_radians(orient)) - AltosConvert.gravity;
+
+ vert_accel_series.add(a.time, v_a);
+ }
+ }
+
+ AltosTimeSeries temp_series = make_series(speed_name, AltosConvert.speed);
+
+ if (vert_accel_series != null)
+ vert_accel_series.integrate(temp_series);
+ else
+ accel_series.integrate(temp_series);
+
+ accel_speed_series = make_series(speed_name, AltosConvert.speed);
+ temp_series.filter(accel_speed_series, 0.1);
+ }
+
+ if (alt_speed_series != null && accel_speed_series != null) {
+ double apogee_time = AltosLib.MISSING;
+ if (state_series != null) {
+ for (AltosTimeValue d : state_series) {
+ if (d.value >= AltosLib.ao_flight_drogue){
+ apogee_time = d.time;
+ break;
+ }
+ }
+ }
+ if (apogee_time == AltosLib.MISSING) {
+ new_speed_series = alt_speed_series;
+ } else {
+ new_speed_series = make_series(speed_name, AltosConvert.speed);
+ for (AltosTimeValue d : accel_speed_series) {
+ if (d.time <= apogee_time)
+ new_speed_series.add(d);
+ }
+ for (AltosTimeValue d : alt_speed_series) {
+ if (d.time > apogee_time)
+ new_speed_series.add(d);
+ }
+
+ }
+ } else if (alt_speed_series != null) {
+ new_speed_series = alt_speed_series;
+ } else if (accel_speed_series != null) {
+ new_speed_series = accel_speed_series;
+ }
+ return new_speed_series;
+ }
+
+ public AltosTimeSeries orient_series;
+
+ public static final String orient_name = "Tilt Angle";
+
+ private void compute_orient() {
+
+ if (orient_series != null)
+ return;
+
+ if (accel_ground_across == AltosLib.MISSING)
+ return;
+
+ if (cal_data().pad_orientation == AltosLib.MISSING)
+ return;
+
+ if (cal_data().accel_zero_across == AltosLib.MISSING)
+ return;
+
+ AltosRotation rotation = new AltosRotation(AltosIMU.convert_accel(accel_ground_across - cal_data().accel_zero_across),
+ AltosIMU.convert_accel(accel_ground_through - cal_data().accel_zero_through),
+ AltosIMU.convert_accel(accel_ground_along - cal_data().accel_zero_along),
+ cal_data().pad_orientation);
+ double prev_time = ground_time;
+
+ orient_series = add_series(orient_name, AltosConvert.orient);
+ orient_series.add(ground_time, rotation.tilt());
+
+ for (AltosTimeValue roll_v : gyro_roll) {
+ double time = roll_v.time;
+ double dt = time - prev_time;
+
+ if (dt > 0) {
+ double roll = AltosConvert.degrees_to_radians(roll_v.value) * dt;
+ double pitch = AltosConvert.degrees_to_radians(gyro_pitch.value(time)) * dt;
+ double yaw = AltosConvert.degrees_to_radians(gyro_yaw.value(time)) * dt;
+
+ rotation.rotate(pitch, yaw, roll);
+ orient_series.add(time, rotation.tilt());
+ }
+ prev_time = time;
+ }
+ }
+
+ public AltosTimeSeries kalman_height_series, kalman_speed_series, kalman_accel_series;
+
+ public static final String kalman_height_name = "Kalman Height";
+ public static final String kalman_speed_name = "Kalman Speed";
+ public static final String kalman_accel_name = "Kalman Accel";
+
+ public void set_kalman(double height, double speed, double acceleration) {
+ if (kalman_height_series == null) {
+ kalman_height_series = add_series(kalman_height_name, AltosConvert.height);
+ kalman_speed_series = add_series(kalman_speed_name, AltosConvert.speed);
+ kalman_accel_series = add_series(kalman_accel_name, AltosConvert.accel);
+ }
+ kalman_height_series.add(time(), height);
+ kalman_speed_series.add(time(), speed);
+ kalman_accel_series.add(time(), acceleration);