humoto
common.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  static const char * COP_VARIABLES_ID = "CoP";
18  static const char * FOOTPOS_VARIABLES_ID = "footpos";
19 
20 
21  /**
22  * @brief Class containing options of the walking pattern generator
23  */
25  {
26  #define HUMOTO_CONFIG_SECTION_ID "WalkParameters"
27  #define HUMOTO_CONFIG_CONSTRUCTOR WalkParameters
28  #define HUMOTO_CONFIG_ENTRIES \
29  HUMOTO_CONFIG_COMPOUND_(com_velocity)\
30  HUMOTO_CONFIG_COMPOUND_(first_stance_com_velocity)\
31  HUMOTO_CONFIG_COMPOUND_(last_stance_com_velocity)\
32  \
33  HUMOTO_CONFIG_SCALAR_(step_height)\
34  HUMOTO_CONFIG_SCALAR_(theta_increment)\
35  \
36  HUMOTO_CONFIG_PARENT_CLASS(humoto::walking::StanceFSMParameters)
37  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
38 
39 
40  public:
41  etools::Vector2 com_velocity_;
42  etools::Vector2 first_stance_com_velocity_;
43  etools::Vector2 last_stance_com_velocity_;
44 
45  double step_height_;
47 
48 
49  public:
50  /**
51  * @brief Default constructor
52  */
54  {
55  setDefaults();
56  }
57 
58 
59 
60  /**
61  * @brief Default parameters of the walk
62  */
63  void setDefaults()
64  {
65  com_velocity_ << 0.2, 0.;
66  first_stance_com_velocity_ << 0.2, 0.;
67  last_stance_com_velocity_ << 0., 0.;
68  step_height_ = 0.07;
69  theta_increment_ = 0.0;
70 
72  }
73  };
74 
75 
76 
77  /**
78  * @brief Parameters of an MPC problem. [set_parameters_mpc.m]
79  */
81  {
82  #define HUMOTO_CONFIG_SECTION_ID "MPCParameters"
83  #define HUMOTO_CONFIG_CONSTRUCTOR MPCParameters
84  #define HUMOTO_CONFIG_ENTRIES \
85  HUMOTO_CONFIG_SCALAR_(preview_horizon_length)\
86  HUMOTO_CONFIG_SCALAR_(sampling_time_ms)\
87  HUMOTO_CONFIG_SCALAR_(subsampling_time_ms)\
88  HUMOTO_CONFIG_SCALAR_(tds_sampling_time_ms)
89  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
90 
91 
92  private:
93  /// Number of subsamples per sample (TN)
94  std::size_t subsamples_num_;
95 
96  /// Number of subsamples per doubles support sample (TN_tds)
97  std::size_t tds_subsamples_num_;
98 
99  /// Sampling time in seconds (T)
101 
102  /// Subsampling time in seconds (Ts)
104 
105  /// Sampling time of a transitional double support in
106  /// seconds (Ttds)
108 
109 
110  protected:
111  /**
112  * @brief Compute some derived variables.
113  */
114  void finalize()
115  {
116  if (sampling_time_ms_ % subsampling_time_ms_ == 0)
117  {
118  subsamples_num_ = sampling_time_ms_ / subsampling_time_ms_;
119  }
120  else
121  {
122  HUMOTO_THROW_MSG("Sampling time should be a multiple of subsampling time.");
123  }
124 
125 
126  if (tds_sampling_time_ms_ % subsampling_time_ms_ == 0)
127  {
128  tds_subsamples_num_ = tds_sampling_time_ms_ / subsampling_time_ms_;
129  }
130  else
131  {
132  HUMOTO_THROW_MSG("Transitional double support sampling time should be a multiple of subsampling time.");
133  }
134 
135  // convert milliseconds to seconds
136  sampling_time_ = convertMillisecondToSecond(sampling_time_ms_);
137  subsampling_time_ = convertMillisecondToSecond(subsampling_time_ms_);
138  tds_sampling_time_ = convertMillisecondToSecond(tds_sampling_time_ms_);
139  }
140 
141 
142  public:
143  /// Length of the preview horizon (N)
145 
146  /// Sampling time in milliseconds (T_ms)
147  std::size_t sampling_time_ms_;
148 
149  /// Subsampling time in milliseconds (Ts_ms)
150  std::size_t subsampling_time_ms_;
151 
152  /// Sampling time of a transitional double support in
153  /// milliseconds (Ttds_ms)
155 
156 
157  public:
158  /**
159  * @brief Initialize to default values
160  */
161  void setDefaults()
162  {
163  preview_horizon_length_ = 16;
164  sampling_time_ms_ = 100;
165  subsampling_time_ms_ = 100;
166  tds_sampling_time_ms_ = 100;
167 
168  finalize();
169  }
170 
171 
172  /**
173  * @brief Constructor.
174  *
175  * @param[in] preview_horizon_len Length of the preview horizon
176  * @param[in] sampling_time_ms Sampling time in milliseconds
177  * @param[in] subsampling_time_ms Subsampling time in milliseconds
178  * @param[in] tds_sampling_time_ms Sampling time of a transitional double support in milliseconds
179  */
180  MPCParameters( const std::size_t preview_horizon_len = 16,
181  const std::size_t sampling_time_ms = 100,
182  const std::size_t subsampling_time_ms = 100,
183  const std::size_t tds_sampling_time_ms = 100)
184  {
185  preview_horizon_length_ = preview_horizon_len;
186  sampling_time_ms_ = sampling_time_ms;
187  subsampling_time_ms_ = subsampling_time_ms;
188  tds_sampling_time_ms_ = tds_sampling_time_ms;
189 
190  finalize();
191  }
192 
193 
194  /**
195  * @brief getSubsamplingTime
196  *
197  * @return subsampling time
198  */
199  double getSubsamplingTime () const
200  {
201  return (subsampling_time_);
202  }
203  };
204  }
205 }
206 
void setDefaults()
Initialize to default values.
Definition: common.h:161
double subsampling_time_
Subsampling time in seconds (Ts)
Definition: common.h:103
static const char * COP_VARIABLES_ID
Definition: common.h:17
double sampling_time_
Sampling time in seconds (T)
Definition: common.h:100
std::size_t preview_horizon_length_
Length of the preview horizon (N)
Definition: common.h:144
etools::Vector2 com_velocity_
Definition: common.h:41
#define HUMOTO_LOCAL
Definition: export_import.h:26
double tds_sampling_time_
Sampling time of a transitional double support in seconds (Ttds)
Definition: common.h:107
double getSubsamplingTime() const
getSubsamplingTime
Definition: common.h:199
Parameters of an MPC problem. [set_parameters_mpc.m].
Definition: common.h:80
Default configurable base is strict.
Definition: config.h:353
double HUMOTO_LOCAL convertMillisecondToSecond(const std::size_t milliseconds)
Converts milliseconds to seconds.
Definition: time.h:22
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
etools::Vector2 last_stance_com_velocity_
Definition: common.h:43
etools::Vector2 first_stance_com_velocity_
Definition: common.h:42
Class containing options of the walking pattern generator.
Definition: common.h:24
std::size_t subsamples_num_
Number of subsamples per sample (TN)
Definition: common.h:94
void finalize()
Compute some derived variables.
Definition: common.h:114
WalkParameters()
Default constructor.
Definition: common.h:53
void setDefaults()
Default parameters of the walk.
Definition: common.h:63
void setDefaults()
Default parameters of the finite state machine.
static const char * FOOTPOS_VARIABLES_ID
Definition: common.h:18
std::size_t subsampling_time_ms_
Subsampling time in milliseconds (Ts_ms)
Definition: common.h:150
The root namespace of HuMoTo.
Definition: config.h:12
MPCParameters(const std::size_t preview_horizon_len=16, const std::size_t sampling_time_ms=100, const std::size_t subsampling_time_ms=100, const std::size_t tds_sampling_time_ms=100)
Constructor.
Definition: common.h:180
std::size_t sampling_time_ms_
Sampling time in milliseconds (T_ms)
Definition: common.h:147
std::size_t tds_sampling_time_ms_
Sampling time of a transitional double support in milliseconds (Ttds_ms)
Definition: common.h:154
std::size_t tds_subsamples_num_
Number of subsamples per doubles support sample (TN_tds)
Definition: common.h:97
Class containing parameters of the stance finite state machine.