Control Libraries 6.3.4
Loading...
Searching...
No Matches
JointTorques.cpp
1#include "state_representation/space/joint/JointTorques.hpp"
2
3using namespace state_representation::exceptions;
4
5namespace state_representation {
7 this->set_type(StateType::JOINT_TORQUES);
8}
9
10JointTorques::JointTorques(const std::string& robot_name, unsigned int nb_joints) : JointState(robot_name, nb_joints) {
11 this->set_type(StateType::JOINT_TORQUES);
12}
13
14JointTorques::JointTorques(const std::string& robot_name, const Eigen::VectorXd& torques) :
15 JointState(robot_name, torques.size()) {
16 this->set_type(StateType::JOINT_TORQUES);
17 this->set_torques(torques);
18}
19
20JointTorques::JointTorques(const std::string& robot_name, const std::vector<std::string>& joint_names) :
21 JointState(robot_name, joint_names) {
22 this->set_type(StateType::JOINT_TORQUES);
23}
24
25JointTorques::JointTorques(const std::string& robot_name, const std::vector<std::string>& joint_names,
26 const Eigen::VectorXd& torques) : JointState(robot_name, joint_names) {
27 this->set_type(StateType::JOINT_TORQUES);
28 this->set_torques(torques);
29}
30
32 // set all the state variables to 0 except torques
33 this->set_type(StateType::JOINT_TORQUES);
34 this->set_zero();
35 this->set_torques(state.get_torques());
36 this->set_empty(state.is_empty());
37}
38
39JointTorques::JointTorques(const JointTorques& torques) : JointTorques(static_cast<const JointState&>(torques)) {}
40
41JointTorques JointTorques::Zero(const std::string& robot_name, unsigned int nb_joints) {
42 return JointState::Zero(robot_name, nb_joints);
43}
44
45JointTorques JointTorques::Zero(const std::string& robot_name, const std::vector<std::string>& joint_names) {
46 return JointState::Zero(robot_name, joint_names);
47}
48
49JointTorques JointTorques::Random(const std::string& robot_name, unsigned int nb_joints) {
50 return JointTorques(robot_name, Eigen::VectorXd::Random(nb_joints));
51}
52
53JointTorques JointTorques::Random(const std::string& robot_name, const std::vector<std::string>& joint_names) {
54 return JointTorques(robot_name, joint_names, Eigen::VectorXd::Random(joint_names.size()));
55}
56
58 this->JointState::operator+=(torques);
59 return (*this);
60}
61
63 return this->JointState::operator+(torques);
64}
65
67 this->JointState::operator-=(torques);
68 return (*this);
69}
70
72 return this->JointState::operator-(torques);
73}
74
76 this->JointState::operator*=(lambda);
77 return (*this);
78}
79
81 return this->JointState::operator*(lambda);
82}
83
84JointTorques& JointTorques::operator*=(const Eigen::ArrayXd& lambda) {
85 this->multiply_state_variable(lambda, JointStateVariable::TORQUES);
86 return (*this);
87}
88
89JointTorques JointTorques::operator*(const Eigen::ArrayXd& lambda) const {
90 JointTorques result(*this);
91 result *= lambda;
92 return result;
93}
94
95JointTorques& JointTorques::operator*=(const Eigen::MatrixXd& lambda) {
96 this->multiply_state_variable(lambda, JointStateVariable::TORQUES);
97 return (*this);
98}
99
100JointTorques JointTorques::operator*(const Eigen::MatrixXd& lambda) const {
101 JointTorques result(*this);
102 result *= lambda;
103 return result;
104}
105
107 this->JointState::operator/=(lambda);
108 return (*this);
109}
110
112 return this->JointState::operator/(lambda);
113}
114
116 JointTorques result(*this);
117 return result;
118}
119
120Eigen::VectorXd JointTorques::data() const {
121 return this->get_torques();
122}
123
124void JointTorques::set_data(const Eigen::VectorXd& data) {
125 this->set_torques(data);
126}
127
128void JointTorques::set_data(const std::vector<double>& data) {
129 this->set_torques(Eigen::VectorXd::Map(data.data(), data.size()));
130}
131
132void JointTorques::clamp(double max_absolute_value, double noise_ratio) {
133 this->clamp_state_variable(max_absolute_value, JointStateVariable::TORQUES, noise_ratio);
134}
135
136JointTorques JointTorques::clamped(double max_absolute_value, double noise_ratio) const {
137 JointTorques result(*this);
138 result.clamp(max_absolute_value, noise_ratio);
139 return result;
140}
141
142void JointTorques::clamp(const Eigen::ArrayXd& max_absolute_value_array, const Eigen::ArrayXd& noise_ratio_array) {
143 this->clamp_state_variable(max_absolute_value_array, JointStateVariable::TORQUES, noise_ratio_array);
144}
145
146JointTorques JointTorques::clamped(const Eigen::ArrayXd& max_absolute_value_array,
147 const Eigen::ArrayXd& noise_ratio_array) const {
148 JointTorques result(*this);
149 result.clamp(max_absolute_value_array, noise_ratio_array);
150 return result;
151}
152
153std::ostream& operator<<(std::ostream& os, const JointTorques& torques) {
154 if (torques.is_empty()) {
155 os << "Empty JointTorques";
156 } else {
157 os << torques.get_name() << " JointTorques" << std::endl;
158 os << "names: [";
159 for (auto& n : torques.get_names()) { os << n << ", "; }
160 os << "]" << std::endl;
161 os << "torques: [";
162 for (unsigned int i = 0; i < torques.get_size(); ++i) { os << torques.get_torques()(i) << ", "; }
163 os << "]";
164 }
165 return os;
166}
167
168JointTorques operator*(double lambda, const JointTorques& torques) {
169 JointTorques result(torques);
170 result *= lambda;
171 return result;
172}
173
174JointTorques operator*(const Eigen::ArrayXd& lambda, const JointTorques& torques) {
175 JointTorques result(torques);
176 result *= lambda;
177 return result;
178}
179
180JointTorques operator*(const Eigen::MatrixXd& lambda, const JointTorques& torques) {
181 JointTorques result(torques);
182 result *= lambda;
183 return result;
184}
185}// namespace state_representation
Class to define a state in joint space.
Definition: JointState.hpp:36
const Eigen::VectorXd & get_torques() const
Getter of the torques attribute.
Definition: JointState.cpp:182
JointState operator+(const JointState &state) const
Overload the + operator.
Definition: JointState.cpp:231
JointState & operator*=(double lambda)
Overload the *= operator with a double gain.
Definition: JointState.cpp:260
void set_zero()
Set the JointState to a zero value.
Definition: JointState.cpp:43
unsigned int get_size() const
Getter of the size from the attributes.
Definition: JointState.hpp:656
JointState operator-(const JointState &state) const
Overload the - operator.
Definition: JointState.cpp:254
static JointState Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for a zero JointState.
Definition: JointState.cpp:50
JointState & operator+=(const JointState &state)
Overload the += operator.
Definition: JointState.cpp:214
void set_torques(const Eigen::VectorXd &torques)
Setter of the torques attribute.
Definition: JointState.cpp:195
JointState & operator-=(const JointState &state)
Overload the -= operator.
Definition: JointState.cpp:237
void multiply_state_variable(const Eigen::ArrayXd &lambda, const JointStateVariable &state_variable_type)
Proxy function that multiply the specified state variable by an array of gain.
Definition: JointState.cpp:268
JointState & operator/=(double lambda)
Overload the /= operator with a scalar.
Definition: JointState.cpp:319
friend JointState operator*(double lambda, const JointState &state)
Overload the * operator with a scalar.
Definition: JointState.cpp:443
const std::vector< std::string > & get_names() const
Getter of the names attribute.
Definition: JointState.hpp:660
JointState operator/(double lambda) const
Overload the / operator with a scalar.
Definition: JointState.cpp:323
Class to define torques of the joints.
void clamp(double max_absolute_value, double noise_ratio=0.)
Clamp inplace the magnitude of the torque to the values in argument.
JointTorques copy() const
Return a copy of the JointTorques.
JointTorques & operator+=(const JointTorques &torques)
Overload the += operator.
JointTorques clamped(double max_absolute_value, double noise_ratio=0.) const
Return the torque clamped to the values in argument.
JointTorques()
Empty constructor.
Definition: JointTorques.cpp:6
virtual void set_data(const Eigen::VectorXd &data) override
Set the torques data from an Eigen vector.
static JointTorques Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for the random JointTorques.
JointTorques operator+(const JointTorques &torques) const
Overload the + operator.
JointTorques & operator-=(const JointTorques &torques)
Overload the -= operator.
JointTorques operator-(const JointTorques &torques) const
Overload the - operator.
static JointTorques Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for the zero JointTorques.
JointTorques & operator/=(double lambda)
Overload the /= operator with a scalar.
JointTorques operator/(double lambda) const
Overload the / operator with a scalar.
JointTorques & operator*=(double lambda)
Overload the *= operator with a double gain.
Eigen::VectorXd data() const override
Returns the torques data as an Eigen vector.
friend JointTorques operator*(double lambda, const JointTorques &torques)
Overload the * operator with a scalar.
const std::string & get_name() const
Getter of the name as const reference.
Definition: State.cpp:48
void set_type(const StateType &type)
Override the state type.
Definition: State.cpp:89
bool is_empty() const
Getter of the empty attribute.
Definition: State.cpp:23
void set_empty(bool empty=true)
Setter of the empty attribute.
Definition: State.cpp:27
Core state variables and objects.
CartesianAcceleration operator*(const CartesianState &state, const CartesianAcceleration &acceleration)
std::ostream & operator<<(std::ostream &os, const Ellipsoid &ellipsoid)
Definition: Ellipsoid.cpp:185