diff --git a/src/modules/sih/sih.cpp b/src/modules/sih/sih.cpp index ff4f9292f0..5686182dca 100644 --- a/src/modules/sih/sih.cpp +++ b/src/modules/sih/sih.cpp @@ -125,9 +125,11 @@ void Sih::Run() _px4_gyro.update(_now, _gyro(0), _gyro(1), _gyro(2)); // magnetometer published at 50 Hz - if (_now - _mag_time >= 20_ms) { + if (_now - _mag_time >= 20_ms + && fabs(_mag_offset_x) < 10000 + && fabs(_mag_offset_y) < 10000 + && fabs(_mag_offset_z) < 10000) { _mag_time = _now; - _px4_mag.update(_now, _mag(0), _mag(1), _mag(2)); } @@ -186,6 +188,9 @@ void Sih::parameters_updated() _gps_used = _sih_gps_used.get(); _baro_offset_m = _sih_baro_offset.get(); + _mag_offset_x = _sih_mag_offset_x.get(); + _mag_offset_y = _sih_mag_offset_y.get(); + _mag_offset_z = _sih_mag_offset_z.get(); } // initialization of the variables for the simulator @@ -301,6 +306,9 @@ void Sih::reconstruct_sensors_signals() _acc = _C_IB.transpose() * (_v_I_dot - Vector3f(0.0f, 0.0f, CONSTANTS_ONE_G)) + noiseGauss3f(0.5f, 1.7f, 1.4f); _gyro = _w_B + noiseGauss3f(0.14f, 0.07f, 0.03f); _mag = _C_IB.transpose() * _mu_I + noiseGauss3f(0.02f, 0.02f, 0.03f); + _mag(0) += _mag_offset_x; + _mag(1) += _mag_offset_y; + _mag(2) += _mag_offset_z; // barometer float altitude = (_H0 - _p_I(2)) + _baro_offset_m + generate_wgn() * 0.14f; // altitude with noise diff --git a/src/modules/sih/sih.hpp b/src/modules/sih/sih.hpp index 48484f38df..4f877669a3 100644 --- a/src/modules/sih/sih.hpp +++ b/src/modules/sih/sih.hpp @@ -176,7 +176,7 @@ private: matrix::Vector3f _mu_I; // NED magnetic field in inertial frame [G] int _gps_used; - float _baro_offset_m; + float _baro_offset_m, _mag_offset_x, _mag_offset_y, _mag_offset_z; // parameters defined in sih_params.c DEFINE_PARAMETERS( @@ -202,6 +202,9 @@ private: (ParamFloat) _sih_mu_y, (ParamFloat) _sih_mu_z, (ParamInt) _sih_gps_used, - (ParamFloat) _sih_baro_offset + (ParamFloat) _sih_baro_offset, + (ParamFloat) _sih_mag_offset_x, + (ParamFloat) _sih_mag_offset_y, + (ParamFloat) _sih_mag_offset_z ) }; diff --git a/src/modules/sih/sih_params.c b/src/modules/sih/sih_params.c index 517e52cf46..a0aefd5637 100644 --- a/src/modules/sih/sih_params.c +++ b/src/modules/sih/sih_params.c @@ -362,3 +362,32 @@ PARAM_DEFINE_INT32(SIH_GPS_USED, 10); * @group Simulation In Hardware */ PARAM_DEFINE_FLOAT(SIH_BARO_OFFSET, 0.0f); + +/** + * magnetometer X offset in Gauss + * + * Absolute value superior to 10000 will disable magnetometer + * + * @unit gauss + * @group Simulation In Hardware + */ +PARAM_DEFINE_FLOAT(SIH_MAG_OFFSET_X, 0.0f); + +/** + * magnetometer Y offset in Gauss + * + * Absolute value superior to 10000 will disable magnetometer + * + * @unit gauss + * @group Simulation In Hardware + */ +PARAM_DEFINE_FLOAT(SIH_MAG_OFFSET_Y, 0.0f); +/** + * magnetometer Z offset in Gauss + * + * Absolute value superior to 10000 will disable magnetometer + * + * @unit gauss + * @group Simulation In Hardware + */ +PARAM_DEFINE_FLOAT(SIH_MAG_OFFSET_Z, 0.0f);