16 const unsigned int N_,
17 const unsigned int T_,
18 const double step_height_,
19 const double bezier_weight_1_,
20 const double bezier_weight_2_,
21 const double bezier_inclination_1_,
22 const double bezier_inclination_2_,
23 const bool use_fsr_constraints)
29 T_ms =
new unsigned int[
N];
30 for (
unsigned int i = 0; i <
N; i++)
40 if (use_fsr_constraints)
51 for (
int i = 0; i < 4; ++i)
76 const unsigned int def_periods,
77 const unsigned int ds_periods,
78 const unsigned int ds_number,
79 bool use_user_constraints_)
85 use_user_constraints_);
90 const unsigned int def_time_ms_,
91 const unsigned int ds_time_ms_,
92 const unsigned int ds_number,
93 bool use_user_constraints_)
103 const double x_relative,
104 const double y_relative,
105 const double angle_relative,
108 const double *constraints;
109 const double *constraints_auto_ds;
158 Transform<double, 3> posture (Translation<double, 3>(x_relative, y_relative, 0.0));
159 Vector3d zref_offset ((constraints[0] - constraints[2])/2, 0.0, 0.0);
164 posture *= AngleAxisd(angle_relative, Vector3d::UnitZ());
166 Vector3d zref_abs = posture * zref_offset;
180 posture = (*
FS.back().posture) * posture * AngleAxisd(angle_relative, Vector3d::UnitZ());
182 double prev_a =
FS.back().angle;
183 double next_a = prev_a + angle_relative;
184 Vector3d next_zref = posture * zref_offset;
189 double theta = (double) 1/(
ds_num + 1);
190 double angle_shift = angle_relative * theta;
191 double x_shift = theta*x_relative;
192 double y_shift = theta*y_relative;
193 Vector3d *ds_zref = &
FS.back().ZMPref;
194 for (
unsigned int i = 0; i <
ds_num; i++)
196 Transform<double, 3> ds_posture = (*
FS.back().posture)
197 * Translation<double, 3>(x_shift, y_shift, 0.0)
198 * AngleAxisd(angle_shift, Vector3d::UnitZ());
202 ds_zref = &next_zref;
207 FS.back().angle + angle_shift,
212 constraints_auto_ds));
231 const unsigned int shift_from_current_ms,
232 double *left_foot_pos,
233 double *right_foot_pos)
238 unsigned int shift_ms = shift_from_current_ms;
241 while (shift_ms > step_time_left)
243 shift_ms -= step_time_left;
245 if (support_number >=
FS.size())
249 step_time_left =
FS[support_number].time_left;
259 double theta = (double)
260 ((
FS[support_number].time_period - step_time_left) + shift_ms)
261 /
FS[support_number].time_period;
317 fixed_fs_type =
FS[ind].type;
319 for (; (ind < (int)
FS.size()) && (
FS[ind].type != fixed_fs_type); ++ind);
321 Translation<double, 3> diff(diff_x, diff_y, 0.0);
323 for (; ind < (int)
FS.size(); ++ind)
325 *
FS[ind].posture = diff * (*
FS[ind].posture);
326 FS[ind].rotate_translate(
FS[ind].ca,
FS[ind].sa,
FS[ind].x(),
FS[ind].y());
335 unsigned int step_time_left =
FS[win_step_num].time_left;
338 for (
unsigned int i = 0; i <
N;)
340 if (step_time_left > 0)
342 par.
angle[i] =
FS[win_step_num].angle;
344 par.
fp_x[i] =
FS[win_step_num].x();
345 par.
fp_y[i] =
FS[win_step_num].y();
349 par.
zref_x[i] =
FS[win_step_num].ZMPref.x();
350 par.
zref_y[i] =
FS[win_step_num].ZMPref.y();
353 par.
lb[i*2] = -
FS[win_step_num].d[2];
354 par.
ub[i*2] =
FS[win_step_num].d[0];
356 par.
lb[i*2 + 1] = -
FS[win_step_num].d[3];
357 par.
ub[i*2 + 1] =
FS[win_step_num].d[1];
360 unsigned int step_len_ms;
365 step_len_ms = step_time_left;
374 if (
T_ms[i] > step_time_left)
379 step_len_ms =
T_ms[i];
381 par.
T[i] = (double) step_len_ms / 1000;
382 step_time_left -= step_len_ms;
393 if (win_step_num ==
FS.size())
398 step_time_left =
FS[win_step_num].time_left;
426 FILE *file_op = fopen(filename.c_str(),
"w");
430 fprintf(stderr,
"Cannot open file (for writing)\n");
434 fprintf(file_op,
"%%\n%% Footsteps generated using the c++ version of the WMG\n%%\n\n");
435 fprintf(file_op,
"cla;\n");
436 fprintf(file_op,
"clear FS;\n\n");
439 for (i=0; i< (int)
FS.size(); i++ )
443 fprintf(file_op,
"FS(%i).a = %f;\nFS(%i).p = [%f;%f];\nFS(%i).d = [%f;%f;%f;%f];\n",
445 i+1,
FS[i].x(),
FS[i].y(),
446 i+1,
FS[i].d[0],
FS[i].d[1],
FS[i].d[2],
FS[i].d[3]);
448 fprintf(file_op,
"FS(%i).D = [%f %f;%f %f;%f %f;%f %f];\n",
449 i+1,
FS[i].D[0],
FS[i].D[4],
450 FS[i].D[1],
FS[i].D[5],
451 FS[i].D[2],
FS[i].D[6],
452 FS[i].D[3],
FS[i].D[7]);
454 fprintf(file_op,
"FS(%i).v = [%f %f; %f %f; %f %f; %f %f; %f %f];\n",
455 i+1,
FS[i].vert(0,0),
FS[i].vert(0,1),
456 FS[i].vert(1,0),
FS[i].vert(1,1),
457 FS[i].vert(2,0),
FS[i].vert(2,1),
458 FS[i].vert(3,0),
FS[i].vert(3,1),
459 FS[i].vert(0,0),
FS[i].vert(0,1));
463 fprintf(file_op,
"FS(%i).type = 1;\n\n", i+1);
467 fprintf(file_op,
"FS(%i).type = 2;\n\n", i+1);
472 fprintf(file_op,
"hold on\n");
473 fprintf(file_op,
"for i=1:length(FS)\n");
474 fprintf(file_op,
" if FS(i).type == 1;\n");
475 fprintf(file_op,
" plot (FS(i).p(1),FS(i).p(2),'gs','MarkerFaceColor','r','MarkerSize',2)\n");
476 fprintf(file_op,
" plot (FS(i).v(:,1), FS(i).v(:,2), 'c');\n");
477 fprintf(file_op,
" end\n");
478 fprintf(file_op,
" if FS(i).type == 2;\n");
479 fprintf(file_op,
" plot (FS(i).p(1),FS(i).p(2),'gs','MarkerFaceColor','g','MarkerSize',4)\n");
480 fprintf(file_op,
" plot (FS(i).v(:,1), FS(i).v(:,2), 'r');\n");
481 fprintf(file_op,
" end\n");
482 fprintf(file_op,
"end\n");
483 fprintf(file_op,
"grid on; %%axis equal\n");
489 std::vector<double> & x_coord,
490 std::vector<double> & y_coord,
491 std::vector<double> & angle_rot)
493 for (
unsigned int i = 0; i <
FS.size(); i++)
497 x_coord.push_back(
FS[i].x());
498 y_coord.push_back(
FS[i].y());
499 angle_rot.push_back(
FS[i].angle);
double step_height
The maximum height, that can be reached by a swing foot.
int getPrevSS(const int, const fs_type type=FS_TYPE_AUTO)
Returns index of the previous SS.
void getDSFeetPositions(const int, double *, double *)
Determine position and orientation of feet in DS.
double * zref_y
N reference coordinates of ZMP.
A container for parameters of the SMPC solver.
WMGret formPreviewWindow(smpc_parameters &)
Forms a preview window.
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).
defConstraints def_constraints
Default SS and DS constraints.
double bezier_inclination_2
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.
unsigned int last_time_decrement
double * fp_x
Coordinates of N points satisfying constraints,.
int getNextSS(const int, const fs_type type=FS_TYPE_AUTO)
Returns index of the next SS.
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.
void changeNextSSPosition(const double *posture, const bool zero_z_coordinate)
Changes position of the next SS.
double ds[4]
Both feet standing together.
bool use_user_constraints
Constraints given by the user, initialized to the default values on initialization.
unsigned int N
Number of iterations in a preview window.
double * lb
2*N bounds for coordinates of ZMP position.
void getFeetPositions(const unsigned int shift_from_current_ms, double *left_foot_pos, double *right_foot_pos)
Determine position and orientation of feet.
double auto_ds[4]
Automatically added DS.
bool isSupportSwitchNeeded()
Checks if the support foot switch is needed.
std::vector< footstep > FS
A vector of footsteps.
double * T
Norm of the acceleration due to gravity.
void FS2file(const std::string filename, const bool plot_ds=true)
Outputs the footsteps in FS to a Matlab/Octave script for plotting.
unsigned int sampling_period
double user_constraints_auto_ds[4]
Constraints given by the user, initialized to the default values on initialization.
int first_preview_step
The first step in the current preview window.
double bezier_inclination_1
double user_constraints[4]
Constraints given by the user, initialized to the default values on initialization.
double * ub
2*N bounds for coordinates of ZMP position.
double ss_left[4]
Support constraints with safety margin.
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.
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.
int current_step_number
This is the step in FS that is at the start of the current preview window.
void repositionFootsteps(const double diff_x, const double diff_y)
Reposition all subsequent footsteps that are not fixed at the current moment.
void addFootstep(const double, const double, const double, fs_type type=FS_TYPE_AUTO)
Adds a footstep to FS.
double * fp_y
Coordinates of N points satisfying constraints,.