humoto
two_point_mass_model.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Jan Michalczyk
4  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
5  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6  @brief
7 */
8 
9 #pragma once
10 
11 namespace humoto
12 {
13  namespace pepper_mpc
14  {
15  /**
16  * @brief Two Point Mass Model
17  *
18  * This class generates matrices of the following systems:
19  *
20  * 1) simple:
21  * c(k+1) = A c(k) + B cjerk(k+1)
22  * p(k) = D c(k)
23  *
24  * 2) final:
25  * c(k+1) = A c(k) + Bs us(k) + Bd RS(k+1) ud(k)
26  * p(k) = Dps c(k)
27  * cjerk(k) = Dcjerk c(k) + Escjerk us(k) + Edcjerk RS(k+1) ud(k)
28  */
30  {
31  public:
32  // number of state varaibles
33  const std::size_t Ns_;
34  // number of control varaibles
35  const std::size_t Nu_;
36 
37 
38  public:
39  /**
40  * @brief Constructor
41  */
42  TwoPointMassModel() : Ns_(12), Nu_(4)
43  {
44  }
45 
46 
47 
48  /**
49  * @brief Create intermediate As3 matrix
50  *
51  * @param[in] T timestep
52  * @return 3x3 matrix
53  */
54  etools::Matrix3 getAs3(const double T) const
55  {
56  return(getAVel<1>(T));
57  }
58 
59 
60  /**
61  * @brief Create intermediate Ad3 matrix
62  *
63  * @param[in] T timestep
64  * @return 3x3 matrix
65  */
66  etools::Matrix3 getAd3(const double T) const
67  {
68  return(getAJerk<1>(T));
69  }
70 
71 
72  /**
73  * @brief Create intermediate Bs3 matrix
74  *
75  * @param[in] T timestep
76  * @return Bs6 matrix
77  */
78  etools::Vector3 getBs3(const double T) const
79  {
80  return(getBVel<1>(T));
81  }
82 
83 
84  /**
85  * @brief Create intermediate Bd3 matrix
86  *
87  * @param[in] T timestep
88  * @return Bd6 matrix
89  */
90  etools::Vector3 getBd3(const double T) const
91  {
92  return(getBJerk<1>(T));
93  }
94 
95 
96  /**
97  * @brief Create Dps3 matrix
98  *
99  * @param[in] base_height CoM of base height
100  * @param[in] base_mass base mass
101  * @param[in] body_mass body mass
102  * @return matrix
103  */
104  etools::Matrix1x3 getDps3( const double base_height,
105  const double base_mass,
106  const double body_mass) const
107  {
109  D << -body_mass, 0., -base_mass * (base_height / humoto::g_gravitational_acceleration);
110 
111  return(1./(base_mass + body_mass) * D);
112  }
113 
114 
115  /**
116  * @brief Create Dpd3 matrix
117  *
118  * @param[in] body_height CoM of body height
119  * @param[in] base_mass base mass
120  * @param[in] body_mass body mass
121  * @return matrix
122  */
123  etools::Matrix1x3 getDpd3( const double body_height,
124  const double base_mass,
125  const double body_mass) const
126  {
128  D << body_mass, 0., -body_mass * (body_height / humoto::g_gravitational_acceleration);
129 
130  return(1./(base_mass + body_mass) * D);
131  }
132 
133 
134 
135  /**
136  * @brief Create intermediate Dc6 matrix
137  * of final model
138  *
139  * @param[in] T timestep
140  * @return Dcjerk6 matrix
141  */
142  etools::Matrix1x3 getDjs3(const double T) const
143  {
144  return(getDVel<1>(T));
145  }
146 
147 
148  /**
149  * @brief Create intermediate Esc6 matrix
150  * of final model
151  *
152  * @param[in] T timestep
153  * @return Escjerk6 matrix
154  */
155  double getEjs3(const double T) const
156  {
157  return(getEVel<1>(T)(0,0));
158  }
159 
160 
161 
162  // convert body state to mpc state
163 
164 
165  /**
166  * @brief Get mpc base state
167  *
168  * @param[in] base_state base state
169  * @param[in] body_state body state
170  *
171  * @return mpc state
172  */
173  EIGENTOOLS_CONSTANT_SIZE_VECTOR(6) convertBaseStateRBtoMPC(const humoto::rigidbody::RigidBodyState& base_state) const
174  {
176  mpcstate << base_state.position_.x(),
177  base_state.velocity_.x(),
178  base_state.acceleration_.x(),
179  base_state.position_.y(),
180  base_state.velocity_.y(),
181  base_state.acceleration_.y();
182  return(mpcstate);
183  }
184 
185 
186  /**
187  * @brief Get mpc body state
188  *
189  * @param[in] base_state base state
190  * @param[in] body_state body state
191  *
192  * @return mpc state
193  */
194  EIGENTOOLS_CONSTANT_SIZE_VECTOR(6) convertBodyStateRBtoMPC(const humoto::rigidbody::PointMassState& body_state) const
195  {
197  mpcstate << body_state.position_.x(),
198  body_state.velocity_.x(),
199  body_state.acceleration_.x(),
200  body_state.position_.y(),
201  body_state.velocity_.y(),
202  body_state.acceleration_.y();
203  return(mpcstate);
204  }
205 
206 
207 
208  /**
209  * @brief Get mpc state
210  *
211  * @param[in] base_state base state
212  * @param[in] body_state body state
213  *
214  * @return mpc state
215  */
216  EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) convertStateRBtoMPC(const humoto::rigidbody::RigidBodyState& base_state,
217  const humoto::rigidbody::PointMassState& body_state) const
218  {
219  EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) mpcstate;
220  mpcstate << convertBaseStateRBtoMPC(base_state),
221  convertBodyStateRBtoMPC(body_state);
222  return(mpcstate);
223  }
224 
225 
226 
227  /**
228  * @brief Converts given mpcstate vector to base state
229  *
230  * @param[in] mpc_state mpc state vector
231  * @param[in] base_height body height
232  * @return base state
233  */
234  humoto::rigidbody::RigidBodyState convertBaseStateMPCtoRB( const EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) &mpcstate,
235  const double base_height) const
236  {
238 
239  base_state.position_ << mpcstate(0), mpcstate(3), base_height;
240  base_state.velocity_ << mpcstate(1), mpcstate(4), 0.0;
241  base_state.acceleration_ << mpcstate(2), mpcstate(5), 0.0;
242 
243  return(base_state);
244  }
245 
246 
247  /**
248  * @brief Converts given mpcstate vector to base and body states
249  *
250  * @param[in] mpc_state mpc state vector
251  * @param[in] body_height body height
252  * @return body state
253  */
254  humoto::rigidbody::PointMassState convertBodyStateMPCtoRB( const EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) &mpcstate,
255  const double body_height) const
256  {
258 
259  body_state.position_ << mpcstate(6), mpcstate(9), body_height;
260  body_state.velocity_ << mpcstate(7), mpcstate(10), 0.0;
261  body_state.acceleration_ << mpcstate(8), mpcstate(11), 0.0;
262 
263  return(body_state);
264  }
265 
266 
267  /**
268  * @brief Evaluate the state of the base
269  *
270  * @param[in] T timestep
271  * @param[in] Ts subsampling timestep (use Ts = T if not needed)
272  * @param[in] preceding_mpcstate mpc state
273  * @param[in] control control vector
274  * @param[in] rotation rotation matrix from base to global frame
275  *
276  * @return base state
277  */
278  EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) evaluate(
279  const double T,
280  const double Ts,
281  const EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) & preceding_mpcstate,
282  const etools::Vector2 &base_control,
283  const etools::Vector2 &body_control) const
284  {
285  etools::Vector4 control;
286 
287  control << base_control, body_control;
288 
289  return( getA12(T, Ts) * preceding_mpcstate
290  +
291  getB12(T, Ts) * control);
292  }
293 
294 
295  // final model
296 
297 
298  /**
299  * @brief Create A matrix of final model
300  *
301  * @param[in] T timestep
302  * @param[in] Ts subsampling timestep (use Ts = T if not needed)
303  * @return A matrix
304  */
305  Eigen::MatrixXd getA12(const double T, const double Ts) const
306  {
307  Eigen::MatrixXd A12;
309 
310  A12_bmi.setZero(4,4);
311 
312  if (Ts == T)
313  {
314  A12_bmi(0) = getAVel<1>(T);
315  }
316  else
317  {
318  A12_bmi(0) = getAsVel<1>(T, Ts);
319  }
320  A12_bmi(1) = A12_bmi(0);
321 
322  A12_bmi(2) = getAJerk<1>(Ts);
323  A12_bmi(3) = A12_bmi(2);
324 
325  return(A12);
326  }
327 
328 
329 
330  /**
331  * @brief Create Bs matrix of final model
332  *
333  * @param[in] T timestep
334  * @param[in] Ts subsampling timestep (use Ts = T if not needed)
335  * @return Bs matrix
336  */
337  Eigen::MatrixXd getB12(const double T, const double Ts) const
338  {
339  Eigen::MatrixXd B12;
341 
342  B12_bmi.setZero(4,4);
343 
344  if (Ts == T)
345  {
346  B12_bmi(0) = getBVel<1>(T);
347  }
348  else
349  {
350  B12_bmi(0) = getBsVel<1>(T, Ts);
351  }
352  B12_bmi(1) = B12_bmi(0);
353 
354  B12_bmi(2) = getBJerk<1>(Ts);
355  B12_bmi(3) = B12_bmi(2);
356 
357  return(B12);
358  }
359 
360 
361 
362 
363  /**
364  * @brief Create Djs matrix of final model
365  *
366  * @param[in] T timestep
367  * @return Dcjerk matrix
368  */
369  Eigen::MatrixXd getDj6(const double T) const
370  {
371  Eigen::MatrixXd D;
373 
374  D_bmi.setZero(2,2);
375  D_bmi(0) = getDVel<1>(T);
376  D_bmi(1) = D_bmi(0);
377 
378  return(D);
379  }
380 
381 
382  /**
383  * @brief Create Ejs matrix of final model
384  *
385  * @param[in] T timestep
386  * @return Escjerk matrix
387  */
388  Eigen::MatrixXd getEjs6(const double T) const
389  {
390  etools::Matrix2 E;
391 
392  E.setZero(2,2);
393  E(0,0) = getEVel<1>(T)(0,0);
394  E(1,1) = E(0,0);
395 
396  return(E);
397  }
398  };
399  } // pepper
400 } // humoto
Class that groups together parameters related to a robot foot.
#define HUMOTO_LOCAL
Definition: export_import.h:26
etools::Matrix3 getAd3(const double T) const
Create intermediate Ad3 matrix.
Triple integrator class Class supports arbitrary number of integrators in the system.
etools::Matrix1x3 getDps3(const double base_height, const double base_mass, const double body_mass) const
Create Dps3 matrix.
void setZero(const std::ptrdiff_t num_blocks_vert, const std::ptrdiff_t num_blocks_hor)
Resize matrix and initialize it with zeros.
etools::Matrix1x3 getDpd3(const double body_height, const double base_mass, const double body_mass) const
Create Dpd3 matrix.
etools::Vector3 getBd3(const double T) const
Create intermediate Bd3 matrix.
etools::Vector3 getBs3(const double T) const
Create intermediate Bs3 matrix.
etools::Matrix3 getAs3(const double T) const
Create intermediate As3 matrix.
The root namespace of HuMoTo.
Definition: config.h:12
Class that groups together parmeters related to a robot foot.
double getEjs3(const double T) const
Create intermediate Esc6 matrix of final model.
EIGENTOOLS_CONSTANT_SIZE_MATRIX Matrix1x3
Definition: eigentools.h:87
const double g_gravitational_acceleration
Gravitational acceleration.
Definition: constants.h:21
#define EIGENTOOLS_CONSTANT_SIZE_VECTOR(rows)
Definition: eigentools.h:58
etools::Matrix1x3 getDjs3(const double T) const
Create intermediate Dc6 matrix of final model.
Provides block interface for arbitrary Matrix without copying it.
Definition: blockmatrix.h:49
EIGENTOOLS_CONSTANT_SIZE_MATRIX Matrix2
Definition: eigentools.h:76
EIGENTOOLS_CONSTANT_SIZE_MATRIX Matrix3
Definition: eigentools.h:77