36 using namespace gtsam;
40 static const double tol = 1
e-5;
97 Pose2 value(2.0, 1.0, 2.0), wrong(2.0, 3.0, 4.0);
99 bad_linearize.
insert(key, wrong);
114 bad_linearize.
insert(key, wrong);
127 Values feasible, bad_linearize;
135 Vector actual = nle->unwhitenedError(feasible);
138 actual = nle->unwhitenedError(bad_linearize);
140 assert_equal(actual, Vector::Constant(3, std::numeric_limits<double>::infinity())));
154 EXPECT(nle1->equals(*nle2));
156 EXPECT(nle2->equals(*nle1));
158 EXPECT(!nle1->equals(*nle3));
165 Pose2 feasible1(1.0, 2.0, 3.0);
166 double error_gain = 500.0;
167 PoseNLE nle(key1, feasible1, error_gain);
170 Pose2 badPoint1(0.0, 2.0, 3.0);
177 config.
insert(key1, badPoint1);
178 double actError = nle.
error(config);
194 Pose2 feasible1(1.0, 2.0, 3.0);
195 double error_gain = 500.0;
196 PoseNLE nle(key1, feasible1, error_gain);
203 Pose2 initPose(0.0, 2.0, 3.0);
205 init.
insert(key1, initPose);
209 ordering.push_back(key1);
214 expected.
insert(key1, feasible1);
223 Pose2 feasible1(1.0, 2.0, 3.0);
227 Pose2 initPose(0.0, 2.0, 3.0);
228 init.
insert(key1, initPose);
230 double error_gain = 500.0;
231 PoseNLE nle(key1, feasible1, error_gain);
234 PosePrior prior(key1, initPose, noiseModel::Isotropic::Sigma(3, 0.1));
243 ordering.push_back(key1);
248 expected.
insert(key1, feasible1);
257 TEST( testNonlinearEqualityConstraint, unary_basics ) {
272 config2.insert(
key, ptBad1);
282 TEST( testNonlinearEqualityConstraint, unary_linearization ) {
305 TEST( testNonlinearEqualityConstraint, unary_simple_optimization ) {
308 Point2 truth_pt(1.0, 2.0);
314 Point2 badPt(100.0, -200.0);
323 initValues.
insert(key, badPt);
326 EXPECT(constraint->active(initValues));
329 expected.insert(key, truth_pt);
330 EXPECT(constraint->active(expected));
338 TEST( testNonlinearEqualityConstraint, odo_basics ) {
339 Point2 x1(1.0, 2.0),
x2(2.0, 3.0), odom(1.0, 1.0);
355 config2.insert(
key1, x1bad);
356 config2.insert(key2, x2bad);
366 TEST( testNonlinearEqualityConstraint, odo_linearization ) {
367 Point2 x1(1.0, 2.0),
x2(2.0, 3.0), odom(1.0, 1.0);
385 config2.
insert(key2, x2bad);
394 TEST( testNonlinearEqualityConstraint, odo_simple_optimize ) {
398 Point2 truth_pt1(1.0, 2.0), truth_pt2(3.0, 2.0);
406 Point2 badPt(100.0, -200.0);
421 initValues.
insert(key2, badPt);
426 expected.
insert(key2, truth_pt2);
431 TEST (testNonlinearEqualityConstraint, two_pose ) {
442 Point2 pt_x1(1.0, 1.0), pt_x2(5.0, 6.0);
473 TEST (testNonlinearEqualityConstraint, map_warp ) {
518 TEST (testNonlinearEqualityConstraint, stereo_constrained ) {
521 static double fov = 60;
522 static int w = 640,
h = 480;
524 static boost::shared_ptr<Cal3_S2> shK(
new Cal3_S2(K));
538 Symbol key_x1(
'x', 1), key_x2(
'x', 2);
539 Symbol key_l1(
'l', 1), key_l2(
'l', 2);
551 leftCamera.
project(landmark), vmodel, key_x1, key_l1, shK);
553 rightCamera.
project(landmark), vmodel, key_x2, key_l2, shK);
563 initValues.
insert(key_x1, poseLeft);
564 initValues.
insert(key_x2, poseRight);
565 initValues.
insert(key_l1, landmark1);
566 initValues.
insert(key_l2, landmark2);
573 truthValues.
insert(key_x1, leftCamera.
pose());
574 truthValues.
insert(key_x2, rightCamera.
pose());
575 truthValues.
insert(key_l1, landmark);
576 truthValues.
insert(key_l2, landmark);
boost::shared_ptr< NonlinearEquality1< VALUE > > shared_ptr
fixed value for variable
iq2D::PoseXInequality constraint1(key, 1.0, true, mu)
NonlinearEquality1< Point2 > UnaryEqualityConstraint
boost::shared_ptr< GaussianFactor > linearize(const Values &x) const override
double error(const Values &c) const override
const Pose3 & pose() const
return pose
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
virtual const Values & optimize()
NonlinearEquality< Pose2 > PoseNLE
static int runAllTests(TestResult &result)
Factor Graph consisting of non-linear factors.
boost::shared_ptr< PoseNLE > shared_poseNLE
Point2 prior(const Point2 &x)
Prior on a single pose.
noiseModel::Diagonal::shared_ptr model
void insert(Key j, const Value &val)
static enum @843 ordering
#define DOUBLES_EQUAL(expected, actual, threshold)
iq2D::PoseYInequality constraint2(key, 2.0, true, mu)
static const double sigma
boost::shared_ptr< BetweenConstraint< VALUE > > shared_ptr
static SharedDiagonal soft_model
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
Vector evaluateError(const T &xj, boost::optional< Matrix & > H=boost::none) const override
static const Point3 pt(1.0, 2.0, 3.0)
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
#define CHECK_EXCEPTION(condition, exception_name)
NonlinearFactorGraph graph
Point2 landmark1(5.0, 1.5)
TEST(NonlinearEquality, linearization)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
virtual bool active(const Values &) const
static Point3 landmark(0, 0, 5)
const Symbol key1('v', 1)
GaussianFactor::shared_ptr linearize(const Values &x) const override
Base class for all pinhole cameras.
static Symbol key('x', 1)
Point2 landmark2(7.0, 1.5)
Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const override
NonlinearEquality2< Point2 > PointEqualityConstraint
Vector evaluateError(const X &x1, boost::optional< Matrix & > H=boost::none) const override
GenericMeasurement< Point2, Point2 > Measurement
#define EXPECT(condition)
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Basic bearing factor from 2D measurement.
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
static const Pose3 pose1(Rot3(), Point3(0, 1, 0.5))
noiseModel::Diagonal::shared_ptr SharedDiagonal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
const Symbol key2('v', 2)
PriorFactor< Pose2 > PosePrior
Point2 project(const Point3 &pw, OptionalJacobian< 2, 6 > Dpose=boost::none, OptionalJacobian< 2, 3 > Dpoint=boost::none, OptionalJacobian< 2, DimK > Dcal=boost::none) const
project a 3D point from world coordinates into the image
Chordal Bayes Net, the result of eliminating a factor graph.
double error(const Values &c) const override
boost::shared_ptr< GenericPrior< VALUE > > shared_ptr
static SharedDiagonal hard_model
Vector evaluateError(const T &p1, const T &p2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
evaluate error, returns vector of errors size of tangent space
static const Eigen::MatrixBase< Vector2 >::ConstantReturnType Z_2x1
Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const override
noiseModel::Base::shared_ptr SharedNoiseModel
The most common 5DOF 3D->2D calibration.
measurement functions and constraint definitions for simulated 2D robot