humoto
model.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @author Jan Michalczyk
5  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
6  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @brief
9 */
10 
11 #pragma once
12 
13 namespace humoto
14 {
15  namespace pepper_mpc
16  {
17  /**
18  * @brief
19  */
22  {
23  private:
24  /**
25  * @brief Determines position of the base.
26  */
27  void finalize()
28  {
29  current_base_position_ = state_.base_state_.position_.head(2);
30  }
31 
32 
33  public:
34  /// state of the model
36 
37  /// robot parameters
39 
40  /// 2d position of the base
41  etools::Vector2 current_base_position_;
42 
43 
44  public:
45  /**
46  * @brief Default constructor
47  */
49  {
50  finalize();
51  }
52 
53 
54  /**
55  * @brief Construct and initialize robot parameters
56  */
57  explicit Model(const humoto::pepper_mpc::RobotParameters &robot_parameters)
58  {
59  setParameters(robot_parameters);
60  }
61 
62 
63  /**
64  * @brief Initialize robot parameters
65  */
66  void setParameters(const humoto::pepper_mpc::RobotParameters &robot_parameters)
67  {
68  robot_parameters_ = robot_parameters;
69  finalize();
70  }
71 
72 
73 
74  /**
75  * @brief Returns current body state.
76  *
77  * @return body state
78  */
80  {
81  return (state_.body_state_);
82  }
83 
84 
85  /**
86  * @brief Returns current base state.
87  *
88  * @return base state
89  */
91  {
92  return (state_.base_state_);
93  }
94 
95 
96  /**
97  * @brief Get MPC state
98  */
99  EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) getMPCState() const
100  {
101  EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) mpc_state;
102 
103  mpc_state = convertStateRBtoMPC(state_.base_state_, state_.body_state_);
104  return(mpc_state);
105  }
106 
107 
108  /**
109  * @brief Get base state
110  *
111  * @return base state
112  */
113  etools::Vector6 getMPCBaseState() const
114  {
115  return(getMPCBaseState(state_));
116  }
117 
118 
119  /**
120  * @brief Get body state
121  *
122  * @return body state
123  */
124  etools::Vector6 getMPCBodyState() const
125  {
126  return(getMPCBodyState(state_));
127  }
128 
129 
130 
131  /**
132  * @brief Get base state
133  *
134  * @param[in] model_state
135  *
136  * @return base state
137  */
138  etools::Vector6 getMPCBaseState(const humoto::pepper_mpc::ModelState & model_state) const
139  {
140  etools::Vector6 mpc_state;
141 
142  mpc_state = convertBaseStateRBtoMPC(model_state.base_state_);
143  return(mpc_state);
144  }
145 
146 
147  /**
148  * @brief Get body state
149  *
150  * @param[in] model_state
151  *
152  * @return body state
153  */
154  etools::Vector6 getMPCBodyState(const humoto::pepper_mpc::ModelState & model_state) const
155  {
156  etools::Vector6 mpc_state;
157 
158  mpc_state = convertBodyStateRBtoMPC(model_state.body_state_);
159  return(mpc_state);
160  }
161 
162 
163  /**
164  * @brief Get CoP position
165  *
166  * @return CoP position
167  */
168  etools::Vector2 getCoP() const
169  {
170  return (getCoP(state_));
171  }
172 
173 
174  /**
175  * @brief Get CoP position
176  *
177  * @param[in] model_state
178  *
179  * @return CoP position
180  */
181  etools::Vector2 getCoP(const humoto::pepper_mpc::ModelState & model_state) const
182  {
183  etools::Matrix1x3 Dps = getDps3(model_state.base_state_.position_.z(),
184  model_state.base_mass_,
185  model_state.body_mass_);
186 
187  etools::Matrix1x3 Dpd = getDpd3(model_state.body_state_.position_.z(),
188  model_state.base_mass_,
189  model_state.body_mass_);
190 
191  etools::Vector2 cop;
192 
193  cop = etools::GenericBlockKroneckerProduct<1,3>(Dps, 2)*getMPCBaseState(model_state)
194  +
195  etools::GenericBlockKroneckerProduct<1,3>(Dpd, 2)*getMPCBodyState(model_state);
196 
197  return (cop);
198  }
199 
200 
201 
202  /**
203  * @brief Get next state from the current state
204  *
205  * @param[out] model_state next model state
206  * @param[in] T timestep
207  * @param[in] Ts subsampling timestep (use Ts = T if not needed)
208  * @param[in] base_control control vector
209  * @param[in] body_control control vector
210  * @param[in] base_height base height
211  * @param[in] body_height body height
212  * @param[in] theta orientation of the base
213  */
215  const double T,
216  const double Ts,
217  const etools::Vector2 &base_control,
218  const etools::Vector2 &body_control,
219  const double base_height,
220  const double body_height,
221  const double theta) const
222  {
223  getNextState( model_state,
224  T,
225  Ts,
226  getMPCState(),
227  base_control,
228  body_control,
229  base_height,
230  body_height,
231  theta);
232  }
233 
234 
235 
236  /**
237  * @brief Get next state from the given state
238  *
239  * @param[out] model_state next model state
240  * @param[in] T timestep
241  * @param[in] Ts subsampling timestep (use Ts = T if not needed)
242  * @param[in] preceding_mpcstate mpc state
243  * @param[in] base_control control vector
244  * @param[in] body_control control vector
245  * @param[in] base_height base height
246  * @param[in] body_height body height
247  * @param[in] theta orientation of the base
248  */
250  const double T,
251  const double Ts,
252  const EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) & preceding_mpcstate,
253  const etools::Vector2 &base_control,
254  const etools::Vector2 &body_control,
255  const double base_height,
256  const double body_height,
257  const double theta) const
258  {
259  EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) mpc_state;
260 
261  mpc_state = evaluate(T, Ts, preceding_mpcstate, base_control, body_control);
262 
263  model_state.base_state_ = convertBaseStateMPCtoRB(mpc_state, base_height);
264  model_state.body_state_ = convertBodyStateMPCtoRB(mpc_state, body_height);
265 
266  model_state.base_state_.rpy_.z() = theta;
267  }
268 
269 
270 
271  /**
272  * @brief Get theta angle of the current state
273  *
274  * @return theta angle
275  */
276  double getTheta() const
277  {
278  return(getTheta(state_));
279  }
280 
281 
282  /**
283  * @brief Get theta angle of the given state
284  *
285  * @param[in] model_state
286  *
287  * @return theta angle
288  */
289  double getTheta(const humoto::pepper_mpc::ModelState & model_state) const
290  {
291  return(model_state.base_state_.rpy_.z());
292  }
293 
294 
295  /**
296  * @brief Get body height
297  *
298  * @return body height
299  */
300  double getBodyHeight() const
301  {
302  return (state_.body_state_.position_.z());
303  }
304 
305 
306  /**
307  * @brief Get base height
308  *
309  * @return base height
310  */
311  double getBaseHeight() const
312  {
313  return (state_.base_state_.position_.z());
314  }
315 
316 
317 
318  /**
319  * @brief Get body mass
320  *
321  * @return body mass
322  */
323  double getBodyMass() const
324  {
325  return (state_.body_mass_);
326  }
327 
328 
329  /**
330  * @brief Get base mass
331  *
332  * @return base mass
333  */
334  double getBaseMass() const
335  {
336  return (state_.base_mass_);
337  }
338 
339 
340  /**
341  * @brief Get base orientation
342  *
343  * @return base orientation
344  */
345  double getBaseOrientation() const
346  {
347  return (state_.base_state_.rpy_.z());
348  }
349 
350 
351  /**
352  * @brief Update model state.
353  *
354  * @param[in] model_state model state.
355  */
356  void updateState(const humoto::ModelState &model_state)
357  {
358  const humoto::pepper_mpc::ModelState &state = dynamic_cast <const humoto::pepper_mpc::ModelState &> (model_state);
359  state_ = state;
360  finalize();
361  }
362 
363 
364  /**
365  * @brief Log
366  *
367  * @param[in,out] logger logger
368  * @param[in] parent parent
369  * @param[in] name name
370  */
372  const LogEntryName &parent = LogEntryName(),
373  const std::string &name = "model") const
374  {
375  LogEntryName subname = parent; subname.add(name);
376 
377  state_.log(logger, subname, "state");
378 
379  logger.log(LogEntryName(subname).add("mpc_state") , getMPCState());
380  logger.log(LogEntryName(subname).add("current_base_position"), current_base_position_);
381  }
382  };
383  }
384 }
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="model_state") const
Log.
Definition: model_state.h:195
humoto::rigidbody::RigidBodyState getBaseState() const
Returns current base state.
Definition: model.h:90
void getNextState(humoto::pepper_mpc::ModelState &model_state, const double T, const double Ts, const etools::Vector2 &base_control, const etools::Vector2 &body_control, const double base_height, const double body_height, const double theta) const
Get next state from the current state.
Definition: model.h:214
double getBodyHeight() const
Get body height.
Definition: model.h:300
Class that groups together parameters related to a robot foot.
#define HUMOTO_LOCAL
Definition: export_import.h:26
humoto::rigidbody::PointMassState getBodyState() const
Returns current body state.
Definition: model.h:79
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
Definition: logger.h:997
etools::Vector2 getCoP(const humoto::pepper_mpc::ModelState &model_state) const
Get CoP position.
Definition: model.h:181
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:86
void updateState(const humoto::ModelState &model_state)
Update model state.
Definition: model.h:356
Represents log entry name.
Definition: logger.h:169
double getBaseMass() const
Get base mass.
Definition: model.h:334
etools::Vector2 getCoP() const
Get CoP position.
Definition: model.h:168
EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) getMPCState() const
Get MPC state.
Definition: model.h:99
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="model") const
Log.
Definition: model.h:371
etools::Vector6 getMPCBaseState(const humoto::pepper_mpc::ModelState &model_state) const
Get base state.
Definition: model.h:138
etools::Vector6 getMPCBodyState(const humoto::pepper_mpc::ModelState &model_state) const
Get body state.
Definition: model.h:154
double getTheta() const
Get theta angle of the current state.
Definition: model.h:276
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
Definition: logger.h:555
etools::Vector6 getMPCBodyState() const
Get body state.
Definition: model.h:124
etools::Vector2 current_base_position_
2d position of the base
Definition: model.h:41
double getBaseOrientation() const
Get base orientation.
Definition: model.h:345
double getBaseHeight() const
Get base height.
Definition: model.h:311
humoto::rigidbody::PointMassState body_state_
State of the body.
Definition: model_state.h:75
The root namespace of HuMoTo.
Definition: config.h:12
humoto::pepper_mpc::RobotParameters robot_parameters_
robot parameters
Definition: model.h:38
Class that groups together parmeters related to a robot foot.
humoto::rigidbody::RigidBodyState base_state_
State of the base.
Definition: model_state.h:72
Instances of this class are passed to a virtual method &#39;humoto::TaskBase::form()&#39;, so even though this class is basically useless in its present form we cannot avoid its definition using a template.
Definition: model.h:41
void finalize()
Determines position of the base.
Definition: model.h:27
etools::Vector6 getMPCBaseState() const
Get base state.
Definition: model.h:113
Parameters of the motion.
Definition: common.h:24
Abstract class to be used for interfaces.
Definition: model.h:18
Model(const humoto::pepper_mpc::RobotParameters &robot_parameters)
Construct and initialize robot parameters.
Definition: model.h:57
EIGENTOOLS_CONSTANT_SIZE_MATRIX Matrix1x3
Definition: eigentools.h:87
Model()
Default constructor.
Definition: model.h:48
void setParameters(const humoto::pepper_mpc::RobotParameters &robot_parameters)
Initialize robot parameters.
Definition: model.h:66
LogEntryName & add(const char *name)
extends entry name with a subname
Definition: logger.h:232
double getTheta(const humoto::pepper_mpc::ModelState &model_state) const
Get theta angle of the given state.
Definition: model.h:289
void getNextState(humoto::pepper_mpc::ModelState &model_state, const double T, const double Ts, const EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) &preceding_mpcstate, const etools::Vector2 &base_control, const etools::Vector2 &body_control, const double base_height, const double body_height, const double theta) const
Get next state from the given state.
Definition: model.h:249
#define EIGENTOOLS_CONSTANT_SIZE_VECTOR(rows)
Definition: eigentools.h:58
double getBodyMass() const
Get body mass.
Definition: model.h:323
humoto::pepper_mpc::ModelState state_
state of the model
Definition: model.h:35