use lin_alg::f32::{Quaternion, Vec3};
use num_traits::Float;
use crate::{ppks, ppks::PositVelEarthUnits, Fix, UP};
pub fn from_gyro(accel_data: Vec3, att_gyro: Quaternion, acc_len_at_rest: f32) -> Vec3 {
let grav_axis_from_att_gyro = att_gyro.rotate_vec(UP);
let lin_acc_estimate = accel_data - (grav_axis_from_att_gyro * acc_len_at_rest);
static mut I: u32 = 0;
unsafe { I += 1 };
if unsafe { I } % 1000 == 0 {
let a = grav_axis_from_att_gyro * acc_len_at_rest;
}
lin_acc_estimate
}
pub(crate) fn from_gnss(fix: &Fix, fix_prev: &Fix, attitude: Quaternion) -> Vec3 {
let d_v_earth =
ppks::ned_vel_to_xyz(fix.ned_velocity) - ppks::ned_vel_to_xyz(fix_prev.ned_velocity);
let d_v = attitude.inverse().rotate_vec(d_v_earth);
let d_t = fix.timestamp_s - fix_prev.timestamp_s;
const EPS: f32 = 0.000001;
if d_t.abs() < EPS {
return Vec3::new_zero();
}
d_v / d_t
}
pub(crate) fn from_ground_track(posits_recent: &[PositVelEarthUnits; 5], interval_s: f32) -> Vec3 {
let mut posits_m = [Vec3::new_zero(); 5];
for (i, posit) in posits_recent.iter().enumerate() {
posits_m[i] = Vec3 {
x: posit.lon_e8 as f32 / crate::DEG_SCALE_1E8,
y: posit.lat_e8 as f32 / crate::DEG_SCALE_1E8,
z: posit.elevation_msl,
}
}
let mut total = Vec3::new_zero();
for p in &posits_m {
total += *p;
}
let mean = total / posits_m.len() as f32;
let turn_radius = 1.; let speed = 1.;
let acc_direction = Vec3::new_zero();
acc_direction * speed * 2. * turn_radius
}