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 /* ************************************************************************* */
Vector v2
static int runAllTests(TestResult &result)
Vector v1
int main()
Key P(std::uint64_t j)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
#define M_PI
Definition: main.h:106
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:439
void g(const string &key, int i)
Definition: testBTree.cpp:41
static const Line3 l(Rot3(), 1, 1)
Vector evaluateError(const double &pk1, const double &qk, const double &qk1, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:212
Key Q(std::uint64_t j)
Vector evaluateError(const double &vk1, const double &vk, const double &q, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:101
#define EXPECT(condition)
Definition: Test.h:150
Three-way factors for the pendulum dynamics as in [Stern06siggraph] for (1) explicit Euler method...
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Vector evaluateError(const double &qk1, const double &qk, const double &v, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:51
traits
Definition: chartTesting.h:28
const double h
Key V(std::uint64_t j)
const G double tol
Definition: Group.h:86
TEST(SmartFactorBase, Pinhole)
Vector evaluateError(const double &pk, const double &qk, const double &qk1, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:154


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:38:55