Reverted back to functional

release/4.3a0
Frank 2016-01-25 12:15:29 -08:00
parent e64fc532e3
commit 2542d20367
3 changed files with 28 additions and 23 deletions

View File

@ -36,19 +36,24 @@ namespace sugar {
static Eigen::Block<Vector9, 3, 1> dR(Vector9& v) { return v.segment<3>(0); } static Eigen::Block<Vector9, 3, 1> dR(Vector9& v) { return v.segment<3>(0); }
static Eigen::Block<Vector9, 3, 1> dP(Vector9& v) { return v.segment<3>(3); } static Eigen::Block<Vector9, 3, 1> dP(Vector9& v) { return v.segment<3>(3); }
static Eigen::Block<Vector9, 3, 1> dV(Vector9& v) { return v.segment<3>(6); } static Eigen::Block<Vector9, 3, 1> dV(Vector9& v) { return v.segment<3>(6); }
typedef const Vector9 constV9;
static Eigen::Block<constV9, 3, 1> dR(constV9& v) { return v.segment<3>(0); }
static Eigen::Block<constV9, 3, 1> dP(constV9& v) { return v.segment<3>(3); }
static Eigen::Block<constV9, 3, 1> dV(constV9& v) { return v.segment<3>(6); }
} // namespace sugar } // namespace sugar
// See extensive discussion in ImuFactor.lyx // See extensive discussion in ImuFactor.lyx
void AggregateImuReadings::UpdateEstimate(const Vector3& a_body, Vector9 AggregateImuReadings::UpdateEstimate(const Vector3& a_body,
const Vector3& w_body, double dt, const Vector3& w_body, double dt,
Vector9* zeta, const Vector9& zeta,
OptionalJacobian<9, 9> A, OptionalJacobian<9, 9> A,
OptionalJacobian<9, 3> B, OptionalJacobian<9, 3> B,
OptionalJacobian<9, 3> C) { OptionalJacobian<9, 3> C) {
using namespace sugar; using namespace sugar;
const Vector3 theta = dR(*zeta); const Vector3 theta = dR(zeta);
const Vector3 v = dV(*zeta); const Vector3 v = dV(zeta);
// Calculate exact mean propagation // Calculate exact mean propagation
Matrix3 H; Matrix3 H;
@ -57,9 +62,10 @@ void AggregateImuReadings::UpdateEstimate(const Vector3& a_body,
const Vector3 a_nav = R * a_body; const Vector3 a_nav = R * a_body;
const double dt22 = 0.5 * dt * dt; const double dt22 = 0.5 * dt * dt;
dR(*zeta) += invH * w_body * dt; // theta Vector9 zetaPlus;
dP(*zeta) += v * dt + a_nav * dt22; // position dR(zetaPlus) = dR(zeta) + invH * w_body * dt; // theta
dV(*zeta) += a_nav * dt; // velocity dP(zetaPlus) = dP(zeta) + v * dt + a_nav * dt22; // position
dV(zetaPlus) = dV(zeta) + a_nav * dt; // velocity
if (A) { if (A) {
// First order (small angle) approximation of derivative of invH*w: // First order (small angle) approximation of derivative of invH*w:
@ -84,6 +90,8 @@ void AggregateImuReadings::UpdateEstimate(const Vector3& a_body,
C->block<3, 3>(3, 0) = Z_3x3; C->block<3, 3>(3, 0) = Z_3x3;
C->block<3, 3>(6, 0) = Z_3x3; C->block<3, 3>(6, 0) = Z_3x3;
} }
return zetaPlus;
} }
void AggregateImuReadings::integrateMeasurement(const Vector3& measuredAcc, void AggregateImuReadings::integrateMeasurement(const Vector3& measuredAcc,
@ -96,7 +104,7 @@ void AggregateImuReadings::integrateMeasurement(const Vector3& measuredAcc,
// Do exact mean propagation // Do exact mean propagation
Matrix9 A; Matrix9 A;
Matrix93 B, C; Matrix93 B, C;
UpdateEstimate(a_body, w_body, dt, &zeta_, A, B, C); zeta_ = UpdateEstimate(a_body, w_body, dt, zeta_, A, B, C);
// propagate uncertainty // propagate uncertainty
// TODO(frank): use noiseModel routine so we can have arbitrary noise models. // TODO(frank): use noiseModel routine so we can have arbitrary noise models.

View File

@ -74,11 +74,11 @@ class AggregateImuReadings {
// Update integrated vector on tangent manifold zeta with acceleration // Update integrated vector on tangent manifold zeta with acceleration
// readings a_body and gyro readings w_body, bias-corrected in body frame. // readings a_body and gyro readings w_body, bias-corrected in body frame.
static void UpdateEstimate(const Vector3& a_body, const Vector3& w_body, static Vector9 UpdateEstimate(const Vector3& a_body, const Vector3& w_body,
double dt, Vector9* zeta, double dt, const Vector9& zeta,
OptionalJacobian<9, 9> A = boost::none, OptionalJacobian<9, 9> A = boost::none,
OptionalJacobian<9, 3> B = boost::none, OptionalJacobian<9, 3> B = boost::none,
OptionalJacobian<9, 3> C = boost::none); OptionalJacobian<9, 3> C = boost::none);
}; };
} // namespace gtsam } // namespace gtsam

View File

@ -39,8 +39,7 @@ static boost::shared_ptr<AggregateImuReadings::Params> defaultParams() {
} }
Vector9 f(const Vector9& zeta, const Vector3& a, const Vector3& w) { Vector9 f(const Vector9& zeta, const Vector3& a, const Vector3& w) {
Vector9 zeta_plus = zeta; Vector9 zeta_plus = AggregateImuReadings::UpdateEstimate(a, w, kDt, zeta);
AggregateImuReadings::UpdateEstimate(a, w, kDt, &zeta_plus);
return zeta_plus; return zeta_plus;
} }
@ -50,10 +49,9 @@ TEST(AggregateImuReadings, UpdateEstimate1) {
const Vector3 acc(0.1, 0.2, 10), omega(0.1, 0.2, 0.3); const Vector3 acc(0.1, 0.2, 10), omega(0.1, 0.2, 0.3);
Vector9 zeta; Vector9 zeta;
zeta.setZero(); zeta.setZero();
Vector9 zeta2 = zeta;
Matrix9 aH1; Matrix9 aH1;
Matrix93 aH2, aH3; Matrix93 aH2, aH3;
pim.UpdateEstimate(acc, omega, kDt, &zeta2, aH1, aH2, aH3); pim.UpdateEstimate(acc, omega, kDt, zeta, aH1, aH2, aH3);
EXPECT(assert_equal(numericalDerivative31(f, zeta, acc, omega), aH1, 1e-9)); EXPECT(assert_equal(numericalDerivative31(f, zeta, acc, omega), aH1, 1e-9));
EXPECT(assert_equal(numericalDerivative32(f, zeta, acc, omega), aH2, 1e-9)); EXPECT(assert_equal(numericalDerivative32(f, zeta, acc, omega), aH2, 1e-9));
EXPECT(assert_equal(numericalDerivative33(f, zeta, acc, omega), aH3, 1e-9)); EXPECT(assert_equal(numericalDerivative33(f, zeta, acc, omega), aH3, 1e-9));
@ -65,10 +63,9 @@ TEST(AggregateImuReadings, UpdateEstimate2) {
const Vector3 acc(0.1, 0.2, 10), omega(0.1, 0.2, 0.3); const Vector3 acc(0.1, 0.2, 10), omega(0.1, 0.2, 0.3);
Vector9 zeta; Vector9 zeta;
zeta << 0.01, 0.02, 0.03, 100, 200, 300, 10, 5, 3; zeta << 0.01, 0.02, 0.03, 100, 200, 300, 10, 5, 3;
Vector9 zeta2 = zeta;
Matrix9 aH1; Matrix9 aH1;
Matrix93 aH2, aH3; Matrix93 aH2, aH3;
pim.UpdateEstimate(acc, omega, kDt, &zeta2, aH1, aH2, aH3); pim.UpdateEstimate(acc, omega, kDt, zeta, aH1, aH2, aH3);
// NOTE(frank): tolerance of 1e-3 on H1 because approximate away from 0 // NOTE(frank): tolerance of 1e-3 on H1 because approximate away from 0
EXPECT(assert_equal(numericalDerivative31(f, zeta, acc, omega), aH1, 1e-3)); EXPECT(assert_equal(numericalDerivative31(f, zeta, acc, omega), aH1, 1e-3));
EXPECT(assert_equal(numericalDerivative32(f, zeta, acc, omega), aH2, 1e-7)); EXPECT(assert_equal(numericalDerivative32(f, zeta, acc, omega), aH2, 1e-7));