Skip to content

Commit 0a3fdcc

Browse files
committed
biascorrectedDeltaRij tests
1 parent 1ac286f commit 0a3fdcc

File tree

4 files changed

+71
-61
lines changed

4 files changed

+71
-61
lines changed

gtsam/navigation/PreintegratedRotation.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ Rot3 PreintegratedRotation::IncrementalRotation::operator()(
9595
}
9696

9797
void PreintegratedRotation::integrateGyroMeasurement(
98-
const Vector3& measuredOmega, const Vector3& bias, double deltaT,
98+
const Vector3& measuredOmega, const Vector3& biasHat, double deltaT,
9999
OptionalJacobian<3, 3> F) {
100100
Matrix3 H_bias;
101101
IncrementalRotation f{measuredOmega, deltaT, p_->body_P_sensor};
102-
const Rot3 incrR = f(bias, H_bias);
102+
const Rot3 incrR = f(biasHat, H_bias);
103103

104104
// Update deltaTij and rotation
105105
deltaTij_ += deltaT;
@@ -112,16 +112,16 @@ void PreintegratedRotation::integrateGyroMeasurement(
112112

113113
// deprecated!
114114
void PreintegratedRotation::integrateMeasurement(
115-
const Vector3& measuredOmega, const Vector3& bias, double deltaT,
115+
const Vector3& measuredOmega, const Vector3& biasHat, double deltaT,
116116
OptionalJacobian<3, 3> optional_D_incrR_integratedOmega,
117117
OptionalJacobian<3, 3> F) {
118-
integrateGyroMeasurement(measuredOmega, bias, deltaT, F);
118+
integrateGyroMeasurement(measuredOmega, biasHat, deltaT, F);
119119

120120
// If asked, pass obsolete Jacobians as well
121121
if (optional_D_incrR_integratedOmega) {
122122
Matrix3 H_bias;
123123
IncrementalRotation f{measuredOmega, deltaT, p_->body_P_sensor};
124-
const Rot3 incrR = f(bias, H_bias);
124+
const Rot3 incrR = f(biasHat, H_bias);
125125
*optional_D_incrR_integratedOmega << H_bias / -deltaT;
126126
}
127127
}

gtsam/navigation/PreintegratedRotation.h

+36-33
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,10 @@ class GTSAM_EXPORT PreintegratedRotation {
135135

136136
/// @name Access instance variables
137137
/// @{
138-
const std::shared_ptr<Params>& params() const {
139-
return p_;
140-
}
141-
const double& deltaTij() const {
142-
return deltaTij_;
143-
}
144-
const Rot3& deltaRij() const {
145-
return deltaRij_;
146-
}
147-
const Matrix3& delRdelBiasOmega() const {
148-
return delRdelBiasOmega_;
149-
}
138+
const std::shared_ptr<Params>& params() const { return p_; }
139+
const double& deltaTij() const { return deltaTij_; }
140+
const Rot3& deltaRij() const { return deltaRij_; }
141+
const Matrix3& delRdelBiasOmega() const { return delRdelBiasOmega_; }
150142
/// @}
151143

152144
/// @name Testable
@@ -158,6 +150,35 @@ class GTSAM_EXPORT PreintegratedRotation {
158150
/// @name Main functionality
159151
/// @{
160152

153+
/**
154+
* @brief Calculate an incremental rotation given the gyro measurement and a
155+
* time interval, and update both deltaTij_ and deltaRij_.
156+
* @param measuredOmega The measured angular velocity (as given by the sensor)
157+
* @param bias The biasHat estimate
158+
* @param deltaT The time interval
159+
* @param F Jacobian of internal compose, used in AhrsFactor.
160+
*/
161+
void integrateGyroMeasurement(const Vector3& measuredOmega,
162+
const Vector3& biasHat, double deltaT,
163+
OptionalJacobian<3, 3> F = {});
164+
165+
/**
166+
* @brief Return a bias corrected version of the integrated rotation.
167+
* @param biasOmegaIncr An increment with respect to biasHat used above.
168+
* @param H Jacobian of the correction w.r.t. the bias increment.
169+
* @note The *key* functionality of this class used in optimizing the bias.
170+
*/
171+
Rot3 biascorrectedDeltaRij(const Vector3& biasOmegaIncr,
172+
OptionalJacobian<3, 3> H = {}) const;
173+
174+
/// Integrate coriolis correction in body frame rot_i
175+
Vector3 integrateCoriolis(const Rot3& rot_i) const;
176+
177+
/// @}
178+
179+
/// @name Internal, exposed for testing only
180+
/// @{
181+
161182
/**
162183
* @brief Function object for incremental rotation.
163184
* @param measuredOmega The measured angular velocity (as given by the sensor)
@@ -179,25 +200,6 @@ class GTSAM_EXPORT PreintegratedRotation {
179200
OptionalJacobian<3, 3> H_bias = {}) const;
180201
};
181202

182-
/**
183-
* @brief Calculate an incremental rotation given the gyro measurement and a
184-
* time interval, and update both deltaTij_ and deltaRij_.
185-
* @param measuredOmega The measured angular velocity (as given by the sensor)
186-
* @param bias The bias estimate
187-
* @param deltaT The time interval
188-
* @param F Jacobian of internal compose, used in AhrsFactor.
189-
*/
190-
void integrateGyroMeasurement(const Vector3& measuredOmega,
191-
const Vector3& bias, double deltaT,
192-
OptionalJacobian<3, 3> F = {});
193-
194-
/// Return a bias corrected version of the integrated rotation, with optional Jacobian
195-
Rot3 biascorrectedDeltaRij(const Vector3& biasOmegaIncr,
196-
OptionalJacobian<3, 3> H = {}) const;
197-
198-
/// Integrate coriolis correction in body frame rot_i
199-
Vector3 integrateCoriolis(const Rot3& rot_i) const;
200-
201203
/// @}
202204

203205
/// @name Deprecated API
@@ -215,9 +217,10 @@ class GTSAM_EXPORT PreintegratedRotation {
215217
return incrR;
216218
}
217219

218-
/// @deprecated: returned hard-to-understand Jacobian D_incrR_integratedOmega.
220+
/// @deprecated: use integrateGyroMeasurement from now on
221+
/// @note this returned hard-to-understand Jacobian D_incrR_integratedOmega.
219222
void GTSAM_DEPRECATED integrateMeasurement(
220-
const Vector3& measuredOmega, const Vector3& bias, double deltaT,
223+
const Vector3& measuredOmega, const Vector3& biasHat, double deltaT,
221224
OptionalJacobian<3, 3> D_incrR_integratedOmega, OptionalJacobian<3, 3> F);
222225

223226
#endif

gtsam/navigation/tests/testAHRSFactor.cpp

-23
Original file line numberDiff line numberDiff line change
@@ -301,29 +301,6 @@ TEST(AHRSFactor, FirstOrderPreIntegratedMeasurements) {
301301
// 1e-3 needs to be added only when using quaternions for rotations
302302
}
303303

304-
//******************************************************************************
305-
// TEST(AHRSFactor, PimWithBodyDisplacement) {
306-
// Vector3 bias(0, 0, 0.3);
307-
// Vector3 measuredOmega(0, 0, M_PI / 10.0 + 0.3);
308-
// double deltaT = 1.0;
309-
310-
// auto p = std::make_shared<PreintegratedAhrsMeasurements::Params>();
311-
// p->gyroscopeCovariance = kMeasuredOmegaCovariance;
312-
// p->body_P_sensor = Pose3(Rot3::Roll(M_PI_2), Point3(0, 0, 0));
313-
// PreintegratedAhrsMeasurements pim(p, Vector3::Zero());
314-
315-
// pim.integrateMeasurement(measuredOmega, deltaT);
316-
317-
// Vector3 biasOmegaIncr(0.01, 0.0, 0.0);
318-
// Matrix3 actualH;
319-
// pim.biascorrectedDeltaRij(biasOmegaIncr, actualH);
320-
321-
// // Numerical derivative using a lambda function:
322-
// auto f = [&](const Vector3& bias) { return pim.biascorrectedDeltaRij(bias); };
323-
// Matrix3 expectedH = numericalDerivative11<Rot3, Vector3>(f, bias);
324-
// EXPECT(assert_equal(expectedH, actualH));
325-
// }
326-
327304
//******************************************************************************
328305
TEST(AHRSFactor, ErrorWithBiasesAndSensorBodyDisplacement) {
329306
Vector3 bias(0, 0, 0.3);

gtsam/navigation/tests/testPreintegratedRotation.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ TEST(PreintegratedRotation, integrateGyroMeasurement) {
7171

7272
// Make sure delRdelBiasOmega is H_bias after integration.
7373
EXPECT(assert_equal<Matrix3>(H_bias, pim.delRdelBiasOmega()));
74+
75+
// Check if we make a correction to the bias, the value and Jacobian are
76+
// correct. Note that the bias is subtracted from the measurement, and the
77+
// integration time is taken into account, so we expect -deltaT*delta change.
78+
Matrix3 H;
79+
const double delta = 0.05;
80+
const Vector3 biasOmegaIncr(delta, 0, 0);
81+
Rot3 corrected = pim.biascorrectedDeltaRij(biasOmegaIncr, H);
82+
EQUALITY(Vector3(-deltaT * delta, 0, 0), expected.logmap(corrected));
83+
EXPECT(assert_equal(Rot3::Roll((omega - delta) * deltaT), corrected, 1e-9));
84+
85+
// TODO(frank): again the derivative is not the *sane* one!
86+
// auto g = [&](const Vector3& increment) {
87+
// return pim.biascorrectedDeltaRij(increment, {});
88+
// };
89+
// EXPECT(assert_equal(numericalDerivative11<Rot3, Vector3>(g, Z_3x1), H));
7490
}
7591

7692
//******************************************************************************
@@ -100,6 +116,20 @@ TEST(PreintegratedRotation, integrateGyroMeasurementWithTransform) {
100116

101117
// Make sure delRdelBiasOmega is H_bias after integration.
102118
EXPECT(assert_equal<Matrix3>(H_bias, pim.delRdelBiasOmega()));
119+
120+
// Check the bias correction in same way, but will now yield pitch change.
121+
Matrix3 H;
122+
const double delta = 0.05;
123+
const Vector3 biasOmegaIncr(delta, 0, 0);
124+
Rot3 corrected = pim.biascorrectedDeltaRij(biasOmegaIncr, H);
125+
EQUALITY(Vector3(0, -deltaT * delta, 0), expected.logmap(corrected));
126+
EXPECT(assert_equal(Rot3::Pitch((omega - delta) * deltaT), corrected, 1e-9));
127+
128+
// TODO(frank): again the derivative is not the *sane* one!
129+
// auto g = [&](const Vector3& increment) {
130+
// return pim.biascorrectedDeltaRij(increment, {});
131+
// };
132+
// EXPECT(assert_equal(numericalDerivative11<Rot3, Vector3>(g, Z_3x1), H));
103133
}
104134

105135
//******************************************************************************

0 commit comments

Comments
 (0)