Cheetah Software  1.0
test_actuatorModel.cpp
Go to the documentation of this file.
1 
8 #include "Dynamics/Cheetah3.h"
9 #include "Dynamics/MiniCheetah.h"
10 #include "Dynamics/Quadruped.h"
11 
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
14 
15 TEST(ActuatorModel, miniCheetah) {
16  Quadruped<double> quad = buildMiniCheetah<double>();
17  auto actuatorModels = quad.buildActuatorModels();
18  auto& hipModel = actuatorModels[1];
19 
20  // first, disable friction
21  hipModel.setFriction(false);
22 
23  double tauMaxPositive = 0, tauMaxNegative = 0;
24  double maxQdMaxTorque = 0, qdMax = 0;
25 
26  // check our max torque in the positive direction:
27  for (double tau = 0; tau < 200; tau += .1) {
28  double tauAct = hipModel.getTorque(tau, 0);
29  if (!fpEqual(tau, tauAct, .0001)) {
30  tauMaxPositive = tauAct;
31  break;
32  }
33  }
34 
35  for (double tau = 0; tau > -200; tau -= .1) {
36  double tauAct = hipModel.getTorque(tau, 0);
37  if (!fpEqual(tau, tauAct, .0001)) {
38  tauMaxNegative = tauAct;
39  break;
40  }
41  }
42 
43  for (double qd = 0; qd < 40; qd += .01) {
44  double tauAct = hipModel.getTorque(18, qd);
45  if (!fpEqual(18., tauAct, .0001)) {
46  maxQdMaxTorque = qd;
47  break;
48  }
49  }
50 
51  for (double qd = 0; qd < 60; qd += .01) {
52  double tauAct = hipModel.getTorque(18, qd);
53  if (tauAct <= 0) {
54  qdMax = qd;
55  break;
56  }
57  }
58 
59  EXPECT_TRUE(fpEqual(tauMaxPositive, 18., .0001));
60  EXPECT_TRUE(fpEqual(tauMaxNegative, -18., .0001));
61  EXPECT_TRUE(fpEqual(maxQdMaxTorque, 28.47, .02));
62  EXPECT_TRUE(fpEqual(qdMax, 40., .0001));
63 }
64 
65 TEST(ActuatorModel, cheetah3) {
66  Quadruped<double> quad = buildCheetah3<double>();
67  auto actuatorModels = quad.buildActuatorModels();
68  auto& hipModel = actuatorModels[1];
69 
70  // first, disable friction
71  hipModel.setFriction(false);
72 
73  double tauMaxPositive = 0, tauMaxNegative = 0;
74  double maxQdMaxTorque = 0, qdMax = 0;
75 
76  // check our max torque in the positive direction:
77  for (double tau = 0; tau < 300; tau += .1) {
78  double tauAct = hipModel.getTorque(tau, 0);
79  if (!fpEqual(tau, tauAct, .0001)) {
80  tauMaxPositive = tauAct;
81  break;
82  }
83  }
84 
85  for (double tau = 0; tau > -300; tau -= .1) {
86  double tauAct = hipModel.getTorque(tau, 0);
87  if (!fpEqual(tau, tauAct, .0001)) {
88  tauMaxNegative = tauAct;
89  break;
90  }
91  }
92 
93  for (double qd = 0; qd < 40; qd += .01) {
94  double tauAct = hipModel.getTorque(208, qd);
95  if (!fpEqual(208., tauAct, .0001)) {
96  maxQdMaxTorque = qd;
97  break;
98  }
99  }
100 
101  for (double qd = 0; qd < 60; qd += .01) {
102  double tauAct = hipModel.getTorque(208, qd);
103  if (tauAct <= 0) {
104  qdMax = qd;
105  break;
106  }
107  }
108 
109  EXPECT_TRUE(fpEqual(tauMaxPositive, 208.6, .1));
110  EXPECT_TRUE(fpEqual(tauMaxNegative, -208.6, .1));
111  EXPECT_TRUE(fpEqual(maxQdMaxTorque, 8.44, .02));
112  EXPECT_TRUE(fpEqual(qdMax, 15.94, .1));
113 }
bool fpEqual(T a, T b, T tol)
Definition: utilities.h:15
Data structure containing parameters for quadruped robot.
Utility function to build a Cheetah 3 Quadruped object.
Utility function to build a Mini Cheetah Quadruped object.
TEST(ActuatorModel, miniCheetah)
std::vector< ActuatorModel< T > > buildActuatorModels()
Definition: Quadruped.cpp:225
Model of actuator Includes friction, max torque, and motor torque speed curve.