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 /* ************************************************************************* */
Point2 q2
Definition: testPose2.cpp:753
Vector evaluateError(const double &pk, const double &qk, const double &qk1, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
Definition: Pendulum.h:147
Vector evaluateError(const double &vk1, const double &vk, const double &q, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
Definition: Pendulum.h:96
Vector v2
Point2 q1
Definition: testPose2.cpp:753
static int runAllTests(TestResult &result)
Vector v1
int main()
Key P(std::uint64_t j)
#define M_PI
Definition: main.h:78
Vector evaluateError(const double &pk1, const double &qk, const double &qk1, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
Definition: Pendulum.h:203
Vector evaluateError(const double &qk1, const double &qk, const double &v, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
Definition: Pendulum.h:48
void g(const string &key, int i)
Definition: testBTree.cpp:43
static const Line3 l(Rot3(), 1, 1)
Key Q(std::uint64_t j)
#define EXPECT(condition)
Definition: Test.h:151
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.)
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
const double h
Key V(std::uint64_t j)
TEST(LPInitSolver, InfiniteLoopSingleVar)
EIGEN_DEVICE_FUNC const SinReturnType sin() const
const G double tol
Definition: Group.h:83


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:48:34