testConstantVelocityFactor.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #include <gtsam/geometry/Pose3.h>
20 #include <gtsam/inference/Symbol.h>
22 
24 #include <list>
25 
26 /* ************************************************************************* */
27 TEST(ConstantVelocityFactor, VelocityFactor) {
28  using namespace gtsam;
29 
30  const double tol{1e-5};
31 
32  const Key x1 = Key{1};
33  const Key x2 = Key{2};
34 
35  const double dt{1.0};
36 
37  // moving upward with groundtruth velocity"
38  const auto origin = NavState{Pose3{Rot3::Yaw(0), Point3{0.0, 0.0, 0.0}}, Velocity3{0.0, 0.0, 0.0}};
39 
40  const auto state0 = NavState{Pose3{Rot3::Yaw(0), Point3{0.0, 0.0, 0.0}}, Velocity3{0.0, 0.0, 1.0}};
41 
42  const auto state1 = NavState{Pose3{Rot3::Yaw(0), Point3{0.0, 0.0, 1.0}}, Velocity3{0.0, 0.0, 1.0}};
43 
44  const auto state2 = NavState{Pose3{Rot3::Yaw(0), Point3{0.0, 0.0, 2.0}}, Velocity3{0.0, 0.0, 1.0}};
45 
46  const auto state3 = NavState{Pose3{Rot3::Yaw(M_PI_2), Point3{0.0, 0.0, 2.0}}, Velocity3{0.0, 0.0, 1.0}};
47 
48  const double mu{1000};
50 
51  const auto factor = ConstantVelocityFactor(x1, x2, dt, noise_model);
52 
53  // positions are the same, secondary state has velocity 1.0 in z,
54  const auto state0_err_origin = factor.evaluateError(origin, state0);
55  EXPECT(assert_equal((Vector9() << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0).finished(), state0_err_origin, tol));
56 
57  // same velocities, different position
58  // second state agrees with initial state + velocity * dt
59  const auto state1_err_state0 = factor.evaluateError(state0, state1);
60  EXPECT(assert_equal((Vector9() << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0).finished(), state1_err_state0, tol));
61 
62  // same velocities, same position, different rotations
63  // second state agrees with initial state + velocity * dt
64  // as we assume that omega is 0.0 this is the same as the above case
65  // TODO: this should respect omega and actually fail in this case
66  const auto state3_err_state2 = factor.evaluateError(state0, state1);
67  EXPECT(assert_equal((Vector9() << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0).finished(), state3_err_state2, tol));
68 
69  // both bodies have the same velocity,
70  // but state2.pose() does not agree with state0.update()
71  // error comes from this position difference
72  const auto state2_err_state0 = factor.evaluateError(state0, state2);
73  EXPECT(assert_equal((Vector9() << 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0).finished(), state2_err_state0, tol));
74 }
75 
76 /* ************************************************************************* */
77 int main() {
78  TestResult tr;
79  return TestRegistry::runAllTests(tr);
80 }
81 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::Velocity3
Vector3 Velocity3
Velocity is currently typedef'd to Vector3.
Definition: NavState.h:28
mu
double mu
Definition: testBoundingConstraint.cpp:37
dt
const double dt
Definition: testVelocityConstraint.cpp:15
gtsam::Rot3::Yaw
static Rot3 Yaw(double t)
Positive yaw is to right (as in aircraft heading). See ypr.
Definition: Rot3.h:174
gtsam::NavState
Definition: NavState.h:34
ConstantVelocityFactor.h
Maintain a constant velocity motion model between two NavStates.
test_motion::noise_model
auto noise_model
Definition: testHybridNonlinearFactorGraph.cpp:119
gtsam::ConstantVelocityFactor
Definition: ConstantVelocityFactor.h:29
TestableAssertions.h
Provides additional testing facilities for common data structures.
x1
Pose3 x1
Definition: testPose3.cpp:663
gtsam::Pose3
Definition: Pose3.h:37
gtsam::noiseModel::Constrained::All
static shared_ptr All(size_t dim)
Definition: NoiseModel.h:480
Symbol.h
common::state2
static const NavState state2(x2, v2)
TestResult
Definition: TestResult.h:26
M_PI_2
#define M_PI_2
Definition: mconf.h:118
gtsam
traits
Definition: SFMdata.h:40
origin
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 origin
Definition: gnuplot_common_settings.hh:45
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
common::state1
static const NavState state1(x1, v1)
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
x2
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
main
int main()
Definition: testConstantVelocityFactor.cpp:77
Pose3.h
3D Pose
TEST
TEST(ConstantVelocityFactor, VelocityFactor)
Definition: testConstantVelocityFactor.cpp:27


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:19