Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/plane factor #564

Merged
merged 36 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
df5ecac
Add unit test for oriented plane 3 factor jacobian
dwisth Jun 16, 2020
75eb859
Fix OrientedPlane3Factor jacobian using numericalDerivative
dwisth Jun 22, 2020
58a0f82
Address Frank's comments and clean up changes
dwisth Jun 23, 2020
795380d
Update style and switch to errorVector()
dwisth Jun 23, 2020
a897ee7
Fix all unit tests. Only remaining item is the analytical Jacobian fo…
dwisth Jul 15, 2020
1708162
Fixed some warnings
dellaert Oct 12, 2020
5df3eeb
Printing now transpose
dellaert Oct 12, 2020
4adca52
Simplified evaluateError
dellaert Oct 12, 2020
6909c2b
Use keyFormatter
dellaert Oct 12, 2020
adbd9a6
Added unit test for issue 561
dellaert Oct 12, 2020
af4005a
pass in params to optimizer
varunagrawal Nov 15, 2020
d4aec50
Merge branch 'develop' into fix/planeFactor
varunagrawal Nov 16, 2020
edb3aea
Merge branch 'develop' into fix/oriented-plane3-factor-jacobian
varunagrawal Dec 6, 2020
534fa6b
formatting and small fixes
varunagrawal Dec 6, 2020
5076837
Add a simplifed version of the minimal failing example
dwisth Jan 19, 2021
62119d8
Add hessian calculation
dwisth Jan 19, 2021
b9a8101
Merge pull request #680 from dwisth/fix/planeFactor-dwisth
dellaert Jan 21, 2021
b5789f6
Merge branch 'develop' into fix/planeFactor
dellaert Jan 21, 2021
6b11c9f
use transform rather than deprecated static function
dellaert Jan 21, 2021
fd8575b
Merge branch 'fix/planeFactor' into fix/oriented-plane3-factor-jacobian
dellaert Jan 21, 2021
564c8bf
Merge pull request #362 from dwisth/fix/oriented-plane3-factor-jacobian
dellaert Jan 21, 2021
68887f2
Got rid of extra keys
dellaert Jan 21, 2021
6c39730
Got rid of static versions of methods
dellaert Jan 21, 2021
1b36c74
Cleaned up derivative code
dellaert Jan 21, 2021
79d4247
Cleanup
dellaert Jan 21, 2021
46464aa
cleanup
dellaert Jan 29, 2021
9eb6267
Comments
dellaert Feb 3, 2021
a62bdd4
Add new oriented plane 3 factors with local linearisation point
dwisth Feb 15, 2021
0ad488c
Update print method of OrientedPlane3Factor
dwisth Feb 15, 2021
5087d36
remove deprecated Unit3::error() which is replaced by Unit3::errorVec…
dwisth Feb 15, 2021
7480d14
Update documentation on new factor
dwisth Feb 15, 2021
1771a56
Revert "remove deprecated Unit3::error() which is replaced by Unit3::…
dwisth Feb 16, 2021
71f39ab
remove the error() function from OrientedPlane3 (it had incorrect der…
dwisth Feb 16, 2021
960a3e1
Tidy up comments and use cpplint
dwisth Feb 16, 2021
5b0bd08
small tidy and fix unit tests
dwisth Feb 16, 2021
8f18ce9
Add inline comments on commented-out unit tests
dwisth Feb 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions gtsam/geometry/OrientedPlane3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <gtsam/geometry/OrientedPlane3.h>
#include <gtsam/geometry/Point2.h>

#include <iostream>

using namespace std;
Expand All @@ -28,7 +29,7 @@ namespace gtsam {
/* ************************************************************************* */
void OrientedPlane3::print(const string& s) const {
Vector4 coeffs = planeCoefficients();
cout << s << " : " << coeffs << endl;
cout << s << " : " << coeffs.transpose() << endl;
}

/* ************************************************************************* */
Expand All @@ -42,15 +43,14 @@ OrientedPlane3 OrientedPlane3::transform(const Pose3& xr, OptionalJacobian<3, 3>
double pred_d = n_.unitVector().dot(xr.translation()) + d_;

if (Hr) {
*Hr = Matrix::Zero(3,6);
Hr->setZero();
Hr->block<2, 3>(0, 0) = D_rotated_plane;
Hr->block<1, 3>(2, 3) = unit_vec;
}
if (Hp) {
Vector2 hpp = n_.basis().transpose() * xr.translation();
*Hp = Z_3x3;
Hp->setZero();
Hp->block<2, 2>(0, 0) = D_rotated_pose;
Hp->block<1, 2>(2, 0) = hpp;
Hp->block<1, 2>(2, 0) = n_.basis().transpose() * xr.translation();
(*Hp)(2, 2) = 1;
}

Expand Down
8 changes: 5 additions & 3 deletions gtsam/geometry/OrientedPlane3.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <gtsam/geometry/Unit3.h>
#include <gtsam/geometry/Pose3.h>

#include <algorithm>
dwisth marked this conversation as resolved.
Show resolved Hide resolved
#include <string>

namespace gtsam {

/**
Expand Down Expand Up @@ -58,9 +61,8 @@ class GTSAM_EXPORT OrientedPlane3 {
}

/// Construct from a vector of plane coefficients
OrientedPlane3(const Vector4& vec) :
n_(vec(0), vec(1), vec(2)), d_(vec(3)) {
}
explicit OrientedPlane3(const Vector4& vec)
: n_(vec(0), vec(1), vec(2)), d_(vec(3)) {}

/// Construct from four numbers of plane coeffcients (a, b, c, d)
OrientedPlane3(double a, double b, double c, double d) {
Expand Down
4 changes: 2 additions & 2 deletions gtsam/slam/OrientedPlane3Factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace gtsam {
//***************************************************************************
void OrientedPlane3Factor::print(const string& s,
const KeyFormatter& keyFormatter) const {
cout << "OrientedPlane3Factor Factor on " << landmarkKey_ << "\n";
cout << "OrientedPlane3Factor Factor on " << keyFormatter(landmarkKey_) << "\n";
measured_p_.print("Measured Plane");
this->noiseModel_->print(" noise model: ");
}

//***************************************************************************
void OrientedPlane3DirectionPrior::print(const string& s,
const KeyFormatter& keyFormatter) const {
cout << "Prior Factor on " << landmarkKey_ << "\n";
cout << "Prior Factor on " << keyFormatter(landmarkKey_) << "\n";
measured_p_.print("Measured Plane");
this->noiseModel_->print(" noise model: ");
}
Expand Down
15 changes: 6 additions & 9 deletions gtsam/slam/OrientedPlane3Factor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ class OrientedPlane3Factor: public NoiseModelFactor2<Pose3, OrientedPlane3> {
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override;

/// evaluateError
Vector evaluateError(const Pose3& pose, const OrientedPlane3& plane,
boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 =
boost::none) const override {
OrientedPlane3 predicted_plane = OrientedPlane3::Transform(plane, pose, H1,
H2);
Vector err(3);
err << predicted_plane.error(measured_p_);
return (err);
Vector evaluateError(
const Pose3& pose, const OrientedPlane3& plane,
boost::optional<Matrix&> H1 = boost::none,
boost::optional<Matrix&> H2 = boost::none) const override {
auto predicted_plane = OrientedPlane3::Transform(plane, pose, H1, H2);
return predicted_plane.error(measured_p_);
}
;
};

// TODO: Convert this factor to dimension two, three dimensions is redundant for direction prior
Expand Down
81 changes: 77 additions & 4 deletions gtsam/slam/tests/testOrientedPlane3Factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
* -------------------------------------------------------------------------- */

/*
* @file testOrientedPlane3.cpp
* @file testOrientedPlane3Factor.cpp
* @date Dec 19, 2012
* @author Alex Trevor
* @brief Tests the OrientedPlane3Factor class
*/

#include <gtsam/slam/OrientedPlane3Factor.h>
#include <gtsam/nonlinear/ISAM2.h>
#include <gtsam/inference/Symbol.h>

#include <gtsam/base/numericalDerivative.h>
#include <gtsam/inference/Symbol.h>
#include <gtsam/nonlinear/GaussNewtonOptimizer.h>
#include <gtsam/nonlinear/ISAM2.h>

#include <CppUnitLite/TestHarness.h>
#include <boost/bind.hpp>

#include <boost/assign/std/vector.hpp>
#include <boost/assign/std.hpp>
#include <boost/bind.hpp>

using namespace boost::assign;
using namespace gtsam;
Expand Down Expand Up @@ -170,6 +174,75 @@ TEST( OrientedPlane3DirectionPrior, Constructor ) {
EXPECT(assert_equal(expectedH3, actualH3, 1e-8));
}

/* ************************************************************************* */
// Test by Marco Camurri to debug issue #561
TEST(OrientedPlane3Factor, Issue561) {
// Typedefs
using symbol_shorthand::P; //< Planes
using symbol_shorthand::X; //< Pose3 (x,y,z,r,p,y)
using Plane = OrientedPlane3;

NonlinearFactorGraph graph;

// Setup prior factors
Pose3 x0_prior(
Rot3(0.799903913, -0.564527097, 0.203624376, 0.552537226, 0.82520195,
0.117236322, -0.234214312, 0.0187322547, 0.972004505),
Vector3{-91.7500013, -0.47569366, -2.2});
auto x0_noise = noiseModel::Isotropic::Sigma(6, 0.01);
graph.addPrior<Pose3>(X(0), x0_prior, x0_noise);

// Plane p1_prior(0.211098835, 0.214292752, 0.95368543, 26.4269514);
// auto p1_noise =
// noiseModel::Diagonal::Sigmas(Vector3{0.785398163, 0.785398163, 5});
// graph.addPrior<Plane>(P(1), p1_prior, p1_noise);

// ADDING THIS PRIOR MAKES OPTIMIZATION FAIL
// Plane p2_prior(0.301901811, 0.151751467, 0.941183717, 33.4388229);
// auto p2_noise =
// noiseModel::Diagonal::Sigmas(Vector3{0.785398163, 0.785398163, 5});
// graph.addPrior<Plane>(P(2), p2_prior, p2_noise);

// First plane factor
Plane p1_meas = Plane(0.0638967294, 0.0755284627, 0.995094297, 2.55956073);
const auto x0_p1_noise = noiseModel::Isotropic::Sigma(3, 0.0451801);
graph.emplace_shared<OrientedPlane3Factor>(p1_meas.planeCoefficients(),
x0_p1_noise, X(0), P(1));

// Second plane factor
Plane p2_meas = Plane(0.104902077, -0.0275756528, 0.994100165, 1.32765088);
const auto x0_p2_noise = noiseModel::Isotropic::Sigma(3, 0.0322889);
graph.emplace_shared<OrientedPlane3Factor>(p2_meas.planeCoefficients(),
x0_p2_noise, X(0), P(2));

// Optimize
try {
// Initial values
Values initialEstimate;
Plane p1(0.211098835, 0.214292752, 0.95368543, 26.4269514);
Plane p2(0.301901811, 0.151751467, 0.941183717, 33.4388229);
Pose3 x0(
Rot3(0.799903913, -0.564527097, 0.203624376, 0.552537226, 0.82520195,
0.117236322, -0.234214312, 0.0187322547, 0.972004505),
Vector3{-91.7500013, -0.47569366, -2.2});
initialEstimate.insert(P(1), p1);
initialEstimate.insert(P(2), p2);
initialEstimate.insert(X(0), x0);

GaussNewtonParams params;
GTSAM_PRINT(graph);
Ordering ordering = list_of(P(1))(P(2))(X(0)); // make sure P1 eliminated first
params.setOrdering(ordering);
params.setLinearSolverType("SEQUENTIAL_QR"); // abundance of caution
params.setVerbosity("TERMINATION"); // show info about stopping conditions
GaussNewtonOptimizer optimizer(graph, initialEstimate);
dwisth marked this conversation as resolved.
Show resolved Hide resolved
Values result = optimizer.optimize();
EXPECT_DOUBLES_EQUAL(0, graph.error(result), 0.1);
} catch (IndeterminantLinearSystemException e) {
std::cerr << "CAPTURED THE EXCEPTION: " << e.nearbyVariable() << std::endl;
}
}

/* ************************************************************************* */
int main() {
srand(time(nullptr));
Expand Down