Cheetah Software  1.0
test_LegController.cpp File Reference
#include "Controllers/LegController.h"
#include "Dynamics/MiniCheetah.h"
#include "Dynamics/Quadruped.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
+ Include dependency graph for test_LegController.cpp:

Go to the source code of this file.

Functions

 TEST (LegController, JacobianAndFwdKinematics1)
 
 TEST (LegController, JacobianAndFwdKinematics2)
 
 TEST (LegController, FwdKinematicsLegSign)
 

Detailed Description

Todo: it would be nice to test these against the full dynamics model!

Definition in file test_LegController.cpp.

Function Documentation

TEST ( LegController  ,
JacobianAndFwdKinematics1   
)

Test jacobian by verifying that fwd_kin(q + dq) = fwd_kin(q) + J * qd

Definition at line 15 of file test_LegController.cpp.

References almostEqual(), and computeLegJacobianAndPosition().

15  {
16  Quadruped<double> quadruped = buildMiniCheetah<double>();
17  Vec3<double> q0(1, 2, 3);
18  Vec3<double> dq(.001, .002, -.001);
19  Mat3<double> J;
20  Vec3<double> p0, p1Ref, p1;
21 
22  Vec3<double> q1 = q0 + dq;
23  computeLegJacobianAndPosition(quadruped, q0, &J, &p0, 0);
24  computeLegJacobianAndPosition(quadruped, q1, (Mat3<double>*)nullptr, &p1Ref,
25  0);
26 
27  p1 = p0 + J * dq;
28 
29  EXPECT_TRUE(almostEqual(p1, p1Ref, .001 * .001));
30 }
void computeLegJacobianAndPosition(Quadruped< T > &quad, Vec3< T > &q, Mat3< T > *J, Vec3< T > *p, int leg)
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( LegController  ,
JacobianAndFwdKinematics2   
)

Test jacobian by finding it analytically

Definition at line 35 of file test_LegController.cpp.

References almostEqual(), and computeLegJacobianAndPosition().

35  {
36  Quadruped<double> quadruped = buildMiniCheetah<double>();
37  Vec3<double> q0(4, 5, 6);
38  Vec3<double> p0;
39  Mat3<double> Jref;
40  Mat3<double> J;
41 
42  computeLegJacobianAndPosition(quadruped, q0, &Jref, &p0, 0);
43  double d = .001;
44 
45  for (int dim = 0; dim < 3; dim++) {
47  dq(dim) = d;
48  Vec3<double> q1 = q0 + dq;
49  Vec3<double> p1;
50  computeLegJacobianAndPosition(quadruped, q1, (Mat3<double>*)nullptr, &p1,
51  0);
52  Vec3<double> dp = p1 - p0;
53  J.block<3, 1>(0, dim) = dp / d;
54  }
55 
56  EXPECT_TRUE(almostEqual(J, Jref, .001));
57 }
void computeLegJacobianAndPosition(Quadruped< T > &quad, Vec3< T > &q, Mat3< T > *J, Vec3< T > *p, int leg)
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( LegController  ,
FwdKinematicsLegSign   
)

Check that the foot is in the right spot when all joints are at zero

Definition at line 62 of file test_LegController.cpp.

References Quadruped< T >::_abadLinkLength, Quadruped< T >::_hipLinkLength, Quadruped< T >::_kneeLinkLength, almostEqual(), and computeLegJacobianAndPosition().

62  {
63  Quadruped<double> quadruped = buildMiniCheetah<double>();
64  Vec3<double> q(0, 0, 0);
65  Vec3<double> p;
66  computeLegJacobianAndPosition(quadruped, q, (Mat3<double>*)nullptr, &p, 0);
67 
68  Vec3<double> pRef(0, -quadruped._abadLinkLength,
69  -quadruped._hipLinkLength - quadruped._kneeLinkLength);
70 
71  EXPECT_TRUE(almostEqual(pRef, p, .00001));
72 
73  computeLegJacobianAndPosition(quadruped, q, (Mat3<double>*)nullptr, &p, 1);
74 
75  Vec3<double> pRef2(0, quadruped._abadLinkLength,
76  -quadruped._hipLinkLength - quadruped._kneeLinkLength);
77 
78  EXPECT_TRUE(almostEqual(pRef2, p, .00001));
79 }
void computeLegJacobianAndPosition(Quadruped< T > &quad, Vec3< T > &q, Mat3< T > *J, Vec3< T > *p, int leg)
T _hipLinkLength
Definition: Quadruped.h:62
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
T _kneeLinkLength
Definition: Quadruped.h:62
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
T _abadLinkLength
Definition: Quadruped.h:62

+ Here is the call graph for this function: