ocra-recipes
Doxygen documentation for the ocra-recipes repository
FullState.cpp
Go to the documentation of this file.
2 
3 #include "ocra/control/Model.h"
4 
5 namespace ocra
6 {
8  {
9  const Model& model;
10  int part;
11  int size;
12  MatrixXd J;
13 
14  Pimpl(const Model& m, int whichPart)
15  : model(m)
16  , part(whichPart)
17  , size(0)
18  {
19  switch(part)
20  {
21  case FULL_STATE:
22  size = m.nbDofs();
23  J = MatrixXd::Identity(size, size);
24  break;
25  case FREE_FLYER:
26  size = m.nbDofs() - m.nbInternalDofs();
27  J = MatrixXd::Zero(size, m.nbDofs());
28  J.leftCols(size).setIdentity();
29  break;
30  case INTERNAL:
31  size = m.nbInternalDofs();
32  J = MatrixXd::Zero(size, m.nbDofs());
33  J.rightCols(size).setIdentity();
34  break;
35  default:
36  throw std::runtime_error("[FullState::FullState] invalid specified part (specify FULL_STATE, FREE_FLYER or INTERNAL");
37  }
38  }
39  };
40 
41  FullState::FullState(const std::string& name, const Model& model, int whichPart)
42  : NamedInstance(name)
43  , pimpl( new Pimpl(model, whichPart) )
44  {
45  }
46 
48  {
49  }
50 
51  const Model& FullState::getModel() const
52  {
53  return pimpl->model;
54  }
55 
56  int FullState::getSize() const
57  {
58  return pimpl->size;
59  }
60 
61  const MatrixXd& FullState::getJacobian() const
62  {
63  return pimpl->J;
64  }
65 
67  {
68  return pimpl->part;
69  }
70 
71 
72 
74  {
75  MatrixXd M;
76  MatrixXd Minv;
77  VectorXd tau;
78  VectorXd qddot;
79  };
80 
81  FullModelState::FullModelState(const std::string& name, const Model& model, int whichPart)
82  : FullState(name, model, whichPart)
83  , pimpl( new Pimpl )
84  {
85  pimpl->tau = VectorXd::Zero(getSize());
86  pimpl->qddot = VectorXd::Zero(getSize());
87  }
88 
89  const Eigen::VectorXd& FullModelState::q() const
90  {
91  switch(whichPart())
92  {
93  case FREE_FLYER:
95  break;
96  case INTERNAL:
98  break;
99  default:
101  }
102  }
103 
104  const Eigen::VectorXd& FullModelState::qdot() const
105  {
106  switch(whichPart())
107  {
108  case FREE_FLYER:
110  break;
111  case INTERNAL:
113  break;
114  default:
116  }
117  }
118 
119  const Eigen::VectorXd& FullModelState::qddot() const
120  {
121  return pimpl->qddot;
122  }
123 
124  const Eigen::VectorXd& FullModelState::tau() const
125  {
126  return pimpl->tau;
127  }
128 
129  const MatrixXd& FullModelState::getInertiaMatrix() const
130  {
131  switch(whichPart())
132  {
133  case FREE_FLYER:
134  pimpl->M = getModel().getInertiaMatrix().block(0, 0, getSize(), getSize());
135  return pimpl->M;
136  break;
137  case INTERNAL:
138  pimpl->M = getModel().getInertiaMatrix().block(getModel().nbDofs()-getSize(), getModel().nbDofs()-getSize(), getSize(), getSize());
139  return pimpl->M;
140  break;
141  default:
142  return getModel().getInertiaMatrix();
143  }
144  }
145 
147  {
148  switch(whichPart())
149  {
150  case FREE_FLYER:
151  pimpl->Minv = getModel().getInertiaMatrixInverse().block(0, 0, getSize(), getSize());
152  return pimpl->Minv;
153  break;
154  case INTERNAL:
155  pimpl->Minv = getModel().getInertiaMatrixInverse().block(getModel().nbDofs()-getSize(), getModel().nbDofs()-getSize(), getSize(), getSize());
156  return pimpl->Minv;
157  break;
158  default:
160  }
161  }
162 
163 
165  {
166  Eigen::VectorXd q;
167  Eigen::VectorXd qdot;
168  Eigen::VectorXd qddot;
169  Eigen::VectorXd tau;
170  MatrixXd M;
171 
172  Pimpl(const Model& m)
173  {
174  }
175  };
176 
177  FullTargetState::FullTargetState(const std::string& name, const Model& model, int whichPart)
178  : FullState(name, model, whichPart)
179  , pimpl( new Pimpl(model) )
180  {
181  pimpl->q = VectorXd::Zero(getSize());
182  pimpl->qdot = VectorXd::Zero(getSize());
183  pimpl->qddot = VectorXd::Zero(getSize());
184  pimpl->tau = VectorXd::Zero(getSize());
185  pimpl->M = MatrixXd::Zero(getSize(), getSize());
186  }
187 
188  const Eigen::VectorXd& FullTargetState::q() const
189  {
190  return pimpl->q;
191  }
192 
193  const Eigen::VectorXd& FullTargetState::qdot() const
194  {
195  return pimpl->qdot;
196  }
197 
198  const Eigen::VectorXd& FullTargetState::qddot() const
199  {
200  return pimpl->qddot;
201  }
202 
203  const Eigen::VectorXd& FullTargetState::tau() const
204  {
205  return pimpl->tau;
206  }
207 
208  void FullTargetState::set_q(const Eigen::VectorXd& q)
209  {
210  pimpl->q = q;
211  }
212 
213  void FullTargetState::set_qdot(const Eigen::VectorXd& qdot)
214  {
215  pimpl->qdot = qdot;
216  }
217 
218  void FullTargetState::set_qddot(const Eigen::VectorXd& qddot)
219  {
220  pimpl->qddot = qddot;
221  }
222 
223  void FullTargetState::set_tau(const Eigen::VectorXd& tau)
224  {
225  pimpl->tau = tau;
226  }
227 
228  const MatrixXd& FullTargetState::getInertiaMatrix() const
229  {
230  return pimpl->M;
231  }
232 
234  {
235  return pimpl->M;
236  }
237 }
238 
239 // cmake:sourcegroup=Api
const Eigen::MatrixXd & getInertiaMatrixInverse() const
Definition: FullState.cpp:146
Variable & getRootVelocityVariable() const
Definition: Model.cpp:157
Variable & getInternalVelocityVariable() const
Definition: Model.cpp:163
Pimpl(const Model &m, int whichPart)
Definition: FullState.cpp:14
const Model & getModel() const
Definition: FullState.cpp:51
int nbInternalDofs() const
Definition: Model.cpp:59
const Eigen::VectorXd & q() const
Definition: FullState.cpp:188
const VectorXd & getValue() const
Definition: Variable.cpp:94
void set_qdot(const Eigen::VectorXd &qdot)
Definition: FullState.cpp:213
const Eigen::VectorXd & qdot() const
Definition: FullState.cpp:193
Declaration file of the Model class.
void set_q(const Eigen::VectorXd &q)
Definition: FullState.cpp:208
FullModelState(const std::string &name, const Model &model, int whichPart)
Definition: FullState.cpp:81
const Eigen::MatrixXd & getJacobian() const
Definition: FullState.cpp:61
Model class.
Definition: Model.h:38
const Model & model
Definition: FullState.cpp:9
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
const Eigen::VectorXd & qddot() const
Definition: FullState.cpp:119
const Eigen::VectorXd & tau() const
Definition: FullState.cpp:203
const Eigen::MatrixXd & getInertiaMatrix() const
Definition: FullState.cpp:228
Variable & getConfigurationVariable() const
Definition: Model.cpp:123
void set_tau(const Eigen::VectorXd &tau)
Definition: FullState.cpp:223
const Eigen::VectorXd & qdot() const
Definition: FullState.cpp:104
Variable & getRootConfigurationVariable() const
Definition: Model.cpp:143
Variable & getInternalConfigurationVariable() const
Definition: Model.cpp:149
int nbDofs() const
Definition: Model.cpp:54
virtual ~FullState()=0
Definition: FullState.cpp:47
int whichPart() const
Definition: FullState.cpp:66
int getSize() const
Definition: FullState.cpp:56
const Eigen::MatrixXd & getInertiaMatrix() const
Definition: FullState.cpp:129
const Eigen::MatrixXd & getInertiaMatrixInverse() const
Definition: FullState.cpp:233
virtual const Eigen::MatrixXd & getInertiaMatrix() const =0
FullState(const std::string &name, const Model &model, int whichPart)
Definition: FullState.cpp:41
const Eigen::VectorXd & tau() const
Definition: FullState.cpp:124
virtual const Eigen::MatrixXd & getInertiaMatrixInverse() const =0
const Eigen::VectorXd & q() const
Definition: FullState.cpp:89
FullTargetState(const std::string &name, const Model &model, int whichPart)
Definition: FullState.cpp:177
void set_qddot(const Eigen::VectorXd &qddot)
Definition: FullState.cpp:218
const Eigen::VectorXd & qddot() const
Definition: FullState.cpp:198
Variable & getVelocityVariable() const
Definition: Model.cpp:128