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 wpg04
16  {
17  /**
18  * @brief [initialize_model.m]
19  *
20  * @todo AS. Currently the state of the swing foot is not updated
21  * during the swing phase, i.e. it is the same as it was in the end of
22  * the preceding TDS. It may be more reasonable to undefine this state
23  * instead.
24  */
28  {
29  private:
30  /**
31  * @brief Determines position of support.
32  */
34  {
35  /// assume that in DS feet are aligned
36  switch(state_.stance_type_)
37  {
39  current_support_position_ = state_.feet_.getLeft().position_.head(2);
40  break;
42  current_support_position_ = state_.feet_.getRight().position_.head(2);
43  break;
45  current_support_position_ = (state_.feet_.getRight().position_.head(2)
46  + state_.feet_.getLeft().position_.head(2)) / 2.;
47  break;
49  switch(state_.next_stance_type_)
50  {
52  current_support_position_ = state_.feet_.getLeft().position_.head(2);
53  break;
55  current_support_position_ = state_.feet_.getRight().position_.head(2);
56  break;
58  current_support_position_ = (state_.feet_.getRight().position_.head(2)
59  + state_.feet_.getLeft().position_.head(2)) / 2.;
60  break;
61  default:
62  HUMOTO_THROW_MSG("Wrong state sequence.");
63  break;
64  }
65  break;
66  default:
67  HUMOTO_THROW_MSG("Unknown stance type.");
68  break;
69  }
70  }
71 
72 
73  public:
74  /// state of the model
76  /// 2d position of the current support (center of a foot or ADS)
77  etools::Vector2 current_support_position_;
78 
79 
80  public:
81  /**
82  * @brief Default constructor
83  */
85  {
86  determineSupportPosition();
87  }
88 
89 
90  /**
91  * @brief Constructor
92  *
93  * @param[in] foot_param parameters of the robot
94  */
96  {
97  humoto::walking::RobotFootParameters::operator=(foot_param);
98  }
99 
100 
101  /**
102  * @brief Returns current CoM state.
103  *
104  * @return CoM state
105  */
107  {
108  return (state_.com_state_);
109  }
110 
111 
112  /**
113  * @brief Returns current foot state.
114  *
115  * @param[in] left_or_right left/right
116  *
117  * @return foot state
118  */
120  {
121  return (state_.feet_[left_or_right]);
122  }
123 
124 
125 
126  /**
127  * @brief Get cstate
128  */
129  etools::Vector6 getCState() const
130  {
131  etools::Vector6 cstate = convertCoMState(state_.com_state_);
132  return(cstate);
133  }
134 
135 
136 
137  /**
138  * @brief Get CoM height
139  *
140  * @return CoM height
141  */
142  double getCoMHeight() const
143  {
144  return (state_.com_state_.position_.z());
145  }
146 
147 
148 
149  /**
150  * @brief Update model state.
151  *
152  * @param[in] model_state model state.
153  */
154  void updateState(const humoto::ModelState &model_state)
155  {
156  const humoto::wpg04::ModelState &state = dynamic_cast <const humoto::wpg04::ModelState &> (model_state);
157 
158  walking::StanceType::Type prev_stance_type = state_.stance_type_;
159 
160  state_.com_state_ = state.com_state_;
161 
162  state_.stance_type_ = state.stance_type_;
163  state_.next_stance_type_ = state.next_stance_type_;
164 
165 
166  switch (state.stance_type_)
167  {
169  // XXX (undefined)
170  //state_.feet_.copyRight(state.feet_);
171  state_.feet_.copyLeft(state.feet_);
172  break;
173 
175  // XXX (undefined)
176  //state_.feet_.copyLeft(state.feet_);
177  state_.feet_.copyRight(state.feet_);
178  break;
179 
181  switch (prev_stance_type)
182  {
184  state_.feet_.copyRight(state.feet_);
185  break;
186 
188  state_.feet_.copyLeft(state.feet_);
189  break;
190 
192  // no need to update positions of the feet (they must not change)
193  break;
194 
195  default:
196  HUMOTO_THROW_MSG("Unknown stance type.");
197  break;
198  }
199  break;
200 
202  state_.feet_.copyLeft(state.feet_);
203  state_.feet_.copyRight(state.feet_);
204  break;
205 
206  default:
207  HUMOTO_THROW_MSG("Unknown state type.");
208  break;
209  }
210 
211  determineSupportPosition();
212  }
213 
214 
215  /**
216  * @brief Log
217  *
218  * @param[in,out] logger logger
219  * @param[in] parent parent
220  * @param[in] name name
221  */
223  const LogEntryName &parent = LogEntryName(),
224  const std::string &name = "model") const
225  {
226  LogEntryName subname = parent; subname.add(name);
227 
228  RobotFootParameters::log(logger, subname, "foot_parameters");
229 
230  state_.log(logger, subname, "state");
231 
232  logger.log(LogEntryName(subname).add("cstate"), getCState());
233  logger.log(LogEntryName(subname).add("current_support_position"), current_support_position_);
234  }
235  };
236  }
237 }
humoto::rigidbody::RigidBodyState getFootState(const humoto::LeftOrRight::Type left_or_right) const
Returns current foot state.
Definition: model.h:119
void updateState(const humoto::ModelState &model_state)
Update model state.
Definition: model.h:154
humoto::rigidbody::PointMassState com_state_
State of the CoM.
Definition: model_state.h:84
Class that groups together parameters related to a robot foot.
#define HUMOTO_LOCAL
Definition: export_import.h:26
void copyRight(const LeftRightContainer< t_Data > &copy_from)
Get/set/copy left or right object.
Definition: leftright.h:114
etools::Vector2 current_support_position_
2d position of the current support (center of a foot or ADS)
Definition: model.h:77
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
Definition: logger.h:997
void setFootParameters(const humoto::walking::RobotFootParameters &foot_param)
Constructor.
Definition: model.h:95
walking::StanceType::Type next_stance_type_
next stance type
Definition: model_state.h:93
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
Represents log entry name.
Definition: logger.h:169
[initialize_model.m]
Definition: model.h:25
Point Mass Model with piece-wise constant CoP velocity.
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="model") const
Log.
Definition: model.h:222
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
humoto::rigidbody::PointMassState getCoMState() const
Returns current CoM state.
Definition: model.h:106
etools::Vector6 getCState() const
Get cstate.
Definition: model.h:129
void copyLeft(const LeftRightContainer< t_Data > &copy_from)
Get/set/copy left or right object.
Definition: leftright.h:111
double getCoMHeight() const
Get CoM height.
Definition: model.h:142
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.
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="model_state") const
Log.
Definition: model_state.h:179
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
Abstract class to be used for interfaces.
Definition: model.h:18
Model()
Default constructor.
Definition: model.h:84
humoto::wpg04::ModelState state_
state of the model
Definition: model.h:75
LogEntryName & add(const char *name)
extends entry name with a subname
Definition: logger.h:232
void determineSupportPosition()
Determines position of support.
Definition: model.h:33