A sparse MPC solver for walking motion generation.
WMG.h
Go to the documentation of this file.
1 
8 #ifndef WMG_H
9 #define WMG_H
10 
11 
12 /****************************************
13  * INCLUDES
14  ****************************************/
15 
16 #include <string>
17 #include <vector>
18 
19 #include "smpc_solver.h"
20 
21 /****************************************
22  * DEFINES
23  ****************************************/
24 
25 
26 
27 /****************************************
28  * TYPEDEFS
29  ****************************************/
30 class footstep;
31 
32 
34 
35 
36 enum WMGret
37 {
40 };
41 
42 enum fs_type
43 {
44  FS_TYPE_AUTO, // let the library decide
45  FS_TYPE_SS_L, // left single support
46  FS_TYPE_SS_R, // right single support
47  FS_TYPE_DS // double support
48 };
49 
50 
51 
56 {
57  public:
66  const unsigned int,
67  const double,
68  const double gravity_ = 9.81);
69 
74 
75 
76 
77 // variables
78  double hCoM;
79 
80  double gravity;
81 
82  double *T;
83 
84  double *h;
85  double h0;
86 
88  double *angle;
89 
91  double *fp_x;
93  double *fp_y;
95 
97  double *lb;
99  double *ub;
101 
103  double *zref_x;
105  double *zref_y;
107 
108 
111 
113  double *X;
114 };
115 
116 
117 
135 {
136  public:
138  double ss_left[4];
139  double ss_right[4];
140 
142  double ds[4];
143 
145  double auto_ds[4];
146 
149 
150 
152  {
153  // 2*HipOffsetY = 2*0.05
154  support_distance_y = 0.1;
155  }
156 
157  void init()
158  {
159  // measured using ruler =)
160  ss_left[0] = ss_right[0] = 0.09;
161  ss_left[1] = ss_right[1] = 0.025;
162  ss_left[2] = ss_right[2] = 0.03;
163  ss_left[3] = ss_right[3] = 0.025;
164 
165  ds[0] = 0.09;
166  ds[1] = 0.025 + support_distance_y/2;
167  ds[2] = 0.03;
168  ds[3] = 0.025 + support_distance_y/2;
169 
170  // SS constraints with increased safety margin
171  auto_ds[0] = 0.07;
172  auto_ds[1] = 0.025;
173  auto_ds[2] = 0.025;
174  auto_ds[3] = 0.025;
175  };
176 
177 
178  void init_FSR()
179  {
180  /*
181  Positions of forse sensitve resistors (with respect to ankle frame
182  of respective foot):
183 
184  Left foot
185  (0.07025 , 0.0299) *---------* (0.07025 , -0.0231)
186  | |
187  | ^ /
188  | |x /
189  | <--+ |
190  | y |
191  (-0.03025 , 0.0299) *--------* (-0.02965 , -0.0191)
192 
193  Rectangle:
194  ( 0.07 , 0.029) ( 0.07 , -0.019)
195  (-0.029 , 0.029) (-0.029 , -0.019)
196 
197 
198  Right foot
199  (0.07025 , 0.0231) *---------* (0.07025 , -0.0299)
200  | |
201  \ ^ |
202  \ |x |
203  |<--+ |
204  | y |
205  (-0.03025 , 0.0191) *--------* (-0.02965 , -0.0299)
206 
207  Rectangle:
208  ( 0.07 , 0.019) ( 0.07 , -0.029)
209  (-0.029 , 0.019) (-0.029 , -0.029)
210  */
211 
212  ss_left[0] = 0.07;
213  ss_left[1] = 0.029;
214  ss_left[2] = 0.029;
215  ss_left[3] = 0.019;
216 
217  ss_right[0] = 0.07;
218  ss_right[1] = 0.019;
219  ss_right[2] = 0.029;
220  ss_right[3] = 0.029;
221 
222 
223  ds[0] = 0.07;
224  ds[1] = 0.029 + support_distance_y/2;
225  ds[2] = 0.029;
226  ds[3] = 0.029 + support_distance_y/2;
227 
228  auto_ds[0] = 0.065;
229  auto_ds[1] = 0.020;
230  auto_ds[2] = 0.025;
231  auto_ds[3] = 0.020;
232  };
233 };
234 
235 
236 
240 class WMG
241 {
242  public:
243 
244  // --------------------
245 
266  WMG ( const unsigned int N_,
267  const unsigned int T_,
268  const double step_height_ = 0.0135,
269  double bezier_weight_1_ = 1.0,
270  double bezier_weight_2_ = 2.0,
271  double bezier_inclination_1_ = 0.01,
272  double bezier_inclination_2_ = 0.008,
273  bool use_fsr_constraints = false);
274 
276  ~WMG();
277 
278 
291  void setFootstepParameters (
292  const unsigned int def_periods,
293  const unsigned int ds_periods,
294  const unsigned int ds_number,
295  bool use_user_constraints_ = false);
296 
297 
309  const unsigned int def_time_ms_,
310  const unsigned int ds_time_ms_,
311  const unsigned int ds_number,
312  bool use_user_constraints_ = false);
313 
314 
325  void addFootstep(
326  const double,
327  const double,
328  const double,
329  fs_type type = FS_TYPE_AUTO);
330 
331 
338 
339 
340  // --------------------
341 
342 
357  void getFeetPositions (
358  const unsigned int shift_from_current_ms,
359  double * left_foot_pos,
360  double * right_foot_pos);
361 
362 
368  bool isSupportSwitchNeeded ();
369 
370 
379  void changeNextSSPosition (const double *posture, const bool zero_z_coordinate);
380 
381 
388  void repositionFootsteps (const double diff_x, const double diff_y);
389 
390 
391  // --------------------
392 
399  void FS2file(const std::string filename, const bool plot_ds = true);
400 
401 
410  void getFootsteps(
411  std::vector<double> &x_coord,
412  std::vector<double> &y_coord,
413  std::vector<double> &angle_rot);
414 
415  // --------------------
416 
417 
418 // variables
420  std::vector<footstep> FS;
421 
422 
424  unsigned int N;
425 
426  unsigned int *T_ms;
427  unsigned int sampling_period;
428 
429 
432 
435 
437  double step_height;
438 
439 
442 
445  double user_constraints[4];
449 
450 
451 
453 
475 
476  private:
477  void getDSFeetPositions (const int, double *, double *);
478  void getSSFeetPositions (const int, const double, double *, double *);
479  void getSSFeetPositionsBezier (const int, const double, double *, double *);
480  int getNextSS (const int, const fs_type type = FS_TYPE_AUTO);
481  int getPrevSS (const int, const fs_type type = FS_TYPE_AUTO);
482 
483  unsigned int def_time_ms;
484  unsigned int ds_time_ms;
485  unsigned int ds_num;
486 
487  unsigned int last_time_decrement;
488 };
490 
491 #endif /*WMG_H*/
double step_height
The maximum height, that can be reached by a swing foot.
Definition: WMG.h:437
int getPrevSS(const int, const fs_type type=FS_TYPE_AUTO)
Returns index of the previous SS.
Definition: WMG_private.cpp:58
void getDSFeetPositions(const int, double *, double *)
Determine position and orientation of feet in DS.
Definition: WMG_private.cpp:90
Defines the parameters of the Walking Pattern Generator.
Definition: WMG.h:240
void init_FSR()
Definition: WMG.h:178
double * zref_y
N reference coordinates of ZMP.
Definition: WMG.h:105
A container for parameters of the SMPC solver.
Definition: WMG.h:55
WMGret formPreviewWindow(smpc_parameters &)
Forms a preview window.
Definition: WMG.cpp:331
double hCoM
Definition: WMG.h:78
double bezier_weight_2
Definition: WMG.h:471
Definition: WMG.h:39
void init()
Definition: WMG.h:157
void getFootsteps(std::vector< double > &x_coord, std::vector< double > &y_coord, std::vector< double > &angle_rot)
Return coordinates of footstep reference points and rotation angles of footsteps (only for SS).
Definition: WMG.cpp:488
unsigned int * T_ms
Definition: WMG.h:426
void getSSFeetPositions(const int, const double, double *, double *)
Determine position and orientation of feet (parabolic trajectory)
defConstraints def_constraints
Default SS and DS constraints.
Definition: WMG.h:441
double bezier_inclination_2
Definition: WMG.h:473
Definition: WMG.h:38
A container for a state in the original form:
Definition: smpc_solver.h:140
~WMG()
Destructor.
Definition: WMG.cpp:65
void getSSFeetPositionsBezier(const int, const double, double *, double *)
Determine position and orientation of feet (using cubic Bezier curves)
double * zref_x
N reference coordinates of ZMP.
Definition: WMG.h:104
Defines a footstep.
Definition: footstep.h:29
unsigned int last_time_decrement
Definition: WMG.h:487
Interface of the library.
double * fp_x
Coordinates of N points satisfying constraints,.
Definition: WMG.h:92
Definition: WMG.h:47
int getNextSS(const int, const fs_type type=FS_TYPE_AUTO)
Returns index of the next SS.
Definition: WMG_private.cpp:23
void setFootstepParametersMS(const unsigned int def_time_ms_, const unsigned int ds_time_ms_, const unsigned int ds_number, bool use_user_constraints_=false)
Set default parameters of footsteps.
Definition: WMG.cpp:89
void changeNextSSPosition(const double *posture, const bool zero_z_coordinate)
Changes position of the next SS.
Definition: WMG.cpp:300
double bezier_weight_1
Definition: WMG.h:470
double ds[4]
Both feet standing together.
Definition: WMG.h:142
double * angle
initial h
Definition: WMG.h:88
Default footstep constraints.
Definition: WMG.h:134
bool use_user_constraints
Constraints given by the user, initialized to the default values on initialization.
Definition: WMG.h:447
unsigned int N
Number of iterations in a preview window.
Definition: WMG.h:424
double * lb
2*N bounds for coordinates of ZMP position.
Definition: WMG.h:98
void getFeetPositions(const unsigned int shift_from_current_ms, double *left_foot_pos, double *right_foot_pos)
Determine position and orientation of feet.
Definition: WMG.cpp:230
double auto_ds[4]
Automatically added DS.
Definition: WMG.h:145
bool isSupportSwitchNeeded()
Checks if the support foot switch is needed.
Definition: WMG.cpp:273
std::vector< footstep > FS
A vector of footsteps.
Definition: WMG.h:420
double h0
h = hCoM/gravity for each preview step
Definition: WMG.h:85
double * T
Norm of the acceleration due to gravity.
Definition: WMG.h:82
void FS2file(const std::string filename, const bool plot_ds=true)
Outputs the footsteps in FS to a Matlab/Octave script for plotting.
Definition: WMG.cpp:423
unsigned int def_time_ms
Definition: WMG.h:483
~smpc_parameters()
Default destructor.
unsigned int sampling_period
Definition: WMG.h:427
smpc_parameters(const unsigned int, const double, const double gravity_=9.81)
Allocate memory and initialize some of the parameters.
double user_constraints_auto_ds[4]
Constraints given by the user, initialized to the default values on initialization.
Definition: WMG.h:446
int first_preview_step
The first step in the current preview window.
Definition: WMG.h:434
double bezier_inclination_1
Definition: WMG.h:472
double ss_right[4]
Definition: WMG.h:139
double user_constraints[4]
Constraints given by the user, initialized to the default values on initialization.
Definition: WMG.h:445
double * ub
2*N bounds for coordinates of ZMP position.
Definition: WMG.h:99
double ss_left[4]
Support constraints with safety margin.
Definition: WMG.h:138
unsigned int ds_time_ms
Definition: WMG.h:484
double support_distance_y
Distance between reference points of the feet.
Definition: WMG.h:148
double gravity
Height of the CoM.
Definition: WMG.h:80
double * h
Preview sampling time.
Definition: WMG.h:84
smpc::state_com init_state
Definition: WMG.h:110
fs_type
Definition: WMG.h:42
WMG(const unsigned int N_, const unsigned int T_, const double step_height_=0.0135, double bezier_weight_1_=1.0, double bezier_weight_2_=2.0, double bezier_inclination_1_=0.01, double bezier_inclination_2_=0.008, bool use_fsr_constraints=false)
Initializes a WMG object.
Definition: WMG.cpp:15
void setFootstepParameters(const unsigned int def_periods, const unsigned int ds_periods, const unsigned int ds_number, bool use_user_constraints_=false)
Set default parameters of footsteps, a wrapper around not so safe setFootstepParametersMS function.
Definition: WMG.cpp:75
defConstraints()
Definition: WMG.h:151
int current_step_number
This is the step in FS that is at the start of the current preview window.
Definition: WMG.h:431
double * X
A chunk of memory allocated for solution.
Definition: WMG.h:113
void repositionFootsteps(const double diff_x, const double diff_y)
Reposition all subsequent footsteps that are not fixed at the current moment.
Definition: WMG.cpp:306
void addFootstep(const double, const double, const double, fs_type type=FS_TYPE_AUTO)
Adds a footstep to FS.
Definition: WMG.cpp:102
double * fp_y
Coordinates of N points satisfying constraints,.
Definition: WMG.h:93
WMGret
Definition: WMG.h:36
unsigned int ds_num
Definition: WMG.h:485