testPendulumFactors.cpp
Go to the documentation of this file.
1 
9 
10 /* ************************************************************************* */
11 using namespace gtsam;
12 using namespace gtsam::symbol_shorthand;
13 
14 namespace {
15 
16  const double tol=1e-5;
17  const double h = 0.1;
18  const double g = 9.81, l = 1.0;
19 
20  const double deg2rad = M_PI/180.0;
21  double q1(deg2rad*30.0), q2(deg2rad*31.0);
22  double v1(deg2rad*1.0/h), v2((v1-h*g/l*sin(q1)));
23 
24 }
25 
26 /* ************************************************************************* */
27 TEST( testPendulumFactor1, evaluateError) {
28  // hard constraints don't need a noise model
29  PendulumFactor1 constraint(Q(2), Q(1), V(1), h);
30 
31  // verify error function
32  EXPECT(assert_equal(Z_1x1, constraint.evaluateError(q2, q1, v1), tol));
33 }
34 
35 /* ************************************************************************* */
36 TEST( testPendulumFactor2, evaluateError) {
37  // hard constraints don't need a noise model
38  PendulumFactor2 constraint(V(2), V(1), Q(1), h);
39 
40  // verify error function
41  EXPECT(assert_equal(Z_1x1, constraint.evaluateError(v2, v1, q1), tol));
42 }
43 
44 /* ************************************************************************* */
45 TEST( testPendulumFactorPk, evaluateError) {
46  // hard constraints don't need a noise model
47  PendulumFactorPk constraint(P(1), Q(1), Q(2), h);
48 
49  double pk( 1/h * (q2-q1) + h*g*sin(q1) );
50 
51  // verify error function
52  EXPECT(assert_equal(Z_1x1, constraint.evaluateError(pk, q1, q2), tol));
53 }
54 
55 /* ************************************************************************* */
56 TEST( testPendulumFactorPk1, evaluateError) {
57  // hard constraints don't need a noise model
58  PendulumFactorPk1 constraint(P(2), Q(1), Q(2), h);
59 
60  double pk1( 1/h * (q2-q1) );
61 
62  // verify error function
63  EXPECT(assert_equal(Z_1x1, constraint.evaluateError(pk1, q1, q2), tol));
64 }
65 
66 
67 /* ************************************************************************* */
68 int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
69 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
gtsam::symbol_shorthand::P
Key P(std::uint64_t j)
Definition: inference/Symbol.h:163
gtsam::symbol_shorthand::Q
Key Q(std::uint64_t j)
Definition: inference/Symbol.h:164
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
ceres::sin
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:439
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::symbol_shorthand
Definition: inference/Symbol.h:147
gtsam::PendulumFactorPk::evaluateError
Vector evaluateError(const double &pk, const double &qk, const double &qk1, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:154
h
const double h
Definition: testSimpleHelicopter.cpp:19
Pendulum.h
Three-way factors for the pendulum dynamics as in [Stern06siggraph] for (1) explicit Euler method,...
l
static const Line3 l(Rot3(), 1, 1)
gtsam::PendulumFactor1::evaluateError
Vector evaluateError(const double &qk1, const double &qk, const double &v, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:51
Symbol.h
main
int main()
Definition: testPendulumFactors.cpp:68
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
gtsam::PendulumFactorPk
Definition: Pendulum.h:120
TestResult
Definition: TestResult.h:26
gtsam::PendulumFactorPk1
Definition: Pendulum.h:178
gtsam::PendulumFactor2
Definition: Pendulum.h:71
gtsam
traits
Definition: SFMdata.h:40
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition: testSmartFactorBase.cpp:38
gtsam::PendulumFactorPk1::evaluateError
Vector evaluateError(const double &pk1, const double &qk, const double &qk1, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:212
v2
Vector v2
Definition: testSerializationBase.cpp:39
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::PendulumFactor2::evaluateError
Vector evaluateError(const double &vk1, const double &vk, const double &q, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:101
M_PI
#define M_PI
Definition: mconf.h:117
gtsam::PendulumFactor1
Definition: Pendulum.h:23
gtsam::symbol_shorthand::V
Key V(std::uint64_t j)
Definition: inference/Symbol.h:169
v1
Vector v1
Definition: testSerializationBase.cpp:38


gtsam
Author(s):
autogenerated on Thu Nov 28 2024 04:08:35