Cheetah Software  1.0
ControlParameter Class Reference

#include <ControlParameters.h>

+ Collaboration diagram for ControlParameter:

Public Member Functions

 ControlParameter (const std::string &name, double &value, ControlParameterCollection &collection, const std::string &units="")
 
 ControlParameter (const std::string &name, float &value, ControlParameterCollection &collection, const std::string &units="")
 
 ControlParameter (const std::string &name, s64 &value, ControlParameterCollection &collection, const std::string &units="")
 
 ControlParameter (const std::string &name, Vec3< float > &value, ControlParameterCollection &collection, const std::string &units="")
 
 ControlParameter (const std::string &name, Vec3< double > &value, ControlParameterCollection &collection, const std::string &units="")
 
 ControlParameter (const std::string &name, ControlParameterValueKind kind)
 
void truncateName ()
 
void initializeDouble (double d)
 
void initializeFloat (float f)
 
void initializeInteger (s64 i)
 
void initializeVec3f (const Vec3< float > &v)
 
void initializeVec3d (const Vec3< double > &v)
 
void set (ControlParameterValue value, ControlParameterValueKind kind)
 
ControlParameterValue get (ControlParameterValueKind kind)
 
std::string toString ()
 
bool setFromString (const std::string &value)
 

Public Attributes

bool _set = false
 
ControlParameterValuePtr _value
 
std::string _name
 
std::string _units
 
ControlParameterValueKind _kind
 
ControlParameterValue _staticValue
 

Detailed Description

Definition at line 120 of file ControlParameters.h.

Constructor & Destructor Documentation

ControlParameter::ControlParameter ( const std::string &  name,
double &  value,
ControlParameterCollection collection,
const std::string &  units = "" 
)
inline

Constructors for control parameters: Set the type and add to collection. Doesn't "initialize" the parameter - this must be done separately.

Definition at line 127 of file ControlParameters.h.

References ControlParameterCollection::addParameter(), and DOUBLE.

129  {
130  _name = name;
131  truncateName();
132  _units = units;
133  _value.d = &value;
135  collection.addParameter(this, name);
136  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value
void addParameter(ControlParameter *param, const std::string &name)

+ Here is the call graph for this function:

ControlParameter::ControlParameter ( const std::string &  name,
float &  value,
ControlParameterCollection collection,
const std::string &  units = "" 
)
inline

Definition at line 138 of file ControlParameters.h.

References ControlParameterCollection::addParameter(), and FLOAT.

140  {
141  _name = name;
142  truncateName();
143  _units = units;
144  _value.f = &value;
146  collection.addParameter(this, name);
147  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value
void addParameter(ControlParameter *param, const std::string &name)

+ Here is the call graph for this function:

ControlParameter::ControlParameter ( const std::string &  name,
s64 value,
ControlParameterCollection collection,
const std::string &  units = "" 
)
inline

Definition at line 149 of file ControlParameters.h.

References ControlParameterCollection::addParameter(), and S64.

151  {
152  _name = name;
153  truncateName();
154  _units = units;
155  _value.i = &value;
157  collection.addParameter(this, name);
158  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value
void addParameter(ControlParameter *param, const std::string &name)

+ Here is the call graph for this function:

ControlParameter::ControlParameter ( const std::string &  name,
Vec3< float > &  value,
ControlParameterCollection collection,
const std::string &  units = "" 
)
inline

Definition at line 160 of file ControlParameters.h.

References ControlParameterCollection::addParameter(), and VEC3_FLOAT.

162  {
163  _name = name;
164  truncateName();
165  _units = units;
166  _value.vec3f = value.data();
168  collection.addParameter(this, name);
169  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value
void addParameter(ControlParameter *param, const std::string &name)

+ Here is the call graph for this function:

ControlParameter::ControlParameter ( const std::string &  name,
Vec3< double > &  value,
ControlParameterCollection collection,
const std::string &  units = "" 
)
inline

Definition at line 171 of file ControlParameters.h.

References ControlParameterCollection::addParameter(), and VEC3_DOUBLE.

173  {
174  _name = name;
175  truncateName();
176  _units = units;
177  _value.vec3d = value.data();
179  collection.addParameter(this, name);
180  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value
void addParameter(ControlParameter *param, const std::string &name)

+ Here is the call graph for this function:

ControlParameter::ControlParameter ( const std::string &  name,
ControlParameterValueKind  kind 
)
inline

Definition at line 182 of file ControlParameters.h.

182  {
183  _name = name;
184  truncateName();
185  _kind = kind;
186  _value.vec3d = (double*)&_staticValue;
187  }
ControlParameterValueKind _kind
ControlParameterValue _staticValue
ControlParameterValuePtr _value

Member Function Documentation

ControlParameterValue ControlParameter::get ( ControlParameterValueKind  kind)
inline

Definition at line 282 of file ControlParameters.h.

References ControlParameterValue::d, DOUBLE, ControlParameterValue::f, FLOAT, ControlParameterValue::i, S64, VEC3_DOUBLE, VEC3_FLOAT, ControlParameterValue::vec3d, and ControlParameterValue::vec3f.

282  {
283  ControlParameterValue value;
284  if (kind != _kind) {
285  throw std::runtime_error("type mismatch in get");
286  }
287  switch (_kind) {
289  value.f = *_value.f;
290  break;
292  value.d = *_value.d;
293  break;
295  value.i = *_value.i;
296  break;
298  value.vec3f[0] = _value.vec3f[0];
299  value.vec3f[1] = _value.vec3f[1];
300  value.vec3f[2] = _value.vec3f[2];
301  break;
303  value.vec3d[0] = _value.vec3d[0];
304  value.vec3d[1] = _value.vec3d[1];
305  value.vec3d[2] = _value.vec3d[2];
306  break;
307  default:
308  throw std::runtime_error("invalid kind");
309  }
310  return value;
311  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value

+ Here is the caller graph for this function:

void ControlParameter::initializeDouble ( double  d)
inline

Set initial value of the control parameter. Checks to see that the types are correct

Definition at line 201 of file ControlParameters.h.

References DOUBLE.

201  {
203  throw std::runtime_error("Tried to initialize control parameter " +
204  _name + " as a double!");
205  }
206  _set = true;
207  *_value.d = d;
208  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value

+ Here is the caller graph for this function:

void ControlParameter::initializeFloat ( float  f)
inline

Definition at line 212 of file ControlParameters.h.

References f(), and FLOAT.

212  {
214  throw std::runtime_error("Tried to initialize control parameter " +
215  _name + " as a float!");
216  }
217  _set = true;
218  *_value.f = f;
219  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ControlParameter::initializeInteger ( s64  i)
inline

Definition at line 221 of file ControlParameters.h.

References S64.

221  {
223  throw std::runtime_error("Tried to initialize control parameter " +
224  _name + " as an integer!");
225  }
226  _set = true;
227  *_value.i = i;
228  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value

+ Here is the caller graph for this function:

void ControlParameter::initializeVec3d ( const Vec3< double > &  v)
inline

Definition at line 241 of file ControlParameters.h.

References VEC3_DOUBLE.

241  {
243  throw std::runtime_error("Tried to initialize control parameter " +
244  _name + " as a vector3d");
245  }
246  _set = true;
247  _value.vec3d[0] = v[0];
248  _value.vec3d[1] = v[1];
249  _value.vec3d[2] = v[2];
250  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value

+ Here is the caller graph for this function:

void ControlParameter::initializeVec3f ( const Vec3< float > &  v)
inline

Definition at line 230 of file ControlParameters.h.

References VEC3_FLOAT.

230  {
232  throw std::runtime_error("Tried to initialize control parameter " +
233  _name + " as a vector3f");
234  }
235  _set = true;
236  _value.vec3f[0] = v[0];
237  _value.vec3f[1] = v[1];
238  _value.vec3f[2] = v[2];
239  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value

+ Here is the caller graph for this function:

void ControlParameter::set ( ControlParameterValue  value,
ControlParameterValueKind  kind 
)
inline

Definition at line 252 of file ControlParameters.h.

References DOUBLE, FLOAT, S64, VEC3_DOUBLE, and VEC3_FLOAT.

252  {
253  if (kind != _kind) {
254  throw std::runtime_error("type mismatch in set");
255  }
256  switch (kind) {
258  *_value.f = value.f;
259  break;
261  *_value.d = value.d;
262  break;
264  *_value.i = value.i;
265  break;
267  _value.vec3f[0] = value.vec3f[0];
268  _value.vec3f[1] = value.vec3f[1];
269  _value.vec3f[2] = value.vec3f[2];
270  break;
272  _value.vec3d[0] = value.vec3d[0];
273  _value.vec3d[1] = value.vec3d[1];
274  _value.vec3d[2] = value.vec3d[2];
275  break;
276  default:
277  throw std::runtime_error("invalid kind");
278  }
279  _set = true;
280  }
ControlParameterValueKind _kind
ControlParameterValuePtr _value

+ Here is the caller graph for this function:

bool ControlParameter::setFromString ( const std::string &  value)
inline

Definition at line 348 of file ControlParameters.h.

References DOUBLE, FLOAT, S64, VEC3_DOUBLE, and VEC3_FLOAT.

348  {
349  switch (_kind) {
351  *_value.d = std::stod(value);
352  break;
354  *_value.f = std::stof(value);
355  break;
357  *_value.i = std::stoll(value);
358  break;
360  Vec3<float> v = stringToVec3<float>(value);
361  _value.vec3f[0] = v[0];
362  _value.vec3f[1] = v[1];
363  _value.vec3f[2] = v[2];
364  } break;
366  Vec3<double> v = stringToVec3<double>(value);
367  _value.vec3d[0] = v[0];
368  _value.vec3d[1] = v[1];
369  _value.vec3d[2] = v[2];
370  } break;
371  default:
372  return false;
373  }
374  return true;
375  }
ControlParameterValueKind _kind
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
ControlParameterValuePtr _value
std::string ControlParameter::toString ( )
inline

Convert the value to a string that works in a YAML file

Definition at line 316 of file ControlParameters.h.

References DOUBLE, FLOAT, numberToString(), S64, VEC3_DOUBLE, and VEC3_FLOAT.

316  {
317  std::string result;
318  switch (_kind) {
320  result += numberToString(*_value.d);
321  break;
323  result += numberToString(*_value.f);
324  break;
326  result += std::to_string(*_value.i);
327  break;
329  result += "[";
330  result += numberToString(_value.vec3f[0]) + ", ";
331  result += numberToString(_value.vec3f[1]) + ", ";
332  result += numberToString(_value.vec3f[2]) + "]";
333  break;
335  result += "[";
336  result += numberToString(_value.vec3d[0]) + ", ";
337  result += numberToString(_value.vec3d[1]) + ", ";
338  result += numberToString(_value.vec3d[2]) + "]";
339  break;
340  default:
341  result += "<unknown type " + std::to_string((u32)(_kind)) +
342  "> (add it yourself in ControlParameters.h!)";
343  break;
344  }
345  return result;
346  }
ControlParameterValueKind _kind
std::string numberToString(T number)
Definition: utilities.h:130
ControlParameterValuePtr _value
uint32_t u32
Definition: cTypes.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ControlParameter::truncateName ( )
inline

Definition at line 189 of file ControlParameters.h.

References CONTROL_PARAMETER_MAXIMUM_NAME_LENGTH.

189  {
191  printf("[Error] name %s is too long, shortening to ", _name.c_str());
193  printf("%s\n", _name.c_str());
194  }
195  }
#define CONTROL_PARAMETER_MAXIMUM_NAME_LENGTH

Member Data Documentation

ControlParameterValueKind ControlParameter::_kind

Definition at line 381 of file ControlParameters.h.

std::string ControlParameter::_name

Definition at line 379 of file ControlParameters.h.

bool ControlParameter::_set = false

Definition at line 377 of file ControlParameters.h.

ControlParameterValue ControlParameter::_staticValue

Definition at line 382 of file ControlParameters.h.

std::string ControlParameter::_units

Definition at line 380 of file ControlParameters.h.

ControlParameterValuePtr ControlParameter::_value

Definition at line 378 of file ControlParameters.h.


The documentation for this class was generated from the following file: