ocra-recipes
Doxygen documentation for the ocra-recipes repository
Task.h
Go to the documentation of this file.
1 #ifndef _OCRA_TASK_API_H_
2 #define _OCRA_TASK_API_H_
3 
5 #include <Eigen/Core>
6 #include <ocra/util/Macros.h>
9 #include "ocra/control/Feature.h"
10 #include "ocra/control/Model.h"
11 //
12 
13 
14 
18 #include "ocra/control/Task.h"
19 #include "ocra/control/TaskState.h"
26 
27 
28 
29 
30 
31 namespace ocra
32 {
33 
34 class Task : public NamedInstance
35 {
37 
38 public:
39  Task(const std::string& name, std::shared_ptr<Model> model, Feature::Ptr feature, Feature::Ptr featureDes);
40  Task(const std::string& name, std::shared_ptr<Model> model, Feature::Ptr feature);
41  virtual ~Task();
42 
43 
50  COM,
57  };
58 
60 
63  void setDesiredTaskState(const TaskState& newDesiredTaskState);
64  void setDesiredTaskStateDirect(const TaskState& newDesiredTaskState);
65 
66  int getHierarchyLevel();
67  void setHierarchyLevel(int level);
68  void update();
69 
70  // TODO: Need to rethink this... Basically the way a task error is computed in the controller depends on the TYPETASK enum. Unfortunately, it is useful to know specifically what type of task you have even if it is only a subset of TYPETASK. For example, POSE and PARTIAL_POSTURE are both ACCELERATIONTASK but their internals are quite different. Eventually we need to just use the META_TASK_TYPE representation on the user end but inside the Task class we can have access to the TYPETASK in order to determine the error calculation method.
71 
72  void setMetaTaskType(Task::META_TASK_TYPE newMetaTaskType);
74  std::string getMetaTaskTypeAsString();
75 
76  void setTaskType(Task::TYPETASK newTaskType);
78 
79  void activateAsObjective();
80  void activateAsConstraint();
81  void deactivate();
82  bool isActiveAsObjective() const;
83  bool isActiveAsConstraint() const;
84 
86  void setDesiredMass(double Md);
87  void setDesiredMass(const Eigen::VectorXd& Md);
88  void setDesiredMass(const Eigen::MatrixXd& Md);
89 
90  void setDamping(double B);
91  void setDamping(const Eigen::VectorXd& B);
92  void setDamping(const Eigen::MatrixXd& B);
93 
94  void setStiffness(double K);
95  void setStiffness(const Eigen::VectorXd& K);
96  void setStiffness(const Eigen::MatrixXd& K);
97 
98  void setAutoGains(double freq);
99  void setAutoGains(double freq, double massSaturation);
100 
101  bool isDesiredMassTheActualOne() const;
102  const Eigen::MatrixXd& getDesiredMass() const;
103  const Eigen::MatrixXd& getDesiredMassInverse() const;
104  const Eigen::MatrixXd& getDamping() const;
105  const Eigen::MatrixXd& getStiffness() const;
106 
107  void activateContactMode();
108  void deactivateContactMode();
109  bool isContactModeActive() const;
110 
111  bool isBodyContactConstraint() const;
112  bool isPointContactTask() const;
113 
114  double getFrictionCoeff() const;
115  double getMargin() const;
116  const Eigen::Vector3d& getFrictionConstraintOffset() const;
117  void setFrictionCoeff(double coeff);
118  void setMargin(double margin);
119  void setFrictionConstraintOffset(const Eigen::Vector3d& offset);
120 
121  void setWeight(double weight);
122  void setWeight(const Eigen::VectorXd& weight);
123  const Eigen::VectorXd& getWeight() const;
124 
125  int getDimension() const;
126  const Eigen::VectorXd& getOutput() const;
127  const Eigen::VectorXd& getError() const;
128  const Eigen::VectorXd& getErrorDot() const;
129  const Eigen::VectorXd& getErrorDdot() const;
130  const Eigen::VectorXd& getEffort() const;
131  const Eigen::MatrixXd& getJacobian() const;
132 
133 protected:
134  Feature::Ptr getFeature() const;
135  Feature::Ptr getFeatureDes() const;
136 
137 protected:
138  void doActivateAsObjective();
139  void doActivateAsConstraint();
140  void doActivateContactMode();
144  void doSetFrictionCoeff();
145  void doSetMargin();
146  void doSetWeight();
147  void doGetOutput(Eigen::VectorXd& output) const;
148 
149 
150 private:
151  struct Pimpl;
152  std::shared_ptr<Pimpl> pimpl;
153 
154 
155 public:
156  const Eigen::VectorXd& getComputedForce() const;
158  void connectToController(std::shared_ptr<OneLevelSolver> _solver, const FullDynamicEquationFunction& dynamicEquation, bool useReducedProblem);
159 
160 protected:
161  void addContactPointInModel();
163 
164  void updateAccelerationTask();
165  void updateTorqueTask();
166  void updateForceTask();
167  void updateCoMMomentumTask();
168 
169  void checkIfConnectedToController() const;
170 
171 
172 
173 
174 };
175 }
176 #endif
177 
178 // cmake:sourcegroup=Api
void doSetFrictionCoeff()
Definition: Task.cpp:890
const Eigen::MatrixXd & getJacobian() const
Definition: Task.cpp:600
void doDeactivateAsObjective()
Definition: Task.cpp:935
double getMargin() const
Definition: Task.cpp:527
Classes that represent frames.
void setDamping(double B)
Definition: Task.cpp:378
void setDesiredTaskState(const TaskState &newDesiredTaskState)
Definition: Task.cpp:1014
void doSetMargin()
Definition: Task.cpp:899
const Eigen::VectorXd & getErrorDot() const
Definition: Task.cpp:582
Declaration file of the SquaredLinearFunction class.
Define the internal solver class that can be used in the wOcra controller.
Declaration file of the Model class.
bool isActiveAsObjective() const
Definition: Task.cpp:343
const Eigen::MatrixXd & getDamping() const
Definition: Task.cpp:466
void activateAsConstraint()
Definition: Task.cpp:312
const Eigen::VectorXd & getError() const
Definition: Task.cpp:576
int getDimension() const
Definition: Task.cpp:565
void update()
Definition: Task.cpp:259
void doActivateAsConstraint()
Definition: Task.cpp:954
void setFrictionConstraintOffset(const Eigen::Vector3d &offset)
Definition: Task.cpp:555
void doActivateContactMode()
Definition: Task.cpp:857
A class hierarchy to compute task errors based on control frames.
const Eigen::Vector3d & getFrictionConstraintOffset() const
Definition: Task.cpp:532
void setTaskType(Task::TYPETASK newTaskType)
Definition: Task.cpp:187
TYPETASK
Definition: Task.h:59
TaskState getTaskState()
Definition: Task.cpp:1004
void updateAccelerationTask()
Definition: Task.cpp:766
const Eigen::MatrixXd & getDesiredMassInverse() const
Definition: Task.cpp:453
void disconnectFromController()
Definition: Task.cpp:644
#define DEFINE_CLASS_POINTER_TYPEDEFS(Class)
Definition: Macros.h:8
const Eigen::VectorXd & getErrorDdot() const
Definition: Task.cpp:588
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Task::META_TASK_TYPE getMetaTaskType()
Definition: Task.cpp:230
bool isBodyContactConstraint() const
Definition: Task.cpp:512
void updateForceTask()
Definition: Task.cpp:807
Feature::Ptr getFeature() const
Definition: Task.cpp:606
void addContactPointInModel()
Definition: Task.cpp:713
void deactivate()
Definition: Task.cpp:326
void updateCoMMomentumTask()
Definition: Task.cpp:817
void doSetWeight()
Definition: Task.cpp:993
Task(const std::string &name, std::shared_ptr< Model > model, Feature::Ptr feature, Feature::Ptr featureDes)
Definition: Task.cpp:171
virtual ~Task()
Definition: Task.cpp:183
void doDeactivateAsConstraint()
Definition: Task.cpp:972
std::string getMetaTaskTypeAsString()
Definition: Task.cpp:235
META_TASK_TYPE
Definition: Task.h:44
void setAutoGains(double freq)
Definition: Task.cpp:412
void checkIfConnectedToController() const
Definition: Task.cpp:841
Declaration file of the WeightedSquareDistanceFunction class.
void setDesiredTaskStateDirect(const TaskState &newDesiredTaskState)
Definition: Task.cpp:1019
Create a linear function that represents the dynamic equation of motion.
Declaration file of the LinearizedCoulombFunction class.
bool isActiveAsConstraint() const
Definition: Task.cpp:348
bool isDesiredMassTheActualOne() const
Definition: Task.cpp:436
Task::TYPETASK getTaskType()
Definition: Task.cpp:216
void setHierarchyLevel(int level)
Definition: Task.cpp:199
void setMetaTaskType(Task::META_TASK_TYPE newMetaTaskType)
Definition: Task.cpp:221
const Eigen::VectorXd & getComputedForce() const
Definition: Task.cpp:639
double getFrictionCoeff() const
Definition: Task.cpp:522
void setMargin(double margin)
Definition: Task.cpp:543
void setWeight(double weight)
Definition: Task.cpp:501
void deactivateContactMode()
Definition: Task.cpp:490
void setStiffness(double K)
Definition: Task.cpp:395
bool isPointContactTask() const
Definition: Task.cpp:517
void setDesiredMass(double Md)
Definition: Task.cpp:358
const Eigen::VectorXd & getEffort() const
Definition: Task.cpp:594
void doActivateAsObjective()
Definition: Task.cpp:916
Feature::Ptr getFeatureDes() const
Definition: Task.cpp:611
bool isContactModeActive() const
Definition: Task.cpp:507
void setDesiredMassToActualOne()
Definition: Task.cpp:353
void doDeactivateContactMode()
Definition: Task.cpp:874
void updateTorqueTask()
Definition: Task.cpp:797
void activateAsObjective()
Definition: Task.cpp:298
const Eigen::VectorXd & getOutput() const
Definition: Task.cpp:570
const Eigen::VectorXd & getWeight() const
Definition: Task.cpp:560
void connectToController(std::shared_ptr< OneLevelSolver > _solver, const FullDynamicEquationFunction &dynamicEquation, bool useReducedProblem)
Definition: Task.cpp:668
void removeContactPointInModel()
Definition: Task.cpp:729
int getHierarchyLevel()
Definition: Task.cpp:195
Define base class that can be used as constraints in wOcra controller.
void doGetOutput(Eigen::VectorXd &output) const
Definition: Task.cpp:633
TaskState getDesiredTaskState()
Definition: Task.cpp:1009
const Eigen::MatrixXd & getStiffness() const
Definition: Task.cpp:471
void activateContactMode()
Definition: Task.cpp:476
const Eigen::MatrixXd & getDesiredMass() const
Definition: Task.cpp:441
void setFrictionCoeff(double coeff)
Definition: Task.cpp:537