humoto
task_footstepbounds.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @author Don Joven Agravante
5  @author Jan Michalczyk
6  @copyright 2014-2017 INRIA, 2014-2015 CNRS. Licensed under the Apache
7  License, Version 2.0. (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
8  @brief
9 */
10 
11 #pragma once
12 
13 namespace humoto
14 {
15  namespace wpg04
16  {
17  /**
18  * @brief [task_footstepbounds.m]
19  */
21  {
22  #define HUMOTO_CONFIG_ENTRIES \
23  HUMOTO_CONFIG_PARENT_CLASS(TaskILU) \
24  HUMOTO_CONFIG_SCALAR_(fix_footsteps)
25  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
26 
27 
28  //private:
29  public:
31 
32 
33  protected:
34  void setDefaults()
35  {
37  fix_footsteps_ = false;
38  }
39 
40 
41  public:
42  explicit TaskFootstepBounds(const bool fix_footsteps = false)
43  : TaskILU("TaskFootstepBounds")
44  {
45  fix_footsteps_ = fix_footsteps;
46  }
47 
48 
49  /// @copydoc humoto::TaskBase::form
50  void form( const humoto::SolutionStructure &sol_structure,
51  const humoto::Model &model_base,
52  const humoto::ControlProblem &control_problem)
53  {
54  const humoto::wpg04::MPCforWPG &mpc = dynamic_cast <const humoto::wpg04::MPCforWPG &> (control_problem);
55 
56  Location loc_var = sol_structure.getSolutionPartLocation(FOOTPOS_VARIABLES_ID);
57 
58 
59  humoto::IndexVector &I = getIndices();
60  Eigen::VectorXd &lb = getLowerBounds();
61  Eigen::VectorXd &ub = getUpperBounds();
62 
63  I.resize(loc_var.length_);
64  lb.resize(loc_var.length_);
65  ub.resize(loc_var.length_);
66 
67  for(std::size_t i = 0; i < mpc.preview_horizon_.variable_steps_indices_.size(); ++i)
68  {
69  I[i*2] = loc_var.offset_ + i*2;
70  I[i*2+1] = loc_var.offset_ + i*2 + 1;
71 
72  lb.segment(i*2, 2) = mpc.preview_horizon_.getFootPositionBounds(i).col(0);
73  ub.segment(i*2, 2) = mpc.preview_horizon_.getFootPositionBounds(i).col(1);
74 
75  // fixed footsteps lb = ub
76  if(fix_footsteps_)
77  {
78  std::size_t interval_index = mpc.preview_horizon_.variable_steps_indices_[i];
80  {
81  lb.segment(i*2, 1) = ub.segment(i*2, 1);
82  lb.segment(i*2+1, 1) = ub.segment(i*2+1, 1);
83  }
84  else
85  {
86  lb.segment(i*2, 1) = ub.segment(i*2, 1);
87  ub.segment(i*2+1, 1) = lb.segment(i*2+1, 1);
88  }
89  }
90  }
91  }
92 
93 
94  /// @copydoc humoto::TaskBase::guessActiveSet
95  void guessActiveSet(const humoto::SolutionStructure &sol_structure,
96  const humoto::Model &model_base,
97  const humoto::ControlProblem &control_problem)
98  {
99  Location loc_var = sol_structure.getSolutionPartLocation(FOOTPOS_VARIABLES_ID);
100  std::size_t size_of_the_old_active_set = getActualActiveSet().size();
101 
102 
103  if (fix_footsteps_)
104  {
105  getActiveSetGuess().initialize(loc_var.length_, ConstraintActivationType::EQUALITY);
106  }
107  else
108  {
109  if (size_of_the_old_active_set == 0)
110  {
111  getActiveSetGuess().initialize(loc_var.length_, ConstraintActivationType::INACTIVE);
112  }
113  else
114  {
115  if (size_of_the_old_active_set == loc_var.length_)
116  {
117  getActiveSetGuess() = getActualActiveSet();
118  }
119  else
120  {
121  if (size_of_the_old_active_set > loc_var.length_)
122  {
123  Location loc_act_set(2, size_of_the_old_active_set - 2);
124 
125  getActiveSetGuess().initialize(getActualActiveSet(), loc_act_set);
126  }
127  else
128  {
129  Location loc_act_set(0, size_of_the_old_active_set);
130 
131  getActiveSetGuess().initialize(loc_var.length_, ConstraintActivationType::INACTIVE);
132  getActiveSetGuess().copyTo(loc_act_set, getActualActiveSet());
133  }
134  }
135  }
136  }
137  }
138  };
139  }
140 }
Abstract base class (for control problems)
etools::Matrix2 getFootPositionBounds(const std::size_t var_support_index) const
Get bounds on foot position.
#define HUMOTO_LOCAL
Definition: export_import.h:26
Constraint is an equality (always active)
Definition: active_set.h:35
void setDefaults()
Set members to their default values.
Analog of &#39;sol_structure&#39; struct in Octave code. [determine_solution_structure.m].
Definition: solution.h:33
TaskFootstepBounds(const bool fix_footsteps=false)
std::size_t length_
Definition: utility.h:150
void form(const humoto::SolutionStructure &sol_structure, const humoto::Model &model_base, const humoto::ControlProblem &control_problem)
Form the task.
Eigen::Matrix< unsigned int, Eigen::Dynamic, 1 > IndexVector
Definition: utility.h:19
void guessActiveSet(const humoto::SolutionStructure &sol_structure, const humoto::Model &model_base, const humoto::ControlProblem &control_problem)
Initialize active set guess with defaults.
Task: lb <= x[I] <= ub.
Definition: task.h:572
static const char * FOOTPOS_VARIABLES_ID
Definition: common.h:18
Location getSolutionPartLocation(const std::string &id) const
Get location of a data in the solution vector.
Definition: solution.h:122
Model Predictive Control problem for walking pattern generation [determine_solution_structure.m, form_rotation_matrices.m, form_foot_pos_matrices.m, form_condensing_matrices.m].
Definition: mpc_wpg.h:21
const WalkState & getWalkState(const std::size_t interval_index) const
Get walk state corresponding to the given interval.
The root namespace of HuMoTo.
Definition: config.h:12
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
virtual void setDefaults()
Set members to their default values.
Definition: task.h:128
Location of a data chunk (offset + length).
Definition: utility.h:146
std::vector< std::size_t > variable_steps_indices_
humoto::wpg04::PreviewHorizon preview_horizon_
Definition: mpc_wpg.h:230