humoto
task_basecom.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 base CoM tracking
18  */
20  {
21  #define HUMOTO_CONFIG_ENTRIES \
22  HUMOTO_CONFIG_PARENT_CLASS(TaskAB) \
23  HUMOTO_CONFIG_SCALAR_(k_position_gain)
24  #include HUMOTO_CONFIG_DEFINE_ACCESSORS
25 
26 
27  protected:
29 
30 
31  protected:
32  TaskBaseCoMTrackingBase(const std::string & id,
33  const double gain,
34  const double k_position_gain) : TaskAB(id, gain)
35  {
36  k_position_gain_ = k_position_gain;
37  }
38 
39 
40  virtual void setDefaults()
41  {
43  k_position_gain_ = 0.0;
44  }
45 
46 
47  /**
48  * @brief Log task.
49  *
50  * @param[in] logger logger
51  * @param[in] parent parent
52  * @param[in] name name
53  */
55  const LogEntryName &parent = LogEntryName(),
56  const std::string &name = "task") const
57  {
58  LogEntryName subname = parent; subname.add(name);
59  TaskAB::logTask(logger, subname, "");
60  logger.log(LogEntryName(subname).add("k_position_gain"), k_position_gain_);
61  }
62  };
63 
64 
65 
66  /**
67  * @brief base CoM tracking
68  */
69  template <int t_features>
71  {
72  public:
73  TaskBaseCoMTracking(const double gain = 1.0,
74  const double k_position_gain = 1.0) : TaskBaseCoMTrackingBase( "TaskBaseCoMTracking",
75  gain,
76  k_position_gain) {}
77 
78  /// @copydoc humoto::TaskBase::form
79  void form( const humoto::SolutionStructure &sol_structure,
80  const humoto::Model &model_base,
81  const humoto::ControlProblem &control_problem)
82  {
84  dynamic_cast <const WholeBodyController<t_features> &>(control_problem);
85 
86  const Model<t_features> &model =
87  dynamic_cast <const Model<t_features> &>(model_base);
88 
89  Eigen::MatrixXd &A = getA();
90  Eigen::VectorXd &b = getB();
91 
92 
93  model.getBaseCoMJacobian(A);
94  b = k_position_gain_ * (wbc.motion_parameters_.base_com_position_ - model.getBaseCoM());
95 
96  if(! isApproximatelyEqual(1.0, getGain()))
97  {
98  A*=getGain();
99  b*=getGain();
100  }
101  }
102  };
103 
104 
105 
106  /**
107  * @brief base CoM tracking
108  */
109 #ifdef HUMOTO_DOXYGEN_PROCESSING
110  template <>
111  class HUMOTO_LOCAL TaskBaseCoMTracking<FIXED_WHEELS | ROOT_PLANAR>
112  : public TaskBaseCoMTrackingBase
113 #else
114  // Doxygen chokes on this for some reason
115  template <>
116  class HUMOTO_LOCAL TaskBaseCoMTracking<ModelFeatures::FIXED_WHEELS | ModelFeatures::ROOT_PLANAR>
117  : public TaskBaseCoMTrackingBase
118 #endif
119  {
120  public:
121  TaskBaseCoMTracking(const double gain = 1.0,
122  const double k_position_gain = 1.0) : TaskBaseCoMTrackingBase( "TaskBaseCoMTracking",
123  gain,
124  k_position_gain) {}
125 
126 
127  /// @copydoc humoto::TaskBase::form
128  void form( const humoto::SolutionStructure &sol_structure,
129  const humoto::Model &model_base,
130  const humoto::ControlProblem &control_problem)
131  {
134 
136  dynamic_cast <const Model<ModelFeatures::FIXED_WHEELS | ModelFeatures::ROOT_PLANAR> &>(model_base);
137 
138 
139  Eigen::MatrixXd &A = getA();
140  Eigen::VectorXd &b = getB();
141 
142 
143  model.getBaseCoMJacobian(A);
144  A.conservativeResize(2, A.cols());
145 
146  etools::Vector3 com = model.getBaseCoM();
147  b = k_position_gain_ * (wbc.motion_parameters_.base_com_position_.segment(0,2) - com.segment(0,2));
148 
149  if(! isApproximatelyEqual(1.0, getGain()))
150  {
151  A*=getGain();
152  b*=getGain();
153  }
154  }
155  };
156  }//pepper
157 }//humoto
Abstract base class (for control problems)
#define HUMOTO_LOCAL
Definition: export_import.h:26
void form(const humoto::SolutionStructure &sol_structure, const humoto::Model &model_base, const humoto::ControlProblem &control_problem)
Form the task.
Definition: task_basecom.h:128
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
etools::Vector3 base_com_position_
Definition: common.h:90
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
Represents log entry name.
Definition: logger.h:169
TaskBaseCoMTrackingBase(const std::string &id, const double gain, const double k_position_gain)
Definition: task_basecom.h:32
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
virtual void setDefaults()
Set members to their default values.
Definition: task_basecom.h:40
TaskBaseCoMTracking(const double gain=1.0, const double k_position_gain=1.0)
Definition: task_basecom.h:121
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 logTask(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="task") const
Log task.
Definition: task_basecom.h:54
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
TaskBaseCoMTracking(const double gain=1.0, const double k_position_gain=1.0)
Definition: task_basecom.h:73
void form(const humoto::SolutionStructure &sol_structure, const humoto::Model &model_base, const humoto::ControlProblem &control_problem)
Form the task.
Definition: task_basecom.h:79