Cheetah Software  1.0
test_ControlParameters.cpp File Reference
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ControlParameters/ControlParameters.h"
#include "ControlParameters/RobotParameters.h"
#include "ControlParameters/SimulatorParameters.h"
#include "Math/MathUtilities.h"
+ Include dependency graph for test_ControlParameters.cpp:

Go to the source code of this file.

Classes

class  TestControlParameters
 
class  TestVectorControlParameters
 

Functions

 TEST (ControlParams, testSimple)
 
 TEST (ControlParams, testIni)
 
 TEST (ControlParams, testVector)
 
 TEST (ControlParams, testYaml)
 
 TEST (ControlParams, CheckSimulatorDefaults)
 
 TEST (ControlParams, CheckMiniCheetahDefaults)
 
 TEST (ControlParams, CheckCheetah3Defulats)
 
 TEST (ControlParams, CheckTypeRecognition)
 
 TEST (ControlParams, DefineFromYaml)
 

Function Documentation

TEST ( ControlParams  ,
testSimple   
)

Definition at line 47 of file test_ControlParameters.cpp.

References ControlParameter::_kind, ControlParameter::_name, ControlParameter::_set, ControlParameter::_value, ControlParameters::collection, ControlParameterValuePtr::d, DOUBLE, ControlParameterValuePtr::f, FLOAT, ControlParameterValuePtr::i, ControlParameters::initializeDouble(), ControlParameters::initializeFloat(), ControlParameters::initializeInteger(), ControlParameters::isFullyInitialized(), ControlParameterCollection::lookup(), and S64.

47  {
48  TestControlParameters settings;
49 
50  EXPECT_FALSE(settings.isFullyInitialized());
51 
52  EXPECT_THROW(settings.initializeInteger("test_double", 1),
53  std::runtime_error);
54  EXPECT_THROW(settings.initializeDouble("not-a-real-thing", 1.2),
55  std::runtime_error);
56 
57  settings.initializeDouble("test_double", 1.2);
58 
59  EXPECT_FALSE(settings.isFullyInitialized());
60  EXPECT_TRUE(1.2 == *settings.collection.lookup("test_double")._value.d);
62  settings.collection.lookup("test_double")._kind);
63  EXPECT_TRUE("test_double" == settings.collection.lookup("test_double")._name);
64  EXPECT_TRUE(settings.collection.lookup("test_double")._set);
65 
66  settings.initializeFloat("test_float", 1);
67  EXPECT_FALSE(settings.isFullyInitialized());
68  EXPECT_TRUE(1 == *settings.collection.lookup("test_float")._value.f);
70  settings.collection.lookup("test_float")._kind);
71  EXPECT_TRUE("test_float" == settings.collection.lookup("test_float")._name);
72  EXPECT_TRUE(settings.collection.lookup("test_float")._set);
73 
74  settings.initializeInteger("test_integer", 8);
75  EXPECT_TRUE(settings.isFullyInitialized());
76  EXPECT_TRUE(8 == *settings.collection.lookup("test_integer")._value.i);
77  EXPECT_TRUE(ControlParameterValueKind::S64 ==
78  settings.collection.lookup("test_integer")._kind);
79  EXPECT_TRUE("test_integer" ==
80  settings.collection.lookup("test_integer")._name);
81  EXPECT_TRUE(settings.collection.lookup("test_integer")._set);
82 }
ControlParameterCollection collection
ControlParameterValueKind _kind
ControlParameterValuePtr _value
void initializeDouble(const std::string &name, double d)
void initializeInteger(const std::string &name, s64 i)
ControlParameter & lookup(const std::string &name)
void initializeFloat(const std::string &name, float f)

+ Here is the call graph for this function:

TEST ( ControlParams  ,
testIni   
)

Definition at line 84 of file test_ControlParameters.cpp.

References f(), fpEqual(), ControlParameters::generateUnitializedList(), ControlParameters::initializeDouble(), ControlParameters::initializeFloat(), ControlParameters::initializeFromIniFile(), ControlParameters::initializeInteger(), ControlParameters::isFullyInitialized(), TestControlParameters::test_double, TestControlParameters::test_float, TestControlParameters::test_integer, and ControlParameters::writeToIniFile().

84  {
85  // create and initialize some parameters
86  TestControlParameters settings;
87  EXPECT_FALSE(settings.isFullyInitialized());
88  settings.initializeDouble("test_double", 2e-9);
89  settings.initializeFloat("test_float", 1);
90  settings.initializeInteger("test_integer", 8);
91  EXPECT_TRUE(settings.isFullyInitialized());
92 
93  // write to ini:
94  settings.writeToIniFile("control-params-test-file.ini");
95 
96  // read from ini
97  TestControlParameters settingsFromIni;
98  EXPECT_FALSE(settingsFromIni.isFullyInitialized());
99  settingsFromIni.initializeFromIniFile("control-params-test-file.ini");
100  printf("%s\n", settingsFromIni.generateUnitializedList().c_str());
101  EXPECT_TRUE(settingsFromIni.isFullyInitialized());
102 
103  EXPECT_TRUE(
104  fpEqual(settings.test_double, settingsFromIni.test_double, 1e-10));
105  EXPECT_TRUE(fpEqual(settings.test_float, settingsFromIni.test_float, 1e-5f));
106  EXPECT_TRUE(settings.test_integer == settingsFromIni.test_integer);
107 }
bool fpEqual(T a, T b, T tol)
Definition: utilities.h:15
void initializeDouble(const std::string &name, double d)
void initializeInteger(const std::string &name, s64 i)
void writeToIniFile(const std::string &path)
void initializeFloat(const std::string &name, float f)
void initializeFromIniFile(const std::string &path)
std::string generateUnitializedList()
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

TEST ( ControlParams  ,
testVector   
)

Definition at line 109 of file test_ControlParameters.cpp.

References almostEqual(), f(), ControlParameters::initializeFromYamlFile(), ControlParameters::initializeVec3d(), ControlParameters::initializeVec3f(), ControlParameters::isFullyInitialized(), TestVectorControlParameters::test_double, TestVectorControlParameters::test_float, and ControlParameters::writeToYamlFile().

109  {
111  EXPECT_FALSE(settings.isFullyInitialized());
112  Vec3<float> v3f(1, 2.2, 54.45);
113  Vec3<double> v3d(.01, 1e-3, -2.23e-7);
114  settings.initializeVec3f("test_float", v3f);
115  settings.initializeVec3d("test_double", v3d);
116  EXPECT_TRUE(settings.isFullyInitialized());
117 
118  settings.writeToYamlFile("test-yaml.yaml");
119 
120  TestVectorControlParameters settingsFromFile;
121  EXPECT_FALSE(settingsFromFile.isFullyInitialized());
122  settingsFromFile.initializeFromYamlFile("test-yaml.yaml");
123  EXPECT_TRUE(settingsFromFile.isFullyInitialized());
124 
125  EXPECT_TRUE(almostEqual(v3f, settingsFromFile.test_float, 1e-6f));
126  EXPECT_TRUE(almostEqual(v3d, settingsFromFile.test_double, 1e-10));
127 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
void writeToYamlFile(const std::string &path)
void initializeVec3d(const std::string &name, Vec3< double > &v)
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
void initializeVec3f(const std::string &name, Vec3< float > &v)
void initializeFromYamlFile(const std::string &path)
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

TEST ( ControlParams  ,
testYaml   
)

Definition at line 129 of file test_ControlParameters.cpp.

References f(), fpEqual(), ControlParameters::initializeDouble(), ControlParameters::initializeFloat(), ControlParameters::initializeFromYamlFile(), ControlParameters::initializeInteger(), ControlParameters::isFullyInitialized(), TestControlParameters::test_double, TestControlParameters::test_float, TestControlParameters::test_integer, and ControlParameters::writeToYamlFile().

129  {
130  // create and initialize some parameters
131  TestControlParameters settings;
132  EXPECT_FALSE(settings.isFullyInitialized());
133  settings.initializeDouble("test_double", 2e-9);
134  settings.initializeFloat("test_float", 1);
135  settings.initializeInteger("test_integer", 8);
136  EXPECT_TRUE(settings.isFullyInitialized());
137 
138  // write to yaml
139  settings.writeToYamlFile("control-params-test-file.yaml");
140 
141  // read from yaml
142  TestControlParameters settingsFromYaml;
143  EXPECT_FALSE(settingsFromYaml.isFullyInitialized());
144  settingsFromYaml.initializeFromYamlFile("control-params-test-file.yaml");
145  EXPECT_TRUE(settingsFromYaml.isFullyInitialized());
146 
147  EXPECT_TRUE(
148  fpEqual(settings.test_double, settingsFromYaml.test_double, 1e-10));
149  EXPECT_TRUE(fpEqual(settings.test_float, settingsFromYaml.test_float, 1e-5f));
150  EXPECT_TRUE(settings.test_integer == settingsFromYaml.test_integer);
151 }
bool fpEqual(T a, T b, T tol)
Definition: utilities.h:15
void initializeDouble(const std::string &name, double d)
void writeToYamlFile(const std::string &path)
void initializeInteger(const std::string &name, s64 i)
void initializeFloat(const std::string &name, float f)
void initializeFromYamlFile(const std::string &path)
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

TEST ( ControlParams  ,
CheckSimulatorDefaults   
)

Definition at line 155 of file test_ControlParameters.cpp.

References ControlParameters::generateUnitializedList(), getConfigDirectoryPath(), ControlParameters::initializeFromYamlFile(), ControlParameters::isFullyInitialized(), and SIMULATOR_DEFAULT_PARAMETERS.

155  {
156  SimulatorControlParameters simParams;
159  if (!simParams.isFullyInitialized()) {
160  printf("Missing parameters:\n%s\n",
161  simParams.generateUnitializedList().c_str());
162  }
163  EXPECT_TRUE(simParams.isFullyInitialized());
164 }
#define SIMULATOR_DEFAULT_PARAMETERS
std::string getConfigDirectoryPath()
Definition: utilities.cpp:30
void initializeFromYamlFile(const std::string &path)
std::string generateUnitializedList()

+ Here is the call graph for this function:

TEST ( ControlParams  ,
CheckMiniCheetahDefaults   
)

Definition at line 168 of file test_ControlParameters.cpp.

References ControlParameters::generateUnitializedList(), getConfigDirectoryPath(), ControlParameters::initializeFromYamlFile(), ControlParameters::isFullyInitialized(), and MINI_CHEETAH_DEFAULT_PARAMETERS.

168  {
169  RobotControlParameters robotParams;
172  if (!robotParams.isFullyInitialized()) {
173  printf("Missing parameters:\n%s\n",
174  robotParams.generateUnitializedList().c_str());
175  }
176  EXPECT_TRUE(robotParams.isFullyInitialized());
177 }
#define MINI_CHEETAH_DEFAULT_PARAMETERS
std::string getConfigDirectoryPath()
Definition: utilities.cpp:30
void initializeFromYamlFile(const std::string &path)
std::string generateUnitializedList()

+ Here is the call graph for this function:

TEST ( ControlParams  ,
CheckCheetah3Defulats   
)

Definition at line 181 of file test_ControlParameters.cpp.

References CHEETAH_3_DEFAULT_PARAMETERS, ControlParameters::generateUnitializedList(), getConfigDirectoryPath(), ControlParameters::initializeFromYamlFile(), and ControlParameters::isFullyInitialized().

181  {
182  RobotControlParameters robotParams;
185  if (!robotParams.isFullyInitialized()) {
186  printf("Missing parameters:\n%s\n",
187  robotParams.generateUnitializedList().c_str());
188  }
189  EXPECT_TRUE(robotParams.isFullyInitialized());
190 }
std::string getConfigDirectoryPath()
Definition: utilities.cpp:30
#define CHEETAH_3_DEFAULT_PARAMETERS
void initializeFromYamlFile(const std::string &path)
std::string generateUnitializedList()

+ Here is the call graph for this function:

TEST ( ControlParams  ,
DefineFromYaml   
)

Definition at line 201 of file test_ControlParameters.cpp.

References CHEETAH_3_DEFAULT_PARAMETERS, ControlParameters::collection, ControlParameters::defineAndInitializeFromYamlFile(), ControlParameterCollection::deleteAll(), getConfigDirectoryPath(), and MINI_CHEETAH_DEFAULT_PARAMETERS.

201  {
202  ControlParameters params("robot-parameters");
203  params.defineAndInitializeFromYamlFile(getConfigDirectoryPath() +
205 
206  params.collection.deleteAll();
207  params.defineAndInitializeFromYamlFile(getConfigDirectoryPath() + MINI_CHEETAH_DEFAULT_PARAMETERS);
208 
209  //printf("Result: \n %s\n", params.collection.printToIniString().c_str());
210 }
#define MINI_CHEETAH_DEFAULT_PARAMETERS
std::string getConfigDirectoryPath()
Definition: utilities.cpp:30
#define CHEETAH_3_DEFAULT_PARAMETERS

+ Here is the call graph for this function: