+
+ public double accel_zero_along;
+ public double accel_zero_across;
+ public double accel_zero_through;
+
+ public AltosRotation rotation;
+ public AltosRotation ground_rotation;
+
+ public void set_accel_zero(double zero_along, double zero_across, double zero_through) {
+ if (zero_along != AltosLib.MISSING) {
+ accel_zero_along = zero_along;
+ accel_zero_across = zero_across;
+ accel_zero_through = zero_through;
+ }
+ }
+
+ public int pad_orientation;
+
+ public double accel_ground_along, accel_ground_across, accel_ground_through;
+
+ void update_pad_rotation() {
+ if (pad_orientation != AltosLib.MISSING && accel_ground_along != AltosLib.MISSING) {
+ rotation = new AltosRotation(AltosIMU.convert_accel(accel_ground_across - accel_zero_across),
+ AltosIMU.convert_accel(accel_ground_through - accel_zero_through),
+ AltosIMU.convert_accel(accel_ground_along - accel_zero_along),
+ pad_orientation);
+ ground_rotation = rotation;
+ orient.set_computed(rotation.tilt(), time);
+ }
+ }
+
+ public void set_accel_ground(double ground_along, double ground_across, double ground_through) {
+ accel_ground_along = ground_along;
+ accel_ground_across = ground_across;
+ accel_ground_through = ground_through;
+ update_pad_rotation();
+ }
+
+ public void set_pad_orientation(int pad_orientation) {
+ this.pad_orientation = pad_orientation;
+ update_pad_rotation();
+ }
+
+ public double gyro_zero_roll;
+ public double gyro_zero_pitch;
+ public double gyro_zero_yaw;
+
+ public void set_gyro_zero(double roll, double pitch, double yaw) {
+ if (roll != AltosLib.MISSING) {
+ gyro_zero_roll = roll;
+ gyro_zero_pitch = pitch;
+ gyro_zero_yaw = yaw;
+ }
+ }
+
+ public double last_imu_time;
+
+ private double radians(double degrees) {
+ if (degrees == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ return degrees * Math.PI / 180.0;
+ }
+
+ private void update_orient() {
+ if (last_imu_time != AltosLib.MISSING) {
+ double t = time - last_imu_time;
+
+ double pitch = radians(gyro_pitch());
+ double yaw = radians(gyro_yaw());
+ double roll = radians(gyro_roll());
+
+ if (t > 0 & pitch != AltosLib.MISSING && rotation != null) {
+ rotation.rotate(t, pitch, yaw, roll);
+ orient.set_computed(rotation.tilt(), time);
+ }
+ }
+ last_imu_time = time;
+ }
+