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 wpg04
15  {
17  {
18  #define HUMOTO_CONFIG_SECTION_ID "ModelState"
19  #define HUMOTO_CONFIG_CONSTRUCTOR ModelState
20  #define HUMOTO_CONFIG_ENTRIES \
21  HUMOTO_CONFIG_ENUM_(stance_type) \
22  HUMOTO_CONFIG_ENUM_(next_stance_type) \
23  HUMOTO_CONFIG_MEMBER_CLASS(com_state_, "com_state") \
24  HUMOTO_CONFIG_MEMBER_CLASS(feet_.getLeft(), "left_foot_state") \
25  HUMOTO_CONFIG_MEMBER_CLASS(feet_.getRight(), "right_foot_state")
26  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
27 
28 
29  private:
30  /**
31  * @brief Initialize foot state in an ADS
32  *
33  * @param[in] foot_param parameters of the feet
34  * @param[in] left_or_right left or right foot
35  * @param[in] theta orientation of the ADS
36  * @param[in] initial_ds_position position of the ADS.
37  */
39  const humoto::LeftOrRight::Type left_or_right,
40  const double theta,
41  const etools::Vector2 &initial_ds_position)
42  {
43  etools::Matrix2 ds_R;
44  ds_R = Eigen::Rotation2Dd(theta);
45 
46  feet_[left_or_right].position_.head(2) = foot_param.getFootPositionFromADS(
47  left_or_right,
48  ds_R,
49  initial_ds_position);
50  feet_[left_or_right].position_.z() = 0.0;
51  feet_[left_or_right].velocity_.setZero();
52  feet_[left_or_right].acceleration_.setZero();
53  feet_[left_or_right].rpy_ << 0., 0., theta;
54  etools::unsetMatrix(feet_[left_or_right].angular_velocity_);
55  etools::unsetMatrix(feet_[left_or_right].angular_acceleration_);
56  }
57 
58 
59  protected:
61  const double com_height = 0.814)
62  {
63  // initialize foot states
64  double theta = 0.;
65  etools::Vector2 initial_ds_position;
66  initial_ds_position.setZero();
67 
68  initializeFoot(foot_param, humoto::LeftOrRight::LEFT, theta, initial_ds_position);
69  initializeFoot(foot_param, humoto::LeftOrRight::RIGHT, theta, initial_ds_position);
70 
71 
72  // initialize com states
73  com_state_.setDefaults();
74  com_state_.position_.z() = com_height; // Height of the CoM
75 
76 
77  stance_type_ = humoto::walking::StanceType::DS;
78  next_stance_type_ = humoto::walking::StanceType::UNDEFINED;
79  }
80 
81 
82  public:
83  /// State of the CoM
85 
86  /// States of the feet
88 
89  /// current stance type
91 
92  /// next stance type
94 
95 
96 
97  public:
98  /**
99  * @brief Default constructor
100  */
102  {
103  setDefaults();
104  }
105 
106 
107  /**
108  * @brief Construct class using given parameters.
109  *
110  * @param[in] robot_parameters parameters of the feet
111  * @param[in] com_height height of the CoM (with respect to the feet)
112  */
114  const double com_height)
115  {
116  setDefaults(robot_parameters, com_height);
117  }
118 
119 
120  /**
121  * @brief Initialize to default values (HRP2)
122  */
123  void setDefaults()
124  {
125  humoto::walking::RobotFootParameters robot_parameters;
126  setDefaults(robot_parameters);
127  }
128 
129 
130 
131  /**
132  * @brief Initialize state using parameters
133  *
134  * @param[in] robot_parameters parameters of the feet
135  * @param[in] com_height height of the CoM (with respect to the feet)
136  */
137  void set ( const humoto::walking::RobotFootParameters & robot_parameters,
138  const double com_height)
139  {
140  setDefaults(robot_parameters, com_height);
141  }
142 
143 
144 
145  /**
146  * @brief Initialize state directly with the states of the CoM and feet.
147  *
148  * @param[in] current_stance current stance
149  * @param[in] com_state state of the CoM
150  * @param[in] left_foot_state state of the left foot
151  * @param[in] right_foot_state state of the right foot
152  */
153  void set( const walking::StanceType::Type current_stance,
154  const rigidbody::PointMassState & com_state,
155  const rigidbody::RigidBodyState & left_foot_state,
156  const rigidbody::RigidBodyState & right_foot_state)
157  {
159  || (current_stance == humoto::walking::StanceType::RSS)
160  || (current_stance == humoto::walking::StanceType::DS),
161  "The stance type must be LSS, RSS, or DS.");
162  com_state_ = com_state;
163  feet_.setLeft(left_foot_state);
164  feet_.setRight(right_foot_state);
165 
166  stance_type_ = current_stance;
167  next_stance_type_ = humoto::walking::StanceType::UNDEFINED;
168  }
169 
170 
171 
172  /**
173  * @brief Log
174  *
175  * @param[in,out] logger logger
176  * @param[in] parent parent
177  * @param[in] name name
178  */
180  const LogEntryName &parent = LogEntryName(),
181  const std::string &name = "model_state") const
182  {
183  LogEntryName subname = parent; subname.add(name);
184 
185  logger.log(LogEntryName(subname).add("stance_type") , stance_type_ );
186  logger.log(LogEntryName(subname).add("next_stance_type"), next_stance_type_);
187 
188  com_state_.log(logger, subname, "com_state");
189 
190  feet_.getLeft().log(logger, subname, "left_foot_state");
191  feet_.getRight().log(logger, subname, "right_foot_state");
192  }
193  };
194  }
195 }
196 
humoto::rigidbody::PointMassState com_state_
State of the CoM.
Definition: model_state.h:84
Class that groups together parameters related to a robot foot.
void setDefaults(const humoto::walking::RobotFootParameters &foot_param, const double com_height=0.814)
Definition: model_state.h:60
#define HUMOTO_LOCAL
Definition: export_import.h:26
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
Definition: logger.h:997
#define HUMOTO_ASSERT(condition, message)
etools::Vector2 getFootPositionFromADS(const humoto::LeftOrRight::Type left_or_right, const etools::Matrix2 &ref_R, const etools::Vector2 &ref_position) const
Get position of a foot or aligned double support based on position of an aligned support or a foot...
Default configurable base is strict.
Definition: config.h:353
walking::StanceType::Type next_stance_type_
next stance type
Definition: model_state.h:93
Represents log entry name.
Definition: logger.h:169
void setRight(const t_Data &data)
Get/set/copy left or right object.
Definition: leftright.h:108
void initializeFoot(const humoto::walking::RobotFootParameters &foot_param, const humoto::LeftOrRight::Type left_or_right, const double theta, const etools::Vector2 &initial_ds_position)
Initialize foot state in an ADS.
Definition: model_state.h:38
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="rigid_body_state") const
Log.
void unsetMatrix(Eigen::DenseBase< t_Derived > &matrix)
Unset matrix (initialize to NaN)
Definition: eigentools.h:178
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="point_mass_state") const
Log.
humoto::LeftRightContainer< humoto::rigidbody::RigidBodyState > feet_
States of the feet.
Definition: model_state.h:87
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
Definition: logger.h:555
void setLeft(const t_Data &data)
Get/set/copy left or right object.
Definition: leftright.h:105
void setDefaults()
Initialize to default values (HRP2)
Definition: model_state.h:123
The root namespace of HuMoTo.
Definition: config.h:12
walking::StanceType::Type stance_type_
current stance type
Definition: model_state.h:90
Class that groups together parmeters related to a robot foot.
t_Data & getRight()
Get/set/copy left or right object.
Definition: leftright.h:99
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="model_state") const
Log.
Definition: model_state.h:179
Abstract class to be used for interfaces.
Definition: model.h:18
ModelState(const humoto::walking::RobotFootParameters &robot_parameters, const double com_height)
Construct class using given parameters.
Definition: model_state.h:113
ModelState()
Default constructor.
Definition: model_state.h:101
LogEntryName & add(const char *name)
extends entry name with a subname
Definition: logger.h:232
t_Data & getLeft()
Get/set/copy left or right object.
Definition: leftright.h:93
EIGENTOOLS_CONSTANT_SIZE_MATRIX Matrix2
Definition: eigentools.h:76