Cheetah Software  1.0
test_cheetah3_model.cpp File Reference
#include "Dynamics/FloatingBaseModel.h"
#include "Dynamics/Quadruped.h"
#include "Utilities/utilities.h"
#include "include/Dynamics/Cheetah3.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <stdio.h>
+ Include dependency graph for test_cheetah3_model.cpp:

Go to the source code of this file.

Functions

 TEST (Cheetah3, simulatorDynamicsDoesntCrashCheetah3)
 
 TEST (Cheetah3, simulatorContactInertiaCheetah3)
 
 TEST (Cheetah3, simulatorTestForceCheetah3)
 

Function Documentation

TEST ( Cheetah3  ,
simulatorDynamicsDoesntCrashCheetah3   
)

Creates a cheetah model and runs forward kinematics and ABA Doesn't test anyting - this is just to make sure it doesn't crash

Definition at line 25 of file test_cheetah3_model.cpp.

References FloatingBaseModel< T >::_nDof, FloatingBaseModel< T >::forwardKinematics(), FBModelStateDerivative< T >::qdd, and FloatingBaseModel< T >::runABA().

25  {
26  FloatingBaseModel<double> cheetah = buildCheetah3<double>().buildModel();
27  DVec<double> tau(12);
29  _dstate.qdd = DVec<double>::Zero(cheetah._nDof - 6);
30 
31  cheetah.forwardKinematics();
32  cheetah.runABA(tau, _dstate);
33 }
void runABA(const DVec< T > &tau, FBModelStateDerivative< T > &dstate)
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec
Definition: cppTypes.h:102

+ Here is the call graph for this function:

TEST ( Cheetah3  ,
simulatorContactInertiaCheetah3   
)

Run the contact inertia algorithm for cheetah 3 Set a weird body orientation, velocity, q, dq, and tau Checks that it matches the result from J H^(-1) J^T

Definition at line 40 of file test_cheetah3_model.cpp.

References FloatingBaseModel< T >::_Jc, almostEqual(), FBModelState< T >::bodyOrientation, FBModelState< T >::bodyPosition, FBModelState< T >::bodyVelocity, FloatingBaseModel< T >::contactJacobians(), ori::coordinateRotation(), FloatingBaseModel< T >::invContactInertia(), FloatingBaseModel< T >::massMatrix(), FBModelState< T >::q, FBModelState< T >::qd, ori::rotationMatrixToQuaternion(), and FloatingBaseModel< T >::setState().

40  {
41  FloatingBaseModel<double> cheetahModel = buildCheetah3<double>().buildModel();
42 
43  RotMat<double> rBody = coordinateRotation(CoordinateAxis::X, .123) *
44  coordinateRotation(CoordinateAxis::Z, .232) *
45  coordinateRotation(CoordinateAxis::Y, .111);
46  SVec<double> bodyVel;
47  bodyVel << 1, 2, 3, 4, 5, 6;
49  DVec<double> q(12);
50  DVec<double> dq(12);
51  DVec<double> tauref(12);
52  for (size_t i = 0; i < 12; i++) {
53  q[i] = i + 1;
54  dq[i] = (i + 1) * 2;
55  tauref[i] = (i + 1) * -30.;
56  }
57 
58  // set state
59  x.bodyOrientation = rotationMatrixToQuaternion(rBody.transpose());
60  x.bodyVelocity = bodyVel;
61  x.bodyPosition = Vec3<double>(6, 7, 8);
62  x.q = q;
63  x.qd = dq;
64 
65  // do aba
66  cheetahModel.setState(x);
67 
68  cheetahModel.contactJacobians();
69  DMat<double> H = cheetahModel.massMatrix();
70  D3Mat<double> J0 = cheetahModel._Jc[15];
71  DMat<double> LambdaInv1 = J0 * H.colPivHouseholderQr().solve(J0.transpose());
72 
73  D6Mat<double> forceOnly = D6Mat<double>::Zero(6, 3);
74  forceOnly.bottomRows<3>() = Mat3<double>::Identity();
75 
76  DMat<double> LambdaInv2 = cheetahModel.invContactInertia(15, forceOnly);
77 
78  EXPECT_TRUE(almostEqual(LambdaInv1, LambdaInv2, .001));
79 }
Vec3< T > bodyPosition
SVec< T > bodyVelocity
typename Eigen::Matrix< T, 6, Eigen::Dynamic > D6Mat
Definition: cppTypes.h:110
Mat3< T > coordinateRotation(CoordinateAxis axis, T theta)
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
typename Eigen::Matrix< T, 3, Eigen::Dynamic > D3Mat
Definition: cppTypes.h:114
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
Quat< typename T::Scalar > rotationMatrixToQuaternion(const Eigen::MatrixBase< T > &r1)
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
void setState(const FBModelState< T > &state)
DMat< T > invContactInertia(const int gc_index, const D6Mat< T > &force_directions)
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec
Definition: cppTypes.h:102
vectorAligned< D3Mat< T > > _Jc
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Quat< T > bodyOrientation

+ Here is the call graph for this function:

TEST ( Cheetah3  ,
simulatorTestForceCheetah3   
)

Check a test force for cheetah 3 Set a weird body orientation, velocity, q, dq, and tau Checks the result matches qdd = H^(-1) J^T F

Definition at line 86 of file test_cheetah3_model.cpp.

References FloatingBaseModel< T >::_Jc, almostEqual(), FloatingBaseModel< T >::applyTestForce(), FBModelState< T >::bodyOrientation, FBModelState< T >::bodyPosition, FBModelState< T >::bodyVelocity, FloatingBaseModel< T >::contactJacobians(), ori::coordinateRotation(), FBModelStateDerivative< T >::dBodyVelocity, FloatingBaseModel< T >::invContactInertia(), FloatingBaseModel< T >::massMatrix(), FBModelState< T >::q, FBModelState< T >::qd, FBModelStateDerivative< T >::qdd, ori::rotationMatrixToQuaternion(), and FloatingBaseModel< T >::setState().

86  {
87  FloatingBaseModel<double> cheetahModel = buildCheetah3<double>().buildModel();
88 
89  RotMat<double> rBody = coordinateRotation(CoordinateAxis::X, .123) *
90  coordinateRotation(CoordinateAxis::Z, .232) *
91  coordinateRotation(CoordinateAxis::Y, .111);
92  SVec<double> bodyVel;
93  bodyVel << 1, 2, 3, 4, 5, 6;
95  DVec<double> q(12);
96  DVec<double> dq(12);
97  DVec<double> tauref(12);
98  for (size_t i = 0; i < 12; i++) {
99  q[i] = i + 1;
100  dq[i] = (i + 1) * 2;
101  tauref[i] = (i + 1) * -30.;
102  }
103 
104  // set state
105  x.bodyOrientation = rotationMatrixToQuaternion(rBody.transpose());
106  x.bodyVelocity = bodyVel;
107  x.bodyPosition = Vec3<double>(6, 7, 8);
108  x.q = q;
109  x.qd = dq;
110 
112  dx.qdd.setZero(12);
113 
114  cheetahModel.setState(x);
115 
116  cheetahModel.contactJacobians();
117  DMat<double> H = cheetahModel.massMatrix();
118  DMat<double> J0 = cheetahModel._Jc[15].bottomRows(1);
119 
120  Vec3<double> zforce;
121  zforce << 0, 0, 1;
122 
123  double foot_accel_in_z = cheetahModel.applyTestForce(15, zforce, dx);
124 
125  DVec<double> qddFull = H.colPivHouseholderQr().solve(J0.transpose());
126  DMat<double> LambdaInv = J0 * qddFull;
127 
128  SVec<double> dBodyVelocity = qddFull.head<6>();
129  DVec<double> qdd = qddFull.tail(12);
130 
131  double foot_accel_2 = LambdaInv(0, 0);
132 
133  double LambdaInv2 = cheetahModel.invContactInertia(15, zforce);
134 
135  EXPECT_TRUE(almostEqual(dBodyVelocity, dx.dBodyVelocity, .001));
136  EXPECT_TRUE(almostEqual(qdd, dx.qdd, 1e-6));
137  EXPECT_TRUE(abs(foot_accel_2 - foot_accel_in_z) < .001);
138  EXPECT_TRUE(abs(LambdaInv2 - foot_accel_in_z) < .001);
139 
140  qdd(0) += 5;
141  EXPECT_FALSE(almostEqual(qdd, dx.qdd, 1e-6));
142 }
Vec3< T > bodyPosition
SVec< T > bodyVelocity
Mat3< T > coordinateRotation(CoordinateAxis axis, T theta)
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
Quat< typename T::Scalar > rotationMatrixToQuaternion(const Eigen::MatrixBase< T > &r1)
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
void setState(const FBModelState< T > &state)
DMat< T > invContactInertia(const int gc_index, const D6Mat< T > &force_directions)
T applyTestForce(const int gc_index, const Vec3< T > &force_ics_at_contact, FBModelStateDerivative< T > &dstate_out)
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec
Definition: cppTypes.h:102
vectorAligned< D3Mat< T > > _Jc
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Quat< T > bodyOrientation

+ Here is the call graph for this function: