humoto
model_state.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
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 
7  @brief
8 */
9 
10 #pragma once
11 
12 namespace humoto
13 {
14  namespace pepper_mpc
15  {
16  /**
17  * @brief
18  */
20  {
21  #define HUMOTO_CONFIG_SECTION_ID "ModelState"
22  #define HUMOTO_CONFIG_CONSTRUCTOR ModelState
23  #define HUMOTO_CONFIG_ENTRIES \
24  HUMOTO_CONFIG_MEMBER_CLASS(base_state_, "base_state") \
25  HUMOTO_CONFIG_MEMBER_CLASS(body_state_, "body_state") \
26  HUMOTO_CONFIG_SCALAR_(base_mass) \
27  HUMOTO_CONFIG_SCALAR_(body_mass)
28  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
29 
30 
31  protected:
32  /**
33  * @brief Set default parameters
34  *
35  * @param[in] base_height
36  * @param[in] body_height
37  * @param[in] body_x_offset offset of the body with respect to the base
38  * @param[in] base_mass
39  * @param[in] body_mass
40  */
41  void setParameters( const double base_height = 0.125564931735602,
42  const double body_height = 7.50001340031501e-01,
43  const double body_x_offset = -0.00656061094036387,
44  //const double body_height = 0.763104597149514,
45  //const double body_x_offset = -0.00671291567566885,
46  const double base_mass = 16.34234,
47  const double body_mass = 12.3389)
48  {
49  // initialize com states
50  base_state_.setDefaults();
51  body_state_.setDefaults();
52 
53  base_state_.position_.z() = base_height; // Height of the CoM
54  base_state_.rpy_.z() = 0.0; // Orientation of the base
55 
56  body_state_.position_.z() = body_height; // Height of the CoM
57  body_state_.position_.x() = body_x_offset; // Height of the CoM
58 
59  base_mass_ = base_mass;
60  body_mass_ = body_mass;
61  }
62 
63 
64  void setDefaults()
65  {
66  setParameters();
67  }
68 
69 
70  public:
71  /// State of the base
73 
74  /// State of the body
76 
77  double base_mass_;
78  double body_mass_;
79 
80 
81  public:
82  /**
83  * @brief Default constructor
84  */
86  {
87  setDefaults();
88  }
89 
90 
91  /**
92  * @brief Construct class using given parameters.
93  *
94  * @param[in] base_height
95  * @param[in] body_height
96  * @param[in] body_x_offset offset of the body with respect to the base
97  */
98  ModelState( const double base_height,
99  const double body_height,
100  const double body_x_offset)
101  {
102  setParameters(body_height, base_height, body_x_offset);
103  }
104 
105 
106  /**
107  * @brief Construct class using given parameters.
108  *
109  * @param[in] base_mass
110  * @param[in] body_mass
111  * @param[in] base_position
112  * @param[in] body_position
113  */
114  ModelState( const double & base_mass,
115  const double & body_mass,
116  const etools::Vector3 & base_position,
117  const etools::Vector3 & body_position)
118  {
119  set(base_mass, body_mass, base_position, body_position);
120  }
121 
122 
123 
124  /**
125  * @brief Initialize state directly with the states of the CoM and feet.
126  *
127  * @param[in] base_state state of the base
128  * @param[in] body_state state of the body
129  */
130  void set( const humoto::rigidbody::RigidBodyState & base_state,
131  const humoto::rigidbody::PointMassState & body_state)
132  {
133  base_state_ = base_state;
134  body_state_ = body_state;
135  }
136 
137 
138  /**
139  * @brief Initialize state.
140  *
141  * @param[in] base_mass
142  * @param[in] body_mass
143  * @param[in] base_position
144  * @param[in] body_position
145  */
146  void set( const double & base_mass,
147  const double & body_mass,
148  const etools::Vector3 & base_position,
149  const etools::Vector3 & body_position)
150  {
151  base_mass_ = base_mass;
152  body_mass_ = body_mass;
153 
154 
155  base_state_.setDefaults();
156  body_state_.setDefaults();
157 
158  base_state_.position_ = base_position;
159  body_state_.position_ = body_position;
160  }
161 
162 
163  /**
164  * @brief Partial update of the state.
165  *
166  * @param[in] base_mass
167  * @param[in] body_mass
168  * @param[in] base_position
169  * @param[in] body_position
170  * @param[in] base_orientation
171  */
172  void update(const double & base_mass,
173  const double & body_mass,
174  const etools::Vector3 & base_position,
175  const etools::Vector3 & body_position,
176  const double & base_orientation)
177  {
178  base_mass_ = base_mass;
179  body_mass_ = body_mass;
180 
181  base_state_.position_ = base_position;
182  base_state_.rpy_.z() = base_orientation;
183 
184  body_state_.position_ = body_position;
185  }
186 
187 
188  /**
189  * @brief Log
190  *
191  * @param[in,out] logger logger
192  * @param[in] parent parent
193  * @param[in] name name
194  */
196  const LogEntryName &parent = LogEntryName(),
197  const std::string &name = "model_state") const
198  {
199  LogEntryName subname = parent; subname.add(name);
200 
201  logger.log(LogEntryName(subname).add("base_mass"), base_mass_);
202  logger.log(LogEntryName(subname).add("body_mass"), body_mass_);
203 
204  base_state_.log(logger, subname, "base_state");
205  body_state_.log(logger, subname, "body_state");
206  }
207  };
208  }
209 }
210 
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="model_state") const
Log.
Definition: model_state.h:195
Class that groups together parameters related to a robot foot.
#define HUMOTO_LOCAL
Definition: export_import.h:26
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
Definition: logger.h:997
Default configurable base is strict.
Definition: config.h:353
Represents log entry name.
Definition: logger.h:169
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="rigid_body_state") const
Log.
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="point_mass_state") const
Log.
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
Definition: logger.h:555
ModelState(const double &base_mass, const double &body_mass, const etools::Vector3 &base_position, const etools::Vector3 &body_position)
Construct class using given parameters.
Definition: model_state.h:114
void update(const double &base_mass, const double &body_mass, const etools::Vector3 &base_position, const etools::Vector3 &body_position, const double &base_orientation)
Partial update of the state.
Definition: model_state.h:172
ModelState(const double base_height, const double body_height, const double body_x_offset)
Construct class using given parameters.
Definition: model_state.h:98
ModelState()
Default constructor.
Definition: model_state.h:85
humoto::rigidbody::PointMassState body_state_
State of the body.
Definition: model_state.h:75
The root namespace of HuMoTo.
Definition: config.h:12
Class that groups together parmeters related to a robot foot.
humoto::rigidbody::RigidBodyState base_state_
State of the base.
Definition: model_state.h:72
Abstract class to be used for interfaces.
Definition: model.h:18
void setDefaults()
Set members to their default values.
Definition: model_state.h:64
LogEntryName & add(const char *name)
extends entry name with a subname
Definition: logger.h:232
void setDefaults()
Initialize state (everything is set to zeros).
void setParameters(const double base_height=0.125564931735602, const double body_height=7.50001340031501e-01, const double body_x_offset=-0.00656061094036387, const double base_mass=16.34234, const double body_mass=12.3389)
Set default parameters.
Definition: model_state.h:41
void setDefaults()
Initialize state (everything is set to zeros).