2010-10-14 12:54:38 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
|
|
|
* Atlanta, Georgia 30332-0415
|
|
|
|
* All Rights Reserved
|
|
|
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
|
|
|
|
|
|
* See LICENSE for the license information
|
|
|
|
|
|
|
|
* -------------------------------------------------------------------------- */
|
|
|
|
|
2009-08-22 06:23:24 +08:00
|
|
|
/**
|
|
|
|
* @file testSimulated3D.cpp
|
|
|
|
* @brief Unit tests for simulated 3D measurement functions
|
|
|
|
* @author Alex Cunningham
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <iostream>
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/CppUnitLite/TestHarness.h>
|
2009-08-22 06:23:24 +08:00
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/geometry/Pose3.h>
|
|
|
|
#include <gtsam/base/numericalDerivative.h>
|
|
|
|
#include <gtsam/slam/Simulated3D.h>
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
using namespace gtsam;
|
Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just says something like
if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
2010-01-14 06:25:03 +08:00
|
|
|
using namespace simulated3D;
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2010-10-09 11:09:58 +08:00
|
|
|
TEST( simulated3D, Values )
|
2009-08-22 06:23:24 +08:00
|
|
|
{
|
2010-10-09 11:09:58 +08:00
|
|
|
Values actual;
|
2010-08-25 01:26:56 +08:00
|
|
|
actual.insert(PointKey(1),Point3(1,1,1));
|
|
|
|
actual.insert(PoseKey(2),Point3(2,2,2));
|
|
|
|
EXPECT(assert_equal(actual,actual,1e-9));
|
2009-08-22 06:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2010-08-25 01:26:56 +08:00
|
|
|
TEST( simulated3D, Dprior )
|
2009-08-22 06:23:24 +08:00
|
|
|
{
|
2010-08-25 01:26:56 +08:00
|
|
|
Point3 x(1,-9, 7);
|
|
|
|
Matrix numerical = numericalDerivative11<Point3, Point3>(boost::bind(prior, _1, boost::none),x);
|
|
|
|
Matrix computed;
|
|
|
|
prior(x,computed);
|
|
|
|
EXPECT(assert_equal(numerical,computed,1e-9));
|
2009-08-22 06:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2010-08-25 01:26:56 +08:00
|
|
|
TEST( simulated3D, DOdo )
|
2009-08-22 06:23:24 +08:00
|
|
|
{
|
2010-08-25 01:26:56 +08:00
|
|
|
Point3 x1(1,-9,7),x2(-5,6,7);
|
|
|
|
Matrix H1,H2;
|
|
|
|
odo(x1,x2,H1,H2);
|
|
|
|
Matrix A1 = numericalDerivative21<Point3, Point3, Point3>(boost::bind(odo, _1, _2, boost::none, boost::none),x1,x2);
|
|
|
|
EXPECT(assert_equal(A1,H1,1e-9));
|
|
|
|
Matrix A2 = numericalDerivative22<Point3, Point3, Point3>(boost::bind(odo, _1, _2, boost::none, boost::none),x1,x2);
|
|
|
|
EXPECT(assert_equal(A2,H2,1e-9));
|
2009-08-22 06:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
|
|
|
|
/* ************************************************************************* */
|