humoto
task_bodycom.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
5  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6 
7  @brief
8 */
9 
10 #pragma once
11 
12 namespace humoto
13 {
14  namespace pepper_ik
15  {
16  /**
17  * @brief body CoM tracking
18  */
19  template <int t_features>
21  {
22  #define HUMOTO_CONFIG_ENTRIES \
23  HUMOTO_CONFIG_PARENT_CLASS(TaskAB) \
24  HUMOTO_CONFIG_SCALAR_(k_position_gain) \
25  HUMOTO_CONFIG_SCALAR_(axis_flag)
26  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
27 
28 
29  private:
32 
33 
34  protected:
35  virtual void setDefaults()
36  {
38  k_position_gain_ = 0.0;
39  }
40 
41 
42  /**
43  * @brief Log task.
44  *
45  * @param[in] logger logger
46  * @param[in] parent parent
47  * @param[in] name name
48  */
50  const LogEntryName &parent = LogEntryName(),
51  const std::string &name = "task") const
52  {
53  LogEntryName subname = parent; subname.add(name);
54  TaskAB::logTask(logger, subname, "");
55  logger.log(LogEntryName(subname).add("k_position_gain"), k_position_gain_);
56  logger.log(LogEntryName(subname).add("axis_flag"), axis_flag_);
57  }
58 
59 
60  public:
61  TaskBodyCoMTracking(const double gain = 1.0,
62  const double k_position_gain = 1.0,
63  const int axis_flag = AxisIndex::FLAG_X | AxisIndex::FLAG_Y | AxisIndex::FLAG_Z,
64  const char * description = "TaskBodyCoMTracking")
65  : TaskAB(description, gain)
66  {
67  k_position_gain_ = k_position_gain;
68  axis_flag_ = axis_flag;
69  }
70 
71 
72  /// @copydoc humoto::TaskBase::form
73  void form( const humoto::SolutionStructure &sol_structure,
74  const humoto::Model &model_base,
75  const humoto::ControlProblem &control_problem)
76  {
78  dynamic_cast <const humoto::pepper_ik::WholeBodyController<t_features> &>(control_problem);
79 
80  const Model<t_features> &model =
81  dynamic_cast <const humoto::pepper_ik::Model<t_features> &>(model_base);
82 
83  Eigen::MatrixXd &A = getA();
84  Eigen::VectorXd &b = getB();
85 
86  etools::Vector3 com = model.getBodyCoM();
87 
89  if (all_flags_set == axis_flag_)
90  {
91  model.getBodyCoMJacobian(A);
92  b = k_position_gain_ * (wbc.motion_parameters_.body_com_position_ - com);
93  }
94  else
95  {
96  Eigen::MatrixXd A_tmp;
97  Eigen::VectorXd b_tmp;
98 
99  EigenIndex num = 0;
100 
101 
102  if (AxisIndex::FLAG_X & axis_flag_)
103  {
104  ++num;
105  }
106  if (AxisIndex::FLAG_Y & axis_flag_)
107  {
108  ++num;
109  }
110  if (AxisIndex::FLAG_Z & axis_flag_)
111  {
112  ++num;
113  }
114 
115  if ( (num == 0)
116  || ((all_flags_set | axis_flag_) != all_flags_set) )
117  {
118  HUMOTO_THROW_MSG(std::string("Wrong set of flags in task '") + getDescription() + "'.");
119  }
120 
121 
122  model.getBodyCoMJacobian(A_tmp);
123  b_tmp = k_position_gain_ * (wbc.motion_parameters_.body_com_position_ - com);
124 
125 
126  A.resize(num, A_tmp.cols());
127  b.resize(num);
128 
129  num = 0;
130  if (AxisIndex::FLAG_X & axis_flag_)
131  {
132  A.row(num) = A_tmp.row(AxisIndex::X);
133  b(num) = b_tmp(AxisIndex::X);
134  ++num;
135  }
136  if (AxisIndex::FLAG_Y & axis_flag_)
137  {
138  A.row(num) = A_tmp.row(AxisIndex::Y);
139  b(num) = b_tmp(AxisIndex::Y);
140  ++num;
141  }
142  if (AxisIndex::FLAG_Z & axis_flag_)
143  {
144  A.row(num) = A_tmp.row(AxisIndex::Z);
145  b(num) = b_tmp(AxisIndex::Z);
146  ++num;
147  }
148  }
149 
150  if(! isApproximatelyEqual(1.0, getGain()))
151  {
152  A*=getGain();
153  b*=getGain();
154  }
155  }
156  };
157  }//pepper
158 }//humoto
Abstract base class (for control problems)
TaskBodyCoMTracking(const double gain=1.0, const double k_position_gain=1.0, const int axis_flag=AxisIndex::FLAG_X|AxisIndex::FLAG_Y|AxisIndex::FLAG_Z, const char *description="TaskBodyCoMTracking")
Definition: task_bodycom.h:61
#define HUMOTO_LOCAL
Definition: export_import.h:26
virtual void logTask(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="task") const
Log task.
Definition: task.h:347
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
Definition: logger.h:997
Analog of &#39;sol_structure&#39; struct in Octave code. [determine_solution_structure.m].
Definition: solution.h:33
virtual void setDefaults()
Set members to their default values.
Definition: task.h:332
etools::Vector3 body_com_position_
Definition: common.h:91
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
Represents log entry name.
Definition: logger.h:169
EIGEN_DEFAULT_DENSE_INDEX_TYPE EigenIndex
Definition: utility.h:26
void form(const humoto::SolutionStructure &sol_structure, const humoto::Model &model_base, const humoto::ControlProblem &control_problem)
Form the task.
Definition: task_bodycom.h:73
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
Definition: logger.h:555
The root namespace of HuMoTo.
Definition: config.h:12
humoto::pepper_ik::MotionParameters motion_parameters_
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_bodycom.h:35
LogEntryName & add(const char *name)
extends entry name with a subname
Definition: logger.h:232
bool isApproximatelyEqual(const double var1, const double var2, const double tol=humoto::g_generic_tolerance)
Returns true if the difference between two given variables is below the given tolerance.
Definition: utility.h:87
Task: A*x = b.
Definition: task.h:542
virtual void logTask(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="task") const
Log task.
Definition: task_bodycom.h:49