ocra-recipes
Doxygen documentation for the ocra-recipes repository
DynamicEquationFunction.cpp
Go to the documentation of this file.
2 #include "ocra/control/Model.h"
3 #include "ocra/optim/Variable.h"
4 #include <sstream>
5 
6 namespace ocra
7 {
8  DynamicEquationFunction::DynamicEquationFunction(const Model& model)
9  :NamedInstance("Dynamic Equation Function")
12  ,LinearFunction(createDEVariable(model), model.nbDofs())
13  , _model(model), _q_ddot(model.getAccelerationVariable()), _tau(model.getJointTorqueVariable())
14  , _f(model.getModelContacts().getContactForcesVariable())
15  {
16  buildA();
17 
20  }
21 
23  {
26  delete &getVariable();
27  }
28 
29  Variable& DynamicEquationFunction::createDEVariable(const Model& model)
30  {
31  static int cpt = 0;
32  std::stringstream name;
33  name << "de" << cpt++;
34  CompositeVariable* var = new CompositeVariable(name.str(), model.getAccelerationVariable());
35  var->add(model.getJointTorqueVariable());
37  return *var;
38  }
39 
41  {
43  }
44 
46  {
47  //A = (M -L J^t)
48  _jacobian.block(0, 0, _dim, _dim) = _model.getInertiaMatrix();
49  if (_f.getSize()>0)
51  }
52 
53  void DynamicEquationFunction::buildA()
54  {
55  _jacobian.setZero();
56  int index = _model.hasFixedRoot() ? 0 : 6;
57  _jacobian.block(0, _dim, _dim, _tau.getSize()).setZero();
58  _jacobian.block(index, _dim, _tau.getSize(), _tau.getSize()).diagonal() = -_model.getActuatedDofs();
59  }
60 
62  {
63  //do nothing : this overload allows to resize
64  }
65 
67  {
68  buildA();
69  }
70 }
71 
72 // cmake:sourcegroup=Functions
const Variable & getVariable() const
Definition: Function.cpp:46
Declaration file of the Model class.
virtual const Eigen::VectorXd & getActuatedDofs() const =0
Model class.
Definition: Model.h:38
LinearFunction class.
virtual const Eigen::VectorXd & getNonLinearTerms() const =0
Variable & getContactForcesVariable() const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
MatrixXd & _jacobian
Definition: Function.h:313
int getSize() const
Definition: Variable.cpp:81
void invalidateb(int timestamp)
This class represents a variable in a mathematical sense.
Definition: Variable.h:105
const Eigen::MatrixXd & getJct() const
Variable & getJointTorqueVariable() const
Definition: Model.cpp:138
Variable & getAccelerationVariable() const
Definition: Model.cpp:133
void invalidateAll()
Definition: Function.h:330
CompositeVariable & add(Variable &child)
Attach/detach the child to/from this node.
Definition: Variable.cpp:580
virtual const Eigen::MatrixXd & getInertiaMatrix() const =0
bool hasFixedRoot() const
Definition: Model.cpp:67
A concatenation of base variables and other composite variables.
Definition: Variable.h:357
virtual const Eigen::VectorXd & getLinearTerms() const =0
Declaration file of the DynamicEquationFunction class.
Declaration file of the Variable class.
const int & _dim
Definition: Function.h:320
void disconnect(Derived &object, void(Base::*callbackToErase)(int)) const
Disconnect non-static method.
void connect(Derived &object, void(Base::*newCallback)(int)) const
Call this method to register a non-static method as a callback.
ModelContacts & getModelContacts() const
Definition: Model.cpp:186