33#if USE_HARDWARE_EEPROM == 0
82AHRS_type::update_circling_state ()
84#if DISABLE_CIRCLING_STATE
93 if (circling_counter > 0)
97 if (circling_counter == 0)
104 return circling_state;
122 for (
unsigned i = 0;
i < 3; ++
i)
134 gyro_integrator({0}),
139 acceleration_nav_frame(),
140 induction_nav_frame(),
141 expected_nav_induction(),
148 compass_calibration(),
152 heading_difference_AHRS_DGNSS(0.0f),
153 cross_acc_correction(0.0f),
154 magnetic_disturbance(0.0f),
155 magnetic_control_gain(1.0f),
157 automatic_earth_field_parameters(
false),
158 magnetic_calibration_updated(
false)
160 update_magnetic_loop_gain();
162 bool fail = compass_calibration.read_from_EEPROM();
164 compass_calibration.set_default();
175#if DISABLE_SAT_COMPASS
179 update_diff_GNSS (gyro, acc, mag, GNSS_acceleration, GNSS_heading);
196 gyro[
PITCH] * Ts_div_2,
197 gyro[
YAW] * Ts_div_2);
203 acceleration_nav_frame = body2nav * acc;
204 induction_nav_frame = body2nav * mag;
213 G_load_averager.
respond( acc.abs());
214 magnetic_disturbance = (induction_nav_frame - expected_nav_induction).abs();
228 update_circling_state ();
230 expected_body_induction = body2nav.
reverse_map( expected_nav_induction);
234 else if( compass_calibration.
available())
239 body_induction_error = body_induction - expected_body_induction;
243 + antenna_DOWN_correction *
SIN (euler.
r)
244 - antenna_RIGHT_correction *
COS (euler.
r);
258 cross_acc_correction =
265#if USE_ACCELERATION_CROSS_GAIN_ALONE_WHEN_CIRCLING
278 gyro_correction = body2nav.
reverse_map(nav_correction);
279 gyro_correction *=
P_GAIN;
282 gyro_integrator += gyro_correction;
284 gyro_correction = gyro_correction + gyro_integrator *
I_GAIN;
285 gyro_correction_power =
SQR( gyro_correction[0]) +
SQR( gyro_correction[1]) +
SQR( gyro_correction[2]);
287 update_attitude (acc, gyro + gyro_correction, body_induction);
292 feed_magnetic_induction_observer (
mag_sensor);
296 handle_magnetic_calibration (
's');
307 expected_body_induction = body2nav.
reverse_map( expected_nav_induction);
311 else if( compass_calibration.
available())
316 body_induction_error = body_induction - expected_body_induction;
330 update_circling_state ();
336 cross_acc_correction =
340 switch (circling_state)
347 gyro_correction = body2nav.
reverse_map (nav_correction);
348 gyro_correction *=
P_GAIN;
349 gyro_integrator += gyro_correction;
355#if USE_ACCELERATION_CROSS_GAIN_ALONE_WHEN_CIRCLING
361 gyro_correction = body2nav.
reverse_map (nav_correction);
362 gyro_correction *=
P_GAIN;
367 gyro_correction = gyro_correction + gyro_integrator *
I_GAIN;
368 gyro_correction_power =
SQR( gyro_correction[0]) +
SQR( gyro_correction[1]) +
SQR( gyro_correction[2]);
371 update_attitude (acc, gyro + gyro_correction, body_induction);
376 feed_magnetic_induction_observer (
mag_sensor);
380 handle_magnetic_calibration(
'm');
393 else if( compass_calibration.
available())
398 expected_body_induction = body2nav.
reverse_map( expected_nav_induction);
399 body_induction_error = body_induction - expected_body_induction;
407 update_circling_state ();
409 cross_acc_correction =
419 gyro_correction = body2nav.
reverse_map (nav_correction);
420 gyro_correction *=
P_GAIN;
422 gyro_integrator += gyro_correction;
423 gyro_correction = gyro_correction + gyro_integrator *
I_GAIN;
426 update_attitude(acc, gyro + gyro_correction, body_induction);
431 if( !magnetic_calibration_updated)
437 magnetic_calibration_updated =
false;
442void AHRS_type::handle_magnetic_calibration (
char type)
453 for(
unsigned i=0;
i<3; ++
i)
457 magnetic_calibration_updated =
true;
attitude and heading reference system (interface)
float3vector nav_induction
Replacement on the PC for the nonvolatile memory of the micro-controller.
uBlox GNSS + D-GNSS interface
Tuning parameters for navigation, wind an variometer.
#define H_GAIN
Attitude controller: horizontal gain.
#define I_GAIN
Attitude controller: integral gain.
#define NAV_CORRECTION_LIMIT
limit for "low AHRS correcting variable"
#define P_GAIN
Attitude controller: proportional gain.
#define HIGH_TURN_RATE
turn rate high limit
#define CROSS_GAIN
Attitude controller: cross-product gain.
#define CIRCLE_LIMIT
10 * 1/100 s delay into / out of circling state
#define LOW_TURN_RATE
turn rate low limit
#define M_H_GAIN
Attitude controller: horizontal gain magnetic.
#define MAG_SCALE
scale factor for high-precision integer statistics
AHRS_type(float sampling_time)
void write_calibration_into_EEPROM(void)
void attitude_setup(const float3vector &acceleration, const float3vector &induction)
initial attitude setup from observables
void update_ACC_only(const float3vector &gyro, const float3vector &acc, const float3vector &mag, const float3vector &GNSS_acceleration)
rotate quaternion taking angular rate readings
void update_compass(const float3vector &gyro, const float3vector &acc, const float3vector &mag, const float3vector &GNSS_acceleration)
rotate quaternion taking angular rate readings
void update(const float3vector &gyro, const float3vector &acc, const float3vector &mag, const float3vector &GNSS_acceleration, float GNSS_heading, bool GNSS_heading_valid)
bool set_calibration_if_changed(linear_least_square_fit< sample_type, evaluation_type > mag_calibrator_right[3], linear_least_square_fit< sample_type, evaluation_type > mag_calibrator_left[3], float scale_factor)
const single_axis_calibration_t * get_calibration(void) const
float3vector calibrate(const float3vector &in)
void write_into_EEPROM(void) const
bool learn(const float3vector &observed_induction, const float3vector &expected_induction, const quaternion< float > &q, bool turning_right, float error_margin)
bool available(void) const
float3vector calibrate(const float3vector &induction, const quaternion< float > &q)
void add_value(const sample_type x, const sample_type y)
vector< datatype, size > reverse_map(const vector< datatype, size > &right) const
multiplication (matrix times vector) -> vector
datatype get_output(void) const
datatype respond(const datatype &input)
void get_rotation_matrix(matrix< datatype, 3 > &m) const
quaternion -> rotation matrix transformation
void rotate(datatype p, datatype q, datatype r)
quaternion update using rotation vector
void normalize(void)
normalize quaternion absolute value to ONE
void from_rotation_matrix(matrix< datatype, 3 > &rotm)
void normalize(void)
vector normalization
datatype abs(void) const
vector abs operator returns absolute value
vector vector_multiply(const vector &right) const
< vector cross product -> vector
induction sensor calibration and magnetic disturbance compensation
settings to allow compiling embedded software on a PC target
void report_magnetic_calibration_has_changed(magnetic_induction_report_t *p_magnetic_induction_report, char type)
float configuration(EEPROM_PARAMETER_ID id)
bool lock_EEPROM(bool lockit)
helper struct containing magnetic calibration data
collection of system tuning parameters