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 pepper_mpc
16  {
17  static const char * BASE_VEL_VARIABLES_ID = "base_vel";
18  static const char * BODY_JERK_VARIABLES_ID = "body_pos";
19 
20 
21  /**
22  * @brief Parameters of the motion
23  */
25  {
26  #define HUMOTO_CONFIG_SECTION_ID "RobotParameters"
27  #define HUMOTO_CONFIG_CONSTRUCTOR RobotParameters
28  #define HUMOTO_CONFIG_ENTRIES \
29  HUMOTO_CONFIG_SCALAR_(base_radius) \
30  HUMOTO_CONFIG_SCALAR_(max_nominal_base_velocity) \
31  HUMOTO_CONFIG_SCALAR_(max_nominal_base_acceleration) \
32  HUMOTO_CONFIG_SCALAR_(max_base_velocity) \
33  HUMOTO_CONFIG_SCALAR_(max_base_acceleration) \
34  HUMOTO_CONFIG_COMPOUND_(body_bounds)
35  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
36 
37 
38  private:
39  // meter
41  // meter / second
43  // meter / second^2
45  // meter / second
47  // meter / second^2
49 
50 
51  protected:
52  /**
53  * @brief Finalize initialization
54  */
55  void finalize()
56  {
57  double cop_bound = getEncircledSquareSide(base_radius_)/2;
58 
59  cop_bounds_ << -cop_bound, cop_bound,
60  -cop_bound, cop_bound;
61 
62  // ---
63 
64  double velocity_bound = getEncircledSquareSide(max_nominal_base_velocity_)/2;
65 
66  nominal_base_velocity_bounds_ << -velocity_bound, velocity_bound,
67  -velocity_bound, velocity_bound;
68 
69 
70  velocity_bound = getEncircledSquareSide(max_base_velocity_)/2;
71 
72  base_velocity_bounds_ << -velocity_bound, velocity_bound,
73  -velocity_bound, velocity_bound;
74 
75  // ---
76 
77  double acceleration_bound = getEncircledSquareSide(max_nominal_base_acceleration_)/2;
78 
79  nominal_base_acceleration_bounds_ << -acceleration_bound, acceleration_bound,
80  -acceleration_bound, acceleration_bound;
81 
82 
83  acceleration_bound = getEncircledSquareSide(max_base_acceleration_)/2;
84 
85  base_acceleration_bounds_ << -acceleration_bound, acceleration_bound,
86  -acceleration_bound, acceleration_bound;
87  }
88 
89 
90  public:
91  // meter
92  double base_radius_;
93  // meter / second
95  // meter / second^2
97  // meter / second
99  // meter / second^2
101 
102  // [lb, ub] meter
104 
105 
106  public:
107  void setDefaults()
108  {
109  base_radius_ = 0.7;
110  max_nominal_base_velocity_ = 0.5;
111  max_nominal_base_acceleration_ = 1.0;
112  max_base_velocity_ = 1.4;
113  max_base_acceleration_ = 1.7;
114 
115  body_bounds_ << -0.06, 0.06,
116  -0.03, 0.03;
117  finalize();
118  }
119 
120 
121  /**
122  * @brief Default constructor
123  */
125  {
126  setDefaults();
127  }
128 
129 
130  /**
131  * @brief Get respective bounds
132  *
133  * @return [lb, ub] 2x2 matrix
134  */
136  {
137  return(cop_bounds_);
138  }
139 
140  /// @copydoc getCoPBounds
142  {
143  return(nominal_base_velocity_bounds_);
144  }
145 
146  /// @copydoc getCoPBounds
148  {
149  return(nominal_base_acceleration_bounds_);
150  }
151 
152  /// @copydoc getCoPBounds
154  {
155  return(body_bounds_);
156  }
157  };
158 
159 
160 
162  {
163  public:
164  enum Mode
165  {
166  UNDEFINED = 0,
167  MAINTAIN_POSITION = 1,
168  MAINTAIN_VELOCITY = 2
169  };
170  };
171 
172 
173  /**
174  * @brief Parameters of the motion
175  */
177  {
178  #define HUMOTO_CONFIG_SECTION_ID "MotionParameters"
179  #define HUMOTO_CONFIG_CONSTRUCTOR MotionParameters
180  #define HUMOTO_CONFIG_ENTRIES \
181  HUMOTO_CONFIG_COMPOUND_(base_velocity)\
182  HUMOTO_CONFIG_COMPOUND_(base_position)\
183  HUMOTO_CONFIG_SCALAR_(base_angular_velocity)\
184  HUMOTO_CONFIG_ENUM_(motion_mode) \
185  HUMOTO_CONFIG_SCALAR_(duration_ms)
186  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
187 
188 
189  public:
190  const static std::ptrdiff_t UNLIMITED_DURATION = -1;
191 
192  etools::Vector2 base_velocity_;
193  etools::Vector2 base_position_;
194 
196  std::ptrdiff_t duration_ms_;
197 
199 
200 
201  public:
202  /**
203  * @brief Default constructor
204  */
206  {
207  setDefaults();
208  }
209 
210 
211  /**
212  * @brief Default parameters of the walk
213  */
214  void setDefaults()
215  {
216  setIdle();
217  }
218 
219 
220  /**
221  * @brief Idle parameters of the motion
222  */
223  void setIdle()
224  {
225  base_velocity_.setZero();
226  base_position_.setZero();
227  base_angular_velocity_ = 0.0;
228  duration_ms_ = UNLIMITED_DURATION;
229  motion_mode_ = MotionMode::MAINTAIN_VELOCITY;
230  }
231 
232 
233  /**
234  * @brief Finalize & check
235  */
236  void finalize()
237  {
238  }
239 
240 
241  /**
242  * @brief Get base reference velocity
243  *
244  * @return base velocity
245  */
246  etools::Vector2 getBaseVelocity() const
247  {
248  return(base_velocity_);
249  }
250 
251 
252  /**
253  * @brief Get base reference position
254  *
255  * @return base position
256  */
257  etools::Vector2 getBasePosition() const
258  {
259  return(base_position_);
260  }
261 
262 
263  /**
264  * @brief Get theta increment
265  *
266  * @return theta increment
267  */
268  double getBaseAngularVelocity() const
269  {
270  return(base_angular_velocity_);
271  }
272  };
273 
274 
275 
276  /**
277  * @brief Parameters of the MPC problem.
278  */
280  {
281  #define HUMOTO_CONFIG_SECTION_ID "MPCParameters"
282  #define HUMOTO_CONFIG_CONSTRUCTOR MPCParameters
283  #define HUMOTO_CONFIG_ENTRIES \
284  HUMOTO_CONFIG_SCALAR_(preview_horizon_length) \
285  HUMOTO_CONFIG_SCALAR_(sampling_time_ms) \
286  HUMOTO_CONFIG_SCALAR_(subsampling_time_ms)
287  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
288 
289 
290  private:
291  /// Sampling time in seconds (T)
293 
294  /// Subsampling time in seconds (Ts)
296 
297 
298  protected:
299  /**
300  * @brief Compute some derived variables.
301  */
302  void finalize()
303  {
304  // convert milliseconds to seconds
305  sampling_time_ = convertMillisecondToSecond(sampling_time_ms_);
306  // convert milliseconds to seconds
307  subsampling_time_ = convertMillisecondToSecond(subsampling_time_ms_);
308  }
309 
310 
311  public:
312  /// Length of the preview horizon (N)
314 
315  /// Sampling time in milliseconds (T_ms)
316  std::size_t sampling_time_ms_;
317 
318  /// Subsampling time in milliseconds (Ts_ms)
319  std::size_t subsampling_time_ms_;
320 
321 
322  public:
323  /**
324  * @brief Initialize to default values
325  */
326  void setDefaults()
327  {
328  preview_horizon_length_ = 15;
329  sampling_time_ms_ = 100;
330  subsampling_time_ms_ = sampling_time_ms_;
331 
332  finalize();
333  }
334 
335 
336  /**
337  * @brief Constructor.
338  *
339  * @param[in] preview_horizon_len Length of the preview horizon
340  * @param[in] sampling_time_ms Sampling time in milliseconds
341  * @param[in] subsampling_time_ms Subsampling time in milliseconds
342  */
343  MPCParameters( const std::size_t preview_horizon_len = 15,
344  const std::size_t sampling_time_ms = 100,
345  const std::size_t subsampling_time_ms = 100)
346  {
347  preview_horizon_length_ = preview_horizon_len;
348  sampling_time_ms_ = sampling_time_ms;
349  subsampling_time_ms_ = subsampling_time_ms;
350 
351  finalize();
352  }
353 
354 
355  /**
356  * @brief Get sampling time in seconds
357  *
358  * @return sampling time in seconds
359  */
360  double getSamplingTime() const
361  {
362  return (sampling_time_);
363  }
364 
365 
366  /**
367  * @brief Get subsampling time in seconds
368  *
369  * @return subsampling time in seconds
370  */
371  double getSubsamplingTime() const
372  {
373  return (subsampling_time_);
374  }
375  };
376  }
377 }
378 
double getSubsamplingTime() const
Get subsampling time in seconds.
Definition: common.h:371
static const char * BODY_JERK_VARIABLES_ID
Definition: common.h:18
etools::Vector2 getBaseVelocity() const
Get base reference velocity.
Definition: common.h:246
std::size_t preview_horizon_length_
Length of the preview horizon (N)
Definition: common.h:313
double getBaseAngularVelocity() const
Get theta increment.
Definition: common.h:268
void setDefaults()
Default parameters of the walk.
Definition: common.h:214
etools::Matrix2 getBodyBounds() const
Get respective bounds.
Definition: common.h:153
#define HUMOTO_LOCAL
Definition: export_import.h:26
RobotParameters()
Default constructor.
Definition: common.h:124
void finalize()
Finalize initialization.
Definition: common.h:55
void finalize()
Compute some derived variables.
Definition: common.h:302
static const char * BASE_VEL_VARIABLES_ID
Definition: common.h:17
etools::Matrix2 nominal_base_acceleration_bounds_
Definition: common.h:44
double subsampling_time_
Subsampling time in seconds (Ts)
Definition: common.h:295
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
void setIdle()
Idle parameters of the motion.
Definition: common.h:223
etools::Matrix2 getNominalBaseAccelerationBounds() const
Get respective bounds.
Definition: common.h:147
Parameters of the motion.
Definition: common.h:176
etools::Matrix2 getCoPBounds() const
Get respective bounds.
Definition: common.h:135
double sampling_time_
Sampling time in seconds (T)
Definition: common.h:292
void setDefaults()
Initialize to default values.
Definition: common.h:326
std::size_t sampling_time_ms_
Sampling time in milliseconds (T_ms)
Definition: common.h:316
std::size_t subsampling_time_ms_
Subsampling time in milliseconds (Ts_ms)
Definition: common.h:319
Parameters of the MPC problem.
Definition: common.h:279
MPCParameters(const std::size_t preview_horizon_len=15, const std::size_t sampling_time_ms=100, const std::size_t subsampling_time_ms=100)
Constructor.
Definition: common.h:343
etools::Matrix2 base_acceleration_bounds_
Definition: common.h:48
void finalize()
Finalize & check.
Definition: common.h:236
The root namespace of HuMoTo.
Definition: config.h:12
Parameters of the motion.
Definition: common.h:24
etools::Matrix2 nominal_base_velocity_bounds_
Definition: common.h:42
etools::Matrix2 getNominalBaseVelocityBounds() const
Get respective bounds.
Definition: common.h:141
etools::Vector2 getBasePosition() const
Get base reference position.
Definition: common.h:257
void setDefaults()
Set members to their default values.
Definition: common.h:107
double HUMOTO_LOCAL getEncircledSquareSide(const double radius)
Function computing side length of a square inscribed inside of a circle of given radius.
Definition: utility.h:133
etools::Matrix2 base_velocity_bounds_
Definition: common.h:46
EIGENTOOLS_CONSTANT_SIZE_MATRIX Matrix2
Definition: eigentools.h:76
MotionParameters()
Default constructor.
Definition: common.h:205
double getSamplingTime() const
Get sampling time in seconds.
Definition: common.h:360