26 using namespace gtsam;
39 Point2 x_initial(0.0, 0.0);
56 Point2 expected1(1.0, 0.0);
57 Point2 expected2(2.0, 0.0);
58 Point2 expected3(3.0, 0.0);
106 using Base::evaluateError;
111 Base(noiseModel::
Diagonal::Sigmas(
Vector2(1.0, 1.0)), TestKey1, TestKey2), Q_(2,2) {
119 G << 1.0, 0.0, 0.0, 1.0;
120 w << 1.0, 0.0, 0.0, 1.0;
123 Q_ = w*w.transpose();
133 double x = x_t0.x() * x_t0.x();
134 double y = x_t0.x() * x_t0.y();
161 std::cout <<
s <<
": NonlinearMotionModel\n";
162 std::cout <<
" TestKey1: " << keyFormatter(key<1>()) << std::endl;
163 std::cout <<
" TestKey2: " << keyFormatter(key<2>()) << std::endl;
168 const This *
e =
dynamic_cast<const This*
> (&
f);
169 return (e !=
nullptr) && (key<1>() == e->key<1>()) && (key<2>() == e->key<2>());
178 return 0.5 * w.dot(w);
182 size_t dim()
const override {
188 return QInvSqrt(c.
at<
Point2>(key<1>()))*unwhitenedError(c);
199 const X1&
x1 = c.
at<X1>(key<1>());
200 const X2&
x2 = c.
at<X2>(key<2>());
202 Vector b = -evaluateError(x1, x2, A1, A2);
205 if (constrained.get() !=
nullptr) {
207 A2, b, constrained));
210 Matrix Qinvsqrt = QInvSqrt(x1);
231 *H2 = Matrix::Identity(dim(),dim());
234 return (p2 - prediction);
253 using Base::evaluateError;
258 Base(noiseModel::Unit::Create(z.
size()), TestKey), z_(z), R_(1,1) {
275 z_hat(0) = 2*x_t1.x()*x_t1.x() - x_t1.x()*x_t1.y() - 2.5*x_t1.x() + 7*x_t1.y();
283 H(0,0) = 4*x_t1.x() - x_t1.y() - 2.5;
284 H(0,1) = -1*x_t1.x() + 7;
297 std::cout <<
s <<
": NonlinearMeasurementModel\n";
298 std::cout <<
" TestKey: " << keyFormatter(
key()) << std::endl;
303 const This *
e =
dynamic_cast<const This*
> (&
f);
304 return (e !=
nullptr) && Base::equals(f);
313 return 0.5 * w.dot(w);
317 size_t dim()
const override {
323 return RInvSqrt(c.
at<
Point2>(
key()))*unwhitenedError(c);
335 Vector b = -evaluateError(x1, A1);
338 if (constrained.get() !=
nullptr) {
342 Matrix Rinvsqrt = RInvSqrt(x1);
369 Point2 expected_predict[10];
370 Point2 expected_update[10];
371 expected_predict[0] =
Point2(0.81,0.99);
372 expected_update[0] =
Point2(0.824926197027,0.29509808);
373 expected_predict[1] =
Point2(0.680503230541,0.24343413);
374 expected_update[1] =
Point2(0.773360464065,0.43518355);
375 expected_predict[2] =
Point2(0.598086407378,0.33655375);
376 expected_update[2] =
Point2(0.908781566884,0.60766713);
377 expected_predict[3] =
Point2(0.825883936308,0.55223668);
378 expected_update[3] =
Point2(1.23221370495,0.74372849);
379 expected_predict[4] =
Point2(1.51835061468,0.91643243);
380 expected_update[4] =
Point2(1.32823362774,0.855855);
381 expected_predict[5] =
Point2(1.76420456986,1.1367754);
382 expected_update[5] =
Point2(1.36378040243,1.0623832);
383 expected_predict[6] =
Point2(1.85989698605,1.4488574);
384 expected_update[6] =
Point2(1.24068063304,1.3431964);
385 expected_predict[7] =
Point2(1.53928843321,1.6664778);
386 expected_update[7] =
Point2(1.04229257957,1.4856408);
387 expected_predict[8] =
Point2(1.08637382142,1.5484724);
388 expected_update[8] =
Point2(1.13201933157,1.5795507);
389 expected_predict[9] =
Point2(1.28146776705,1.7880819);
390 expected_update[9] =
Point2(1.22159588179,1.7434982);
406 Point2 x_initial(0.90, 1.10);
413 Point2 x_predict(0,0), x_update(0,0);
414 for(
unsigned int i = 0;
i < 10; ++
i){
417 x_predict = ekf.
predict(motionFactor);
421 x_update = ekf.
update(measurementFactor);
const gtsam::Symbol key('X', 0)
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
NoiseModelFactorN< Point2, Point2 > Base
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
static int runAllTests(TestResult &result)
JacobiRotation< float > G
NonlinearMotionModel This
NonlinearMeasurementModel(const Symbol &TestKey, Vector z)
const ValueType at(Key j) const
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Rot2 R(Rot2::fromAngle(0.1))
NonlinearMeasurementModel()
Matrix H(const Point2 &x_t1) const
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
std::shared_ptr< GaussianFactor > linearize(const Values &c) const override
static const KeyFormatter DefaultKeyFormatter
Vector whitenedError(const Values &c) const
T update(const NoiseModelFactor &measurementFactor)
static shared_ptr Create(size_t dim)
double error(const Values &c) const override
std::shared_ptr< GaussianFactor > linearize(const Values &c) const override
Matrix F(const Point2 &x_t0) const
~NonlinearMotionModel() override
Matrix * OptionalMatrixType
Class to perform generic Kalman Filtering using nonlinear factor graphs.
size_t dim() const override
Vector evaluateError(const Point2 &p1, const Point2 &p2, OptionalMatrixType H1, OptionalMatrixType H2) const override
Vector h(const Point2 &x_t1) const
#define EXPECT(condition)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
T predict(const NoiseModelFactor &motionFactor)
std::shared_ptr< This > shared_ptr
shared_ptr to this class
double error(const Values &c) const override
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Pose3 x3(Rot3::Ypr(M_PI/4.0, 0.0, 0.0), l2)
std::shared_ptr< This > shared_ptr
shared_ptr to this class
noiseModel::Diagonal::shared_ptr SharedDiagonal
~NonlinearMeasurementModel() override
NoiseModelFactorN< Point2 > Base
Point2 f(const Point2 &x_t0) const
Non-linear factor base classes.
static shared_ptr Sigmas(const Vector &sigmas, bool smart=true)
The quaternion class used to represent 3D orientations and rotations.
Matrix inverse_square_root(const Matrix &A)
NonlinearMeasurementModel This
typename std::tuple_element< I - 1, std::tuple< ValueTypes... > >::type ValueType
NonlinearMotionModel(const Symbol &TestKey1, const Symbol &TestKey2)
static noiseModel::Diagonal::shared_ptr Diagonal(const Matrix &covariance)
Matrix RInvSqrt(const Point2 &x_t0) const
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
TEST(SmartFactorBase, Pinhole)
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
Vector evaluateError(const Point2 &p, OptionalMatrixType H1) const override
size_t dim() const override
Matrix QInvSqrt(const Point2 &x_t0) const
Vector whitenedError(const Values &c) const