TPIK  1.0
Task Priority Inverse Kinematics
Loading...
Searching...
No Matches
Task.h
Go to the documentation of this file.
1#ifndef TASK_H
2#define TASK_H
3
4#include "TPIKDefines.h"
5#include <eigen3/Eigen/Dense>
6#include <iomanip>
7#include <iostream>
8
9namespace tpik {
10/*
11 * @brief The Task virtual class.
12 *
13 * @details Implementation of the abstract Task base class characterized by its jacobian, activation functions and reference. The class objects can be
14 * gather in the PriorityLevel, organized in Action by using the ActionManager. Once defined, a task priority can be solved by using the
15 * Solver class. The derived classes must implement the following pure virtual methods:
16 *
17 * - UpdateJacobian() where the user must update the class variable J_ which stores the task jacobian;
18 *
19 * - UpdateInternalActivationFunction() where the user must update the class variabel Ai_ which stores the task activation function;
20 *
21 * - UpdateReferenceRate() where the user must update the variable x_dot which stores the task reference rate,
22 *
23 * - UpdateReference() where the user must update the variable x_ which stores the task reference,
24 *
25 * - Update() public method used to update the task variables.
26 */
27class Task {
28public:
29 /*
30 * @brief Constructor of Task Class.
31 * @details The Jacobian, reference and Internal Activation Function matrices are pre-allocated:
32 * - Jacobian (taskSpace x DoF)
33 * - Internal Activation Function (taskSpace x taskSpace)
34 * - External Activation Function (taskSpace x taskSpace)
35 * - ReferenceRate x_dot (taskSpace x 1)
36 * @param[in] ID: Task ID;
37 * @param[in] taskSpace: task space;
38 * @param[in] dof: Degrees of Freedom.
39 */
40 Task(const std::string ID, int taskSpace, int dof);
41 /*
42 * @brief Default De-constructor of Task Class.
43 */
44 virtual ~Task();
45 /*
46 * @brief Method returning the Jacobian Matrix of the Task.
47 * @return Jacobian Matrix.
48 */
49 auto Jacobian() const -> const Eigen::MatrixXd& { return J_; }
50 /*
51 * @brief Method returning the Internal Activation Function Matrix of the Task.
52 * @return Internal Activation Function.
53 */
54 auto InternalActivationFunction() const -> const Eigen::MatrixXd& { return Ai_; }
55 /*
56 * @brief Methods setting the external activation function
57 * @detrails This function must be use to active customly a task variable by setting to one the corresponding diagonal matrix selement
58 */
59 auto ExternalActivationFunction() -> Eigen::MatrixXd& { return Aexternal_; }
60 /*
61 * @brief Methods getting the external activation function
62 * @param Internal Activation Function.
63 */
64 auto ExternalActivationFunction() const -> const Eigen::MatrixXd& { return Aexternal_; }
65 /*
66 * @brief Method returning the Task Reference rate
67 * @return task Reference rate.
68 */
69 auto ReferenceRate() const -> const Eigen::VectorXd& { return x_dot_bar_; }
70 /*
71 * @brief Method returning the Task Degrees of Freedom.
72 * @return Degrees of Freedom.
73 */
74 auto DoF() const -> int { return dof_; }
75 /*
76 * @brief Method returning the Task Space.
77 * @return task Space.
78 */
79 auto TaskSpace() const -> int { return taskSpace_; }
80 /*
81 * @brief Method returning the task enable boolean.
82 * @return True if the task is enabled, false otherwise.
83 * @note If the task is disabled, the internal activation function is set to 0 in the tpik::PriorityLevel.
84 */
85 auto Enabled() const -> bool { return enabled_; }
86 /*
87 * @brief Method returning the task ID.
88 * @return task ID.
89 */
90 auto ID() const -> const std::string& { return ID_; }
91 /*
92 * @brief Pure Virtual Method to be implemented by the derived classes to update the task.
93 */
94 virtual void Update();
95 /*
96 * @brief Pure Virtual Method to config from file the task
97 * @details This method allows to read the task params form file using libconfig formalism. Alternately, it can be used the setting methods of the derived classes to acquired the params
98 */
99 virtual bool ConfigFromFile(libconfig::Config& confObj) noexcept(false) = 0;
100 /*
101 * @brief Overload of the cout operator.
102 */
103 friend std::ostream& operator<<(std::ostream& os, Task const& task)
104 {
105 return os << "\033[1;37m"
106 << "Task ID " << task.ID_ << "\n"
107 << std::setprecision(4) << "Internal Activation Function \n"
108 << "\033[0m" << task.Ai_ << "\n"
109 << "External Activation Function\n"
110 << "\033[0m" << task.Aexternal_ << "\n"
111 << "\033[1;37m"
112 << "Jacobian \n"
113 << "\033[0m" << task.J_ << "\n"
114 << "\033[1;37m"
115 << "Reference Rate \n"
116 << "\033[0m" << task.x_dot_bar_ << "\n";
117 }
118
119
120
121protected:
122 /*
123 * @brief Pure Virtual Method to be implemented by the derived classes to update the task internal activation function.
124 */
126 /*
127 * @brief Pure Virtual Method to be implemented by the derived classes to update the task reference rate.
128 */
129 virtual void UpdateReferenceRate() = 0;
130
131 /*
132 * @brief Pure Virtual Method to be implemented by the derived classes to update the task reference.
133 */
134 //virtual void UpdateReference() = 0;
135
136 /*
137 * @brief Pure Virtual Method to be implemented by the derived classes to update the task Jacobian.
138 */
139 virtual void UpdateJacobian() = 0;
140
141 std::string ID_; // The task ID.
142 Eigen::MatrixXd Ai_; // The internal activation function.
143 Eigen::MatrixXd Aexternal_; // The activation function set externely to modify customly the Ai
144 Eigen::MatrixXd J_; // The jacobian.
145 Eigen::VectorXd x_dot_bar_; // reference rate. --> CHECK TODO x_dot_bar
146 int taskSpace_; // The task Space.
147 bool enabled_; // The flag stating whether the task is active.
148 int dof_; // The degrees of freedom.
149};
150} // namespace tpik
151
152#endif
Definition Task.h:27
auto ID() const -> const std::string &
Definition Task.h:90
std::string ID_
Definition Task.h:141
virtual bool ConfigFromFile(libconfig::Config &confObj) noexcept(false)=0
auto InternalActivationFunction() const -> const Eigen::MatrixXd &
Definition Task.h:54
virtual void UpdateInternalActivationFunction()=0
auto TaskSpace() const -> int
Definition Task.h:79
friend std::ostream & operator<<(std::ostream &os, Task const &task)
Definition Task.h:103
virtual void Update()
auto DoF() const -> int
Definition Task.h:74
virtual ~Task()
virtual void UpdateJacobian()=0
Eigen::MatrixXd Aexternal_
Definition Task.h:143
auto ExternalActivationFunction() -> Eigen::MatrixXd &
Definition Task.h:59
Eigen::MatrixXd Ai_
Definition Task.h:142
int dof_
Definition Task.h:148
auto Jacobian() const -> const Eigen::MatrixXd &
Definition Task.h:49
auto ReferenceRate() const -> const Eigen::VectorXd &
Definition Task.h:69
auto ExternalActivationFunction() const -> const Eigen::MatrixXd &
Definition Task.h:64
auto Enabled() const -> bool
Definition Task.h:85
int taskSpace_
Definition Task.h:146
virtual void UpdateReferenceRate()=0
bool enabled_
Definition Task.h:147
Eigen::VectorXd x_dot_bar_
Definition Task.h:145
Eigen::MatrixXd J_
Definition Task.h:144
Task(const std::string ID, int taskSpace, int dof)
Definition Action.h:9