28 #include <boost/bind.hpp> 32 using namespace gtsam;
58 const Vector3& bias,
const list<Vector3>& measuredOmegas,
59 const list<double>& deltaTs,
60 const Vector3& initialRotationRate = Vector3::Zero()) {
63 list<Vector3>::const_iterator itOmega = measuredOmegas.begin();
64 list<double>::const_iterator itDeltaT = deltaTs.begin();
65 for (; itOmega != measuredOmegas.end(); ++itOmega, ++itDeltaT) {
72 Rot3 evaluatePreintegratedMeasurementsRotation(
73 const Vector3& bias,
const list<Vector3>& measuredOmegas,
74 const list<double>& deltaTs,
75 const Vector3& initialRotationRate = Vector3::Zero()) {
77 evaluatePreintegratedMeasurements(bias, measuredOmegas, deltaTs,
78 initialRotationRate).deltaRij());
83 return Rot3::Expmap((measuredOmega - biasOmega) * deltaT);
101 Rot3 expectedDeltaR1 = Rot3::RzRyRx(0.5 *
M_PI / 100.0, 0.0, 0.0);
102 double expectedDeltaT1(0.5);
112 Rot3 expectedDeltaR2 = Rot3::RzRyRx(2.0 * 0.5 *
M_PI / 100.0, 0.0, 0.0);
113 double expectedDeltaT2(1);
125 Matrix3 gyroscopeCovariance = Matrix3::Ones()*0.4;
126 Vector3 omegaCoriolis(0.1, 0.5, 0.9);
130 double deltaTij = 0.02;
131 Matrix3 delRdelBiasOmega = Matrix3::Ones()*0.5;
132 Matrix3 preintMeasCov = Matrix3::Ones()*0.2;
134 boost::make_shared<PreintegratedRotationParams>(params),
160 measuredOmega <<
M_PI / 100, 0, 0;
172 errorExpected << 0, 0, 0;
176 Matrix H1e = numericalDerivative11<Vector3, Rot3>(
177 boost::bind(&callEvaluateError, factor, _1, x2, bias),
x1);
178 Matrix H2e = numericalDerivative11<Vector3, Rot3>(
179 boost::bind(&callEvaluateError, factor, x1, _1, bias),
x2);
180 Matrix H3e = numericalDerivative11<Vector3, Vector3>(
181 boost::bind(&callEvaluateError, factor, x1, x2, _1),
bias);
184 Matrix RH1e = numericalDerivative11<Rot3, Rot3>(
185 boost::bind(&evaluateRotationError, factor, _1, x2, bias),
x1);
186 Matrix RH2e = numericalDerivative11<Rot3, Rot3>(
187 boost::bind(&evaluateRotationError, factor, x1, _1, bias),
x2);
217 measuredOmega << 0, 0,
M_PI / 10.0 + 0.3;
231 errorExpected << 0, 0, 0;
235 Matrix H1e = numericalDerivative11<Vector, Rot3>(
236 boost::bind(&callEvaluateError, factor, _1, x2, bias),
x1);
237 Matrix H2e = numericalDerivative11<Vector, Rot3>(
238 boost::bind(&callEvaluateError, factor, x1, _1, bias),
x2);
239 Matrix H3e = numericalDerivative11<Vector, Vector3>(
240 boost::bind(&callEvaluateError, factor, x1, x2, _1),
bias);
243 Matrix RH1e = numericalDerivative11<Rot3, Rot3>(
244 boost::bind(&evaluateRotationError, factor, _1, x2, bias),
x1);
245 Matrix RH2e = numericalDerivative11<Rot3, Rot3>(
246 boost::bind(&evaluateRotationError, factor, x1, _1, bias),
x2);
247 Matrix RH3e = numericalDerivative11<Rot3, Vector3>(
248 boost::bind(&evaluateRotationError, factor, x1, x2, _1),
bias);
266 measuredOmega << 0.1, 0, 0;
270 Matrix expectedDelRdelBiasOmega = numericalDerivative11<Rot3, Vector3>(
271 boost::bind(&evaluateRotation, measuredOmega, _1, deltaT), biasOmega);
273 const Matrix3 Jr = Rot3::ExpmapDerivative(
274 (measuredOmega - biasOmega) * deltaT);
276 Matrix3 actualdelRdelBiasOmega = -Jr *
deltaT;
288 thetahat << 0.1, 0.1, 0;
292 deltatheta << 0, 0, 0;
295 Matrix expectedDelFdeltheta = numericalDerivative11<Vector3, Vector3>(
296 boost::bind(&evaluateLogRotation, thetahat, _1), deltatheta);
300 double normx = x.norm();
301 const Matrix3 actualDelFdeltheta = I_3x3 + 0.5 * X
302 + (1 / (normx * normx) - (1 +
cos(normx)) / (2 * normx *
sin(normx))) * X
317 measuredOmega << 0.1, 0, 0;
325 const Matrix3 Jr = Rot3::ExpmapDerivative(
326 (measuredOmega - biasOmega) * deltaT);
328 Matrix3 delRdelBiasOmega = -Jr *
deltaT;
331 (measuredOmega - biasOmega - deltabiasOmega) * deltaT).matrix();
333 const Matrix3 hatRot =
334 Rot3::Expmap((measuredOmega - biasOmega) * deltaT).matrix();
335 const Matrix3 actualRot = hatRot
336 *
Rot3::Expmap(delRdelBiasOmega * deltabiasOmega).matrix();
350 list<Vector3> measuredOmegas;
351 list<double> deltaTs;
352 measuredOmegas.push_back(
Vector3(
M_PI / 100.0, 0.0, 0.0));
353 deltaTs.push_back(0.01);
354 measuredOmegas.push_back(
Vector3(
M_PI / 100.0, 0.0, 0.0));
355 deltaTs.push_back(0.01);
356 for (
int i = 1;
i < 100;
i++) {
357 measuredOmegas.push_back(
359 deltaTs.push_back(0.01);
364 evaluatePreintegratedMeasurements(bias, measuredOmegas, deltaTs,
368 Matrix expectedDelRdelBias =
369 numericalDerivative11<Rot3, Vector3>(
370 boost::bind(&evaluatePreintegratedMeasurementsRotation, _1,
372 Matrix expectedDelRdelBiasOmega = expectedDelRdelBias.rightCols(3);
392 omegaCoriolis << 0, 0.1, 0.1;
394 measuredOmega << 0, 0,
M_PI / 10.0 + 0.3;
411 Matrix H1e = numericalDerivative11<Vector, Rot3>(
412 boost::bind(&callEvaluateError, factor, _1, x2, bias),
x1);
413 Matrix H2e = numericalDerivative11<Vector, Rot3>(
414 boost::bind(&callEvaluateError, factor, x1, _1, bias),
x2);
415 Matrix H3e = numericalDerivative11<Vector, Vector3>(
416 boost::bind(&callEvaluateError, factor, x1, x2, _1),
bias);
419 Matrix RH1e = numericalDerivative11<Rot3, Rot3>(
420 boost::bind(&evaluateRotationError, factor, _1, x2, bias),
x1);
421 Matrix RH2e = numericalDerivative11<Rot3, Rot3>(
422 boost::bind(&evaluateRotationError, factor, x1, _1, bias),
x2);
423 Matrix RH3e = numericalDerivative11<Rot3, Vector3>(
424 boost::bind(&evaluateRotationError, factor, x1, x2, _1),
bias);
440 measuredOmega << 0, 0,
M_PI / 10.0;
443 for (
int i = 0;
i < 1000; ++
i) {
447 Matrix expectedMeasCov(3,3);
455 Rot3 expectedRot = Rot3::Ypr(20*
M_PI, 0, 0);
460 Matrix expectedH = numericalDerivative11<Vector3, Vector3>(
461 boost::bind(&AHRSFactor::PreintegratedMeasurements::predict,
462 &pim, _1, boost::none),
bias);
475 Rot3 x1(Rot3::RzRyRx(0, 0, 0));
492 for (
size_t i = 0;
i < 5; ++
i) {
501 graph.push_back(factor);
504 Rot3 expectedRot(Rot3::RzRyRx(0,
M_PI / 4, 0));
Provides additional testing facilities for common data structures.
const Vector3 & biasHat() const
const Matrix3 & getGyroscopeCovariance() const
virtual const Values & optimize()
static int runAllTests(TestResult &result)
const Matrix3 & delRdelBiasOmega() const
Factor Graph consisting of non-linear factors.
noiseModel::Diagonal::shared_ptr model
void insert(Key j, const Value &val)
#define DOUBLES_EQUAL(expected, actual, threshold)
TEST(AHRSFactor, PreintegratedMeasurements)
Vector3 kZeroOmegaCoriolis(0, 0, 0)
Pose2_ Expmap(const Vector3_ &xi)
Some functions to compute numerical derivatives.
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
NonlinearFactorGraph graph
Matrix< SCALARB, Dynamic, Dynamic > B
Vector3 predict(const Vector3 &bias, OptionalJacobian< 3, 3 > H=boost::none) const
T compose(const T &t1, const T &t2)
const double & deltaTij() const
EIGEN_DEVICE_FUNC const CosReturnType cos() const
static Rot3 predict(const Rot3 &rot_i, const Vector3 &bias, const PreintegratedMeasurements preintegratedMeasurements, const Vector3 &omegaCoriolis, const boost::optional< Pose3 > &body_P_sensor=boost::none)
const ValueType at(Key j) const
#define EXPECT(condition)
static const double deltaT
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Vector evaluateError(const Rot3 &rot_i, const Rot3 &rot_j, const Vector3 &bias, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
vector of errors
Linear Factor Graph where all factors are Gaussians.
static SmartStereoProjectionParams params
boost::shared_ptr< Base > shared_ptr
const Matrix3 & preintMeasCov() const
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Matrix3 skewSymmetric(double wx, double wy, double wz)
static const Vector3 measuredOmega(w, 0, 0)
const Matrix3 kMeasuredAccCovariance
boost::optional< Vector3 > getOmegaCoriolis() const
const Rot3 & deltaRij() const
void integrateMeasurement(const Vector3 &measuredOmega, double deltaT)
A class for computing marginals in a NonlinearFactorGraph.
EIGEN_DEVICE_FUNC const SinReturnType sin() const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector