TPIK  1.0
Task Priority Inverse Kinematics
Loading...
Searching...
No Matches
ReactiveTask.h
Go to the documentation of this file.
1#include "TPIKDefines.h"
2#include "TPIKExceptions.h"
3#include "Task.h"
4#include <eigen3/Eigen/Dense>
5#include <iostream>
6#include <rml/RML.h>
7
8namespace tpik {
9
10/*
11* @brief The ReactiveTask pure virtual class.
12* @details
13*/
14class ReactiveTask : public Task {
15public:
16 /*
17 * @brief ReactiveTask class constructor.
18 * @param ID - the task ID
19 * @param taskSpace - the task space
20 * @param dof - degrees of freedom
21 * @param taskOption - Enum class to handle the different task option modalities:
22 * - 0: Default,
23 * - 1: UseErrorNorm,
24 * - 2: ActiveOnNorm
25 */
26 ReactiveTask(const std::string ID, int taskSpace, int DoF, tpik::TaskOption taskOption);
27 /*
28 * @brief ~ReactiveTask default deconstructor.
29 */
30 ~ReactiveTask() override;
31 /*
32 * @brief Method returning and setting the task parameter.
33 * @return task parameter.
34 */
36 {
38 return taskParameter_;
39 }
40 /*
41 * @brief Method getting and setting the task parameter.
42 * @return Task parameter.
43 */
44 auto TaskParameter() const -> const struct TaskParameter& { return taskParameter_; }
45 /*
46 * @brief Method returning the task control variable.
47 */
48 auto ControlVariable() const -> const Eigen::VectorXd& { return x_; }
49 /*
50 * @brief Method setting the task type.
51 */
52 auto Type() -> TaskType&
53 {
54 isTaskTypeSet_ = true;
55 return taskType_;
56 }
57 /*
58 * @brief Method getting the task type.
59 * @return task type.
60 */
61 auto Type() const -> const TaskType& { return taskType_; }
62 /*
63 * @brief Method setting the greaternThan params.
64 */
70 /*
71 * @brief Method getting the greaternThan params.
72 */
74 /*
75 * @brief Method setting the lessThan params
76 */
82 /*
83 * @brief Method getting the lessThan params
84 */
86 /*
87 * @brief Method used setting the control vector reference.
88 */
89 auto Reference() -> Eigen::VectorXd& { return x_bar_; }
90 /*
91 * @brief Method getting control vector reference.
92 */
93 auto Reference() const -> const Eigen::VectorXd& { return x_bar_; }
94 /*
95 * @brief Method to config from file the task
96 */
97 bool ConfigFromFile(libconfig::Config& confObj) noexcept(false) override;
98 /*
99 * @brief Added the saturation on the reference rate on the update
100 */
101 void Update() override;
102 /*
103 * @brief Overload of the cout operator.
104 */
105 friend std::ostream& operator<<(std::ostream& os, ReactiveTask const& reactiveTask)
106 {
107 os << "\033[1;37m"
108 << static_cast<const Task&>(reactiveTask) << "\n";
110 os << "x_ \n"
111 << "\033[0m" << reactiveTask.x_.norm() << "\n";
112 } else {
113 os << "x_ \n"
114 << "\033[0m" << reactiveTask.x_ << "\n";
115 }
116 os << "\033[0m" << reactiveTask.taskParameter_ << "\n";
117 if (reactiveTask.taskType_ == tpik::TaskType::Inequality && reactiveTask.isLessThanParamsInizialized_) {
118 os << "Less Then Params \n"
119 << "\033[0m" << reactiveTask.increasingBellShapeParameter_ << "\n";
120 } else if (reactiveTask.taskType_ == tpik::TaskType::Inequality && reactiveTask.isGreaterThanParamsInizialized_) {
121 os << "Greater Than Params\n"
122 << "\033[0m" << reactiveTask.decreasingBellShapeParameter_ << "\n";
123 }
124
125 return os;
126 }
127
128protected:
129 /*
130 * @brief Implementation of the pure virtual method of the base class Task used to update the internal activation function.
131 * Such method must be called in the Update method.
132 */
134 /*
135 * @brief Method updating the reference for reactive task.
136 */
137 virtual void UpdateReference();
138 /*
139 * @brief Implementation of the pure virtual method of the base class Task used to update the task reference rate.
140 * Such method must be called in the Update method.
141 */
142 void UpdateReferenceRate() override;
143 /*
144 * @brief Method updating the Jacobian.
145 * Implementation of the pure virtual method of the base class tpik::Task.
146 */
147 void UpdateJacobian() override;
148 /*
149 * @brief Method used to saturate the reference, such method must be called in the Update() method after the
150 * UpdateReference method.
151 */
153 /*
154 * @brief Method used to check the initialization, hence that all the task parameters have been initializated before updating the task.
155 * Such meethod must be called in the Update() method before any other method.
156 * @note An exception is thrown if the task parameter has not been initialized yet.
157 */
158 virtual void CheckInitialization() noexcept(false);
159
160 Eigen::VectorXd x_; // The control vector
161 Eigen::VectorXd x_bar_; // The control vector reference
162 struct TaskParameter taskParameter_; // The tpik::TaskParameter.
164 BellShapedParameter decreasingBellShapeParameter_; // The bell shape struct when the task type is inequality in between
165 TaskType taskType_; // Enum stating whether the task type is either inequality greather then, inequality less then, inequality in beteeen or equality
166 bool initializedTaskParameter_; // Boolean stating whether the task parameter have been initialized
167 bool isLessThanParamsInizialized_, isGreaterThanParamsInizialized_; // Boolean stating whether the bell shaped parameters have been initialized
168 bool isTaskTypeSet_; // Boolean stating whether the task type has been set
169 TaskOption taskOption_; // use ActivateOnNorm or ErrorNorm
170 bool saturateRaferenceRateComponentWise_; //flag to check if the refarence rate must be saturete as vector or component by component; // flag to check if the refarence rate must be saturete as vector or component by component
171 Eigen::MatrixXd AgreaterThan_, AlessThan_; // matrix containing the Activation value for the less than and greater than control objetive
172};
173}
Definition ReactiveTask.h:14
bool isLessThanParamsInizialized_
Definition ReactiveTask.h:167
struct TaskParameter taskParameter_
Definition ReactiveTask.h:162
virtual void CheckInitialization() noexcept(false)
friend std::ostream & operator<<(std::ostream &os, ReactiveTask const &reactiveTask)
Definition ReactiveTask.h:105
Eigen::MatrixXd AgreaterThan_
Definition ReactiveTask.h:171
auto Type() const -> const TaskType &
Definition ReactiveTask.h:61
TaskOption taskOption_
Definition ReactiveTask.h:169
~ReactiveTask() override
bool isTaskTypeSet_
Definition ReactiveTask.h:168
bool saturateRaferenceRateComponentWise_
Definition ReactiveTask.h:170
bool initializedTaskParameter_
Definition ReactiveTask.h:166
ReactiveTask(const std::string ID, int taskSpace, int DoF, tpik::TaskOption taskOption)
auto Reference() -> Eigen::VectorXd &
Definition ReactiveTask.h:89
void Update() override
void SaturateReferenceRate()
auto TaskParameter() const -> const struct TaskParameter &
Definition ReactiveTask.h:44
void UpdateJacobian() override
auto LessThanParams() -> tpik::BellShapedParameter &
Definition ReactiveTask.h:77
auto Reference() const -> const Eigen::VectorXd &
Definition ReactiveTask.h:93
auto GreaterThanParams() -> tpik::BellShapedParameter &
Definition ReactiveTask.h:65
Eigen::MatrixXd AlessThan_
Definition ReactiveTask.h:171
auto ControlVariable() const -> const Eigen::VectorXd &
Definition ReactiveTask.h:48
bool isGreaterThanParamsInizialized_
Definition ReactiveTask.h:167
auto Type() -> TaskType &
Definition ReactiveTask.h:52
auto TaskParameter() -> TaskParameter &
Definition ReactiveTask.h:35
virtual void UpdateReference()
Eigen::VectorXd x_bar_
Definition ReactiveTask.h:161
Eigen::VectorXd x_
Definition ReactiveTask.h:160
auto LessThanParams() const -> const BellShapedParameter &
Definition ReactiveTask.h:85
BellShapedParameter decreasingBellShapeParameter_
Definition ReactiveTask.h:164
bool ConfigFromFile(libconfig::Config &confObj) noexcept(false) override
void UpdateReferenceRate() override
BellShapedParameter increasingBellShapeParameter_
Definition ReactiveTask.h:163
TaskType taskType_
Definition ReactiveTask.h:165
void UpdateInternalActivationFunction() override
auto GreaterThanParams() const -> const BellShapedParameter &
Definition ReactiveTask.h:73
Definition Task.h:27
auto ID() const -> const std::string &
Definition Task.h:90
auto DoF() const -> int
Definition Task.h:74
Definition Action.h:9
TaskOption
Definition TPIKDefines.h:105
TaskType
Definition TPIKDefines.h:100
Parameter used to define a bell shaped function. Used to create either an increasing or a decreasing ...
Definition TPIKDefines.h:15
Task Parameter, used both in the equality and inequality task.
Definition TPIKDefines.h:48