TPIK  1.0
Task Priority Inverse Kinematics
Loading...
Searching...
No Matches
PriorityLevel.h
Go to the documentation of this file.
1#ifndef __PRIORITYLEVEL_H__
2#define __PRIORITYLEVEL_H__
3
4#include "Task.h"
5#include <eigen3/Eigen/Dense>
6#include <iostream>
7#include <rml/RML.h>
8#include <vector>
9
10namespace tpik {
11/*
12 * @brief PriorityLevel class.
13 * @details Implementation of the PriorityLevel Class. Starting form a vector of tpik::Task which have the same priority
14 * it computes the Jacobian, internal activation function and reference by juxtaposing the related task matrices.
15 * Methods to set the external Activation Function are provided. It is assumed that all the Tasks have the same behavior
16 * wrt the external activation function (hence either they are all present or none of them are present in an action).
17 * The overall activation function is computed as product between the internal and external activation functions.
18 */
20public:
21 /*
22 * @brief Constructor of PriorityLevel Class.
23 * @param[in] ID Priority Level ID.
24 */
25 PriorityLevel(const std::string ID);
26 /*
27 * @brief Default De-constructor of PriorityLevel Class.
28 */
30 /*
31 * @brief Method which adds a tpik::Task to the PriorityLevel.
32 * @param[in] task std::shared_ptr to the tpik::Task to be added.
33 */
34 void AddTask(const std::shared_ptr<Task> task);
35 /*
36 * @brief Method getting the PriorityLevel ID.
37 * @return PriorityLevel ID.
38 */
39 auto ID() const -> const std::string& { return ID_; }
40 /*
41 * @brief Method which updates the PriorityLevel Jacobian, Internal ActivationFunction and Reference.
42 */
43 void Update();
44 /*
45 * @brief Methods setting the PriorityLevel regularization data.
46 */
47 auto RegularizationData() -> rml::RegularizationData& { return regularizationData_; }
48 /*
49 * @brief Methods getting the PriorityLevel regularization data.
50 */
51 auto RegularizationData() const -> const rml::RegularizationData& { return regularizationData_; }
52 /*
53 * @brief Method Returning the PriorityLevel Jacobian.
54 * @return PriorityLevel Jacobian.
55 */
56 auto Jacobian() const -> const Eigen::MatrixXd& { return J_; }
57 /*
58 * @brief Method Returning the PriorityLevel Activation Function computed as follows : AactionT*Aexternal*Ai.
59 * @return Activation Function.
60 */
61 auto ActivationFunction() const -> const Eigen::MatrixXd& { return A_; }
62 /*
63 * @brief Method returning the PriorityLevel Internal Activation Function.
64 * @return Internal Activation Function.
65 */
66 auto InternalActivationFunction() const -> const Eigen::MatrixXd& { return Ai_; }
67 /*
68 * @brief Method setting the PriorityLevel action transition Activation Function.
69 * @return Action transition Activation Function.
70 */
71 auto ActionTransitionActivation(double x) -> void { actionTransitionA_ = x; }
72 /*
73 * @brief Method returning the PriorityLevel Reference.
74 * @return PriorityLevel Reference.
75 */
76 auto ReferenceRate() const -> const Eigen::VectorXd& { return x_dot_; }
77 /*
78 * @brief Method returning the PriorityLevel Tasks as vector of shared_ptr to tpik::Task.
79 * @return Vector of shared_ptr of tpik::Task.
80 */
81 auto Level() const -> const std::vector<std::shared_ptr<Task>>& { return level_; }
82 /*
83 * @brief Methods setting the last delta increment computed for the priority level.
84 */
85 auto DeltaY() -> Eigen::VectorXd& { return deltaY_; }
86 /*
87 * @brief Methods getting the last delta increment computed for the priority level.
88 */
89 auto DeltaY() const -> const Eigen::VectorXd& { return deltaY_; }
90 /*
91 * @brief Function overloading the cout operator
92 */
93 friend std::ostream& operator<<(std::ostream& os, PriorityLevel const& priorityLevel)
94 {
95 return os << "\033[1;37m"
96 << "PriorityLevel ID " << priorityLevel.ID_ << "\n"
97 << std::setprecision(4) << "\033[1;37m"
98 << "Internal Activation Function \n"
99 << "\033[0m" << priorityLevel.Ai_ << "\n"
100 << "\033[1;37m"
101 << "External Activation Function "
102 << "\033[0m" << priorityLevel.actionTransitionA_ << "\n"
103 << "\033[1;37m"
104 << "Jacobian \n"
105 << "\033[0m" << priorityLevel.J_ << "\n"
106 << "\033[1;37m"
107 << "Reference \n"
108 << "\033[0m" << priorityLevel.x_dot_ << "\n"
109 << "\033[1;37m"
110 << "svdParameters\nThrehsold "
111 << "\033[0m" << priorityLevel.regularizationData_.params.threshold
112 << "\n"
113 << "\033[1;37m"
114 << "lambda "
115 << "\033[0m" << priorityLevel.regularizationData_.params.lambda
116 << "\n";
117 }
118
119private:
120 /*
121 * @brief Method which juxtaposes the Task Jacobians to obtain the priority level Jacobian.
122 */
123 void UpdateJacobian();
124 /*
125 * @brief Method which juxtaposes the Task Internal Activation Functions to
126 * obtain the priority level Internal Activation Function.
127 */
128 void UpdateActivationFunction();
129 /*
130 * @brief Method which juxtaposes the Task References to obtain the priority
131 * level References.
132 */
133 void UpdateReferenceRate();
134
135 std::vector<std::shared_ptr<Task>> level_; // The vector containing the std::shared_ptr to tpik::Task.
136 std::string ID_; // The PriorityLevel ID.
137 Eigen::MatrixXd Ai_; // The internal activation function.
138 Eigen::MatrixXd Aextern_; // The activation function set by externely to modify customly
139 Eigen::MatrixXd A_; // Total activation function
140 Eigen::MatrixXd J_; // The jacobian.
141 Eigen::VectorXd x_dot_; // The reference.
142 double actionTransitionA_; // The action transition activation function.
143 rml::RegularizationData regularizationData_; // The rml::RegularizationData struct, used to compute the regularized pseudoinverse.
144 Eigen::VectorXd deltaY_; // The last delta y comptued for the priority level.
145 int priorityLevelSpace_; // The priority level space
146};
147} // namespace tpik
148
149#endif
Definition PriorityLevel.h:19
auto RegularizationData() -> rml::RegularizationData &
Definition PriorityLevel.h:47
friend std::ostream & operator<<(std::ostream &os, PriorityLevel const &priorityLevel)
Definition PriorityLevel.h:93
auto RegularizationData() const -> const rml::RegularizationData &
Definition PriorityLevel.h:51
auto Jacobian() const -> const Eigen::MatrixXd &
Definition PriorityLevel.h:56
void AddTask(const std::shared_ptr< Task > task)
auto DeltaY() const -> const Eigen::VectorXd &
Definition PriorityLevel.h:89
PriorityLevel(const std::string ID)
auto InternalActivationFunction() const -> const Eigen::MatrixXd &
Definition PriorityLevel.h:66
auto ReferenceRate() const -> const Eigen::VectorXd &
Definition PriorityLevel.h:76
auto DeltaY() -> Eigen::VectorXd &
Definition PriorityLevel.h:85
auto ActivationFunction() const -> const Eigen::MatrixXd &
Definition PriorityLevel.h:61
auto Level() const -> const std::vector< std::shared_ptr< Task > > &
Definition PriorityLevel.h:81
auto ID() const -> const std::string &
Definition PriorityLevel.h:39
auto ActionTransitionActivation(double x) -> void
Definition PriorityLevel.h:71
Definition Task.h:27
Definition Action.h:9