|
14 | 14 |
|
15 | 15 | void QuaternionMEKF::initialize(RocketSystems *args) |
16 | 16 | { |
17 | | - float Pq0 = 1e-4; |
18 | | - float Pb0 = 1e-1; |
| 17 | + float Pq0 = 1e-4; // test it |
| 18 | + float Pb0 = 1e-1; // test it |
19 | 19 | sigma_a = {accel_noise_density_x * sqrt(20.0f) * 1.0e-6 * 9.81, accel_noise_density_y * sqrt(20.0f) * 1.0e-6 * 9.81, accel_noise_density_z * sqrt(20.0f) * 1.0e-6 * 9.81}; // ug/sqrt(Hz) *sqrt(hz). values are from datasheet |
20 | 20 | sigma_g = {gyro_RMS_noise * pow(1.0f, -3.0f) * pi / 180.0f * pow(20.0f, 0.5f), gyro_RMS_noise * pow(1.0f, -3.0f) * pi / 180.0f * pow(20.0f, 0.5f), gyro_RMS_noise * pow(1.0f, -3.0f) * pi / 180.0f * pow(20.0f, 0.5f)}; |
21 | 21 | sigma_m = {mag_noise * 1.0e-4 / sqrt(3), mag_noise * 1.0e-4 / sqrt(3), mag_noise * 1.0e-4 / sqrt(3)}; // 0.4 mG -> T, it is 0.4 total so we divide by sqrt3 // 0.4 mG -> T, it is 0.4 total so we divide by sqrt3 |
@@ -148,6 +148,13 @@ void QuaternionMEKF::measurement_update(Acceleration const &accel, Magnetometer |
148 | 148 | mag(0, 0) = mag_input.mx; |
149 | 149 | mag(1, 0) = mag_input.my; |
150 | 150 | mag(2, 0) = mag_input.mz; |
| 151 | + |
| 152 | + if (acc(0) < 0 ) // Check if the norm of the accelerometer measurement is in boost |
| 153 | + { |
| 154 | + Eigen::Matrix<float, 3, 3> Rm = sigma_m.array().square().matrix().asDiagonal(); |
| 155 | + measurement_update_partial(mag, magnetometer_measurement_func(), Rm); |
| 156 | + return; |
| 157 | + } |
151 | 158 |
|
152 | 159 | Eigen::Matrix<float, 3, 1> const v1hat = accelerometer_measurement_func(); |
153 | 160 | Eigen::Matrix<float, 3, 1> const v2hat = magnetometer_measurement_func(); |
@@ -178,7 +185,7 @@ void QuaternionMEKF::measurement_update(Acceleration const &accel, Magnetometer |
178 | 185 | // x * A = b |
179 | 186 | // Which can be solved with the code below |
180 | 187 | Eigen::FullPivLU<Eigen::Matrix<float, 6, 6>> lu(s); // LU decomposition of s |
181 | | - if (lu.isInvertible()) |
| 188 | + if (lu.determinant() != 0) |
182 | 189 | { |
183 | 190 | Eigen::Matrix<float, 6, 6> const K = P * C.transpose() * lu.inverse(); // gain |
184 | 191 |
|
@@ -219,7 +226,7 @@ void QuaternionMEKF::measurement_update_partial( |
219 | 226 |
|
220 | 227 | // K = P * C.T * s^-1 |
221 | 228 | Eigen::FullPivLU<Eigen::Matrix<float, 3, 3>> lu(s); |
222 | | - if (lu.isInvertible()) |
| 229 | + if (lu.determinant() != 0) |
223 | 230 | { |
224 | 231 | Eigen::Matrix<float, 6, 3> const K = P * C.transpose() * lu.inverse(); |
225 | 232 |
|
|
0 commit comments