ocra-recipes
Doxygen documentation for the ocra-recipes repository
SecondOrderLinearTask.cpp
Go to the documentation of this file.
4 #include <sstream>
5 
6 namespace ocra
7 {
8  SecondOrderLinearTask::SecondOrderLinearTask(Function& f, Function& L)
9  :NamedInstance("second order linear task")
12  ,LinearFunction(f.getVariable().getTimeDerivative().getTimeDerivative(), f.getDimension())
13  , _f(&f)
14  , _L(&L)
15  , _saturate(false)
16  {
17  //check
18  //ocra_assert(f.canCompute<FUN_DOT>() && "function f needs to provide its time derivative.");
20 
21  if (f.getDimension()*2 != L.getVariable().getSize())
22  throw std::runtime_error("[ocra::LinearTask::LinearTask] Input size of L doesn't match with dimension of f");
23  if (f.getDimension() != L.getDimension())
24  throw std::runtime_error("[ocra::LinearTask::LinearTask] Dimension of L doesn't match with dimension of f");
25 
26  //dependencies
29  f.connect<EVT_RESIZE>(*this, &SecondOrderLinearTask::updateDimension);
31  }
32 
34  {
37  _f->disconnect<EVT_RESIZE>(*this, &SecondOrderLinearTask::updateDimension);
39  }
40 
41  void SecondOrderLinearTask::updateb() const
42  {
44  CompositeVariable* v = static_cast<CompositeVariable*>(&_L->getVariable());
45  (*v)(0).setValue(_f->getValue());
46  if (_f->canCompute<FUN_DOT>())
47  (*v)(1).setValue(_f->get<FUN_DOT>());
48  else
49  (*v)(1).setValue(_f->getJacobian()*_f->getVariable().getValue());
51  _b = _L->getValue();
52 
53  if (_saturate)
54  {
55  double max = _b.cwiseAbs().maxCoeff();
56  if (max>_accelerationMax)
57  {
58  double factor = _accelerationMax/max;
59  _b *= factor;
60  }
61  }
62 
65  else if (_f->canCompute<PARTIAL_X_DOT>())
67  }
68 
69 
71  {
72  VectorXd w0(f->getDimension());
73  VectorXd w1(f->getDimension());
74  w0.fill(weight0);
75  w1.fill(weight1);
77  }
78 
79 
81  {
84  int n = v1->getSize();
85  std::stringstream vname;
86  vname << v1->getName() << v2->getName();
87  CompositeVariable* v = new CompositeVariable(vname.str(),*v1,*v2);
88  LinearFunction* L = new DoubleDiagonalLinearFunction(*v, weight0, weight1, 0., true, weight0[n-1], weight1[n-1]);
89  return new SecondOrderLinearTask(*f, *L);
90  }
91 
92  void SecondOrderLinearTask::updateJacobian() const
93  {
95  }
96 
97  void SecondOrderLinearTask::doUpdateInputSizeBegin()
98  {
99  //do nothing : this overload allows to resize
100  }
101 
102  void SecondOrderLinearTask::doUpdateDimensionBegin(int newDimension)
103  {
104  //do nothing : this overload allows to resize
105  }
106 
107  void SecondOrderLinearTask::doUpdateDimensionEnd(int oldDimension)
108  {
109  assert(!_L->getVariable().isBaseVariable() && "Variable of L is supposed to be a composite variable with two base variables.");
110  CompositeVariable* v = static_cast<CompositeVariable*>(&_L->getVariable());
111  assert((*v)(0).isBaseVariable() && "only base variables can be resized");
112  assert((*v)(1).isBaseVariable() && "only base variables can be resized");
113  static_cast<BaseVariable*>(&(*v)(0))->resize(_f->getDimension());
114  static_cast<BaseVariable*>(&(*v)(1))->resize(_f->getDimension());
115  LinearFunction::doUpdateDimensionEnd(oldDimension); //to resize _b
116  }
117 
118  void SecondOrderLinearTask::updateDimension(int timestamp)
119  {
121  }
122 }
123 
124 // cmake:sourcegroup=Function
const Variable & getVariable() const
Definition: Function.cpp:46
virtual Variable & getTimeDerivative()
Get the time derivative/primitive of the variable.
Definition: Variable.cpp:106
virtual const std::string & getName() const
Definition: Variable.cpp:164
void desinhibitPropagationFromb() const
int getDimension() const
Definition: Function.cpp:41
Variable * createOutputVariable(Function &f)
const VectorXd & getValue() const
Definition: Variable.cpp:94
static SecondOrderLinearTask * createSecondOrderLinearTaskWithLinearLaw(Function *f, double weight0, double weight1)
size_t getNumberOfChildren() const
Returns 0 in BaseVariable and the number of childhoods otherwise.
Definition: Variable.cpp:223
DoubleDiagonalLinearFunction class.
LinearFunction class.
Declaration file of the FunctionProperties class.
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
virtual void doUpdateDimensionEnd(int oldDimension)
Definition: Function.cpp:114
Function class.
Definition: Function.h:77
MatrixXd & _jacobian
Definition: Function.h:313
Declaration file of the DoubleDiagonalLinearFunction class.
const IFunction< Ability >::return_type & get() const
Definition: Function.h:353
const MatrixXd & getJacobian() const
Definition: Function.h:375
bool canCompute() const
Definition: Function.h:347
int getSize() const
Definition: Variable.cpp:81
void invalidateb(int timestamp)
This class represents a variable in a mathematical sense.
Definition: Variable.h:105
void inhibitPropagationFromb() const
const VectorXd & getValue() const
Definition: Function.h:365
Declaration file of the SecondOrderLinearTask class.
void resize(size_t newSize)
Definition: Variable.cpp:344
double real
Definition: MathTypes.h:27
void changeFunctionDimension(int newDimension)
Definition: Function.cpp:56
void invalidateAll()
Definition: Function.h:330
A concatenation of base variables and other composite variables.
Definition: Variable.h:357
#define ocra_assert(ocra_expression)
Definition: ocra_assert.h:45
SecondOrderLinearTask class.
virtual bool isBaseVariable() const
Definition: Variable.cpp:169
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.
Implements a basic variable.
Definition: Variable.h:304