30 #define GPS_SPEED_MIN 3 36 #define SPIN_RATE_LIMIT 20 58 if (!skip_ins_update) {
114 uint8_t healthy_count = 0;
122 delta_angle += dangle;
126 if (healthy_count > 1) {
127 delta_angle /= healthy_count;
130 _omega = delta_angle / _G_Dt;
153 if (recover_eulers && !isnan(
roll) && !isnan(
pitch) && !isnan(
yaw)) {
167 while ((initAccVec.
length() < 9.0f || initAccVec.
length() > 11) && counter++ < 20) {
174 if (initAccVec.
length() > 5.0f) {
176 pitch = atan2f(initAccVec.
x,
norm(initAccVec.
y, initAccVec.
z));
178 roll = atan2f(-initAccVec.
y, -initAccVec.
z);
251 const float renorm_val = 1.0f / a.
length();
257 if (!(renorm_val < 2.0f && renorm_val > 0.5
f)) {
259 if (!(renorm_val < 1.0e6f && renorm_val > 1.0e-6f)) {
270 result = a * renorm_val;
313 if (rb.
length() < FLT_EPSILON) {
341 if (spin_rate <
ToRad(50)) {
344 if (spin_rate >
ToRad(500)) {
347 return spin_rate/
ToRad(50);
362 if (VdotEFmag <= 4.0
f) {
363 return 0.2f*(4.5f - VdotEFmag);
433 bool new_value =
false;
473 const float yaw_error_rad =
wrap_PI(gps_course_rad -
yaw);
474 yaw_error = sinf(yaw_error_rad);
578 uint32_t last_correction_time;
597 if (delta_velocity_dt > 0) {
703 bool using_gps_corrections =
false;
707 const float v_scale =
gps_gain.get() * ra_scale;
716 using_gps_corrections =
true;
732 float best_error = 0;
741 if (using_gps_corrections) {
751 if (GA_b[i].is_inf()) {
755 error[i] = GA_b[i] % GA_e;
757 error_dirn[i] = GA_b[i] * GA_e;
758 const float error_length = error[i].
length();
759 if (besti == -1 || error_length < best_error) {
761 best_error = error_length;
764 if (error_dirn[besti] < 0.0
f) {
778 #define YAW_INDEPENDENT_DRIFT_CORRECTION 0 779 #if YAW_INDEPENDENT_DRIFT_CORRECTION 781 const float earth_error_Z = error.
z;
784 const float tilt =
norm(GA_e.
x, GA_e.
y);
787 const float theta = atan2f(GA_b[besti].y, GA_b[besti].
x);
793 error = GA_b[besti] % GA_e2;
794 error.
z = earth_error_Z;
795 #endif // YAW_INDEPENDENT_DRIFT_CORRECTION 803 error[besti].
z *= sinf(fabsf(
roll));
819 if (error[besti].is_nan() || error[besti].is_inf()) {
871 _omega_I_sum_time = 0;
902 _last_fuse = fuselageDirection;
907 float diff_length = fuselageDirectionDiff.
length();
908 if (diff_length > 0.2
f) {
915 V = velocityDiff.
length() / diff_length;
920 _last_fuse = fuselageDirection;
921 _last_vel = velocity;
923 const float theta = atan2f(velocityDiff.
y, velocityDiff.
x) - atan2f(fuselageDirectionDiff.
y, fuselageDirectionDiff.
x);
924 const float sintheta = sinf(theta);
925 const float costheta = cosf(theta);
928 wind.
x = velocitySum.
x - V * (costheta * fuselageDirectionSum.
x - sintheta * fuselageDirectionSum.
y);
929 wind.
y = velocitySum.
y - V * (sintheta * fuselageDirectionSum.
x + costheta * fuselageDirectionSum.
y);
930 wind.
z = velocitySum.
z - V * fuselageDirectionSum.
z;
942 _wind = _wind * 0.92f + wind * 0.08f;
972 float gps_delay_sec = 0;
1002 float true_airspeed = *airspeed_ret *
get_EAS2TAS();
float norm(const T first, const U second, const Params... parameters)
void to_euler(float *roll, float *pitch, float *yaw) const
bool get_soft_armed() const
void location_update(struct Location &loc, float bearing, float distance)
bool use_fast_gains(void) const
float _P_gain(float spin_rate)
void set_home(const Location &loc) override
Vector3< float > Vector3f
bool use_for_yaw(uint8_t i) const
return true if the compass should be used for yaw calculations
float get_declination() const
bool use_compass() override
void get_relative_position_D_home(float &posD) const override
float _position_offset_east
Vector2< T > mulXY(const Vector3< T > &v) const
float get_airspeed(uint8_t i) const
Matrix3f _body_dcm_matrix
void from_euler(float roll, float pitch, float yaw)
uint32_t last_fix_time_ms(uint8_t instance) const
void update(bool skip_ins_update=false) override
Vector3f _ra_sum[INS_MAX_INSTANCES]
auto wrap_180_cd(const T angle) -> decltype(wrap_180(angle, 100.f))
bool get_delta_velocity(uint8_t i, Vector3f &delta_velocity) const
void location_offset(struct Location &loc, float ofs_north, float ofs_east)
Vector3f _accel_ef_blended
bool use_accel(uint8_t instance) const
bool have_gps(void) const
void reset_attitude(const float &roll, const float &pitch, const float &yaw) override
const Location & location(uint8_t instance) const
void reset_gyro_drift() override
virtual void update_AOA_SSA(void)
uint8_t correct_centrifugal
int32_t lat
param 3 - Latitude * 10**7
int32_t ground_course_cd(uint8_t instance) const
uint32_t _last_consistent_heading
float calculate_heading(const Matrix3f &dcm_matrix) const
const Vector3f & get_accel(uint8_t i) const
const Vector3f & get_field(uint8_t i) const
Return the current field as a Vector3f in milligauss.
bool renorm(Vector3f const &a, Vector3f &result)
uint8_t get_primary_accel(void) const
bool get_delta_angle(uint8_t i, Vector3f &delta_angle) const
bool healthy() const override
bool airspeed_estimate(float *airspeed_ret) const override
uint32_t _last_failure_ms
const Vector3f & velocity(uint8_t instance) const
float wrap_PI(const T radian)
float ground_speed(uint8_t instance) const
int32_t alt
param 2 - Altitude in centimeters (meters * 100) see LOCATION_ALT_MAX_M
virtual bool get_position(struct Location &loc) const override
float yaw_error_compass()
void update_cd_values(void)
bool is_zero(const T fVal1)
void drift_correction(float deltat)
void matrix_update(float _G_Dt)
const Matrix3f & get_rotation_vehicle_body_to_autopilot_body(void) const
Receiving valid messages and 2D lock.
float _yaw_gain(void) const
GPS_Status status(uint8_t instance) const
Query GPS status.
Location_Option_Flags flags
options bitmask (1<<0 = relative altitude)
uint8_t _active_accel_instance
float get_delta_time() const
Vector3f ra_delayed(uint8_t instance, const Vector3f &ra)
Vector3< T > mul_transpose(const Vector3< T > &v) const
Vector3f _accel_ef[INS_MAX_INSTANCES]
#define AP_AHRS_YAW_P_MIN
float _position_offset_north
float constrain_float(const float amt, const float low, const float high)
float get_altitude(void) const
int32_t lng
param 4 - Longitude * 10**7
uint8_t num_sats(uint8_t instance) const
uint32_t last_update_usec(void) const
uint16_t _renorm_val_count
std::enable_if< std::is_integral< typename std::common_type< Arithmetic1, Arithmetic2 >::type >::value,bool >::type is_equal(const Arithmetic1 v_1, const Arithmetic2 v_2)
float get_delta_velocity_dt(uint8_t i) const
Receiving valid GPS messages but no lock.
void drift_correction_yaw(void)
void wait_for_sample(void)
uint32_t uptime_ms() const override
#define error(fmt, args ...)
void reset(bool recover_eulers=false) override
uint32_t _compass_last_update
uint8_t get_gyro_count(void) const
AP_InertialSensor & ins()
bool get_gyro_health(uint8_t instance) const
struct AP_AHRS::ahrs_flags _flags
bool airspeed_sensor_enabled(void) const
float get_EAS2TAS(void) const
void rotate(const Vector3< T > &g)
Receiving valid messages and 3D lock.
Vector3f _ra_delay_buffer[INS_MAX_INSTANCES]
#define INS_MAX_INSTANCES
Vector3< T > colx(void) const
uint32_t _last_startup_ms
uint32_t _gps_last_update
uint8_t get_accel_count(void) const
bool get_lag(uint8_t instance, float &lag_sec) const
bool get_accel_health(uint8_t instance) const