Control Libraries 7.4.0
Loading...
Searching...
No Matches
JointTorques.cpp
1#include "state_representation/space/joint/JointTorques.hpp"
2
3namespace state_representation {
4
5using namespace exceptions;
6
8 this->set_type(StateType::JOINT_TORQUES);
9}
10
11JointTorques::JointTorques(const std::string& robot_name, unsigned int nb_joints) : JointState(robot_name, nb_joints) {
12 this->set_type(StateType::JOINT_TORQUES);
13}
14
15JointTorques::JointTorques(const std::string& robot_name, const Eigen::VectorXd& torques) :
16 JointState(robot_name, torques.size()) {
17 this->set_type(StateType::JOINT_TORQUES);
18 this->set_torques(torques);
19}
20
21JointTorques::JointTorques(const std::string& robot_name, const std::vector<std::string>& joint_names) :
22 JointState(robot_name, joint_names) {
23 this->set_type(StateType::JOINT_TORQUES);
24}
25
26JointTorques::JointTorques(const std::string& robot_name, const std::vector<std::string>& joint_names,
27 const Eigen::VectorXd& torques) : JointState(robot_name, joint_names) {
28 this->set_type(StateType::JOINT_TORQUES);
29 this->set_torques(torques);
30}
31
33 this->set_type(StateType::JOINT_TORQUES);
34 if (state) {
35 this->set_zero();
36 this->set_torques(state.get_torques());
37 }
38}
39
40JointTorques::JointTorques(const JointTorques& torques) : JointTorques(static_cast<const JointState&>(torques)) {}
41
42JointTorques JointTorques::Zero(const std::string& robot_name, unsigned int nb_joints) {
43 return JointState::Zero(robot_name, nb_joints);
44}
45
46JointTorques JointTorques::Zero(const std::string& robot_name, const std::vector<std::string>& joint_names) {
47 return JointState::Zero(robot_name, joint_names);
48}
49
50JointTorques JointTorques::Random(const std::string& robot_name, unsigned int nb_joints) {
51 return JointTorques(robot_name, Eigen::VectorXd::Random(nb_joints));
52}
53
54JointTorques JointTorques::Random(const std::string& robot_name, const std::vector<std::string>& joint_names) {
55 return JointTorques(robot_name, joint_names, Eigen::VectorXd::Random(joint_names.size()));
56}
57
58Eigen::VectorXd JointTorques::data() const {
59 return this->get_torques();
60}
61
62void JointTorques::set_data(const Eigen::VectorXd& data) {
63 this->set_torques(data);
64}
65
66void JointTorques::set_data(const std::vector<double>& data) {
67 this->set_torques(Eigen::VectorXd::Map(data.data(), data.size()));
68}
69
70void JointTorques::clamp(double max_absolute_value, double noise_ratio) {
71 this->clamp_state_variable(max_absolute_value, JointStateVariable::TORQUES, noise_ratio);
72}
73
74void JointTorques::clamp(const Eigen::ArrayXd& max_absolute_value_array, const Eigen::ArrayXd& noise_ratio_array) {
75 this->clamp_state_variable(max_absolute_value_array, JointStateVariable::TORQUES, noise_ratio_array);
76}
77
78JointTorques JointTorques::clamped(double max_absolute_value, double noise_ratio) const {
79 JointTorques result(*this);
80 result.clamp(max_absolute_value, noise_ratio);
81 return result;
82}
83
84JointTorques JointTorques::clamped(const Eigen::ArrayXd& max_absolute_value_array,
85 const Eigen::ArrayXd& noise_ratio_array) const {
86 JointTorques result(*this);
87 result.clamp(max_absolute_value_array, noise_ratio_array);
88 return result;
89}
90
92 JointTorques result(*this);
93 return result;
94}
95
97 this->JointState::operator*=(lambda);
98 return (*this);
99}
100
102 return this->JointState::operator*(lambda);
103}
104
105JointTorques operator*(double lambda, const JointTorques& torques) {
106 JointTorques result(torques);
107 result *= lambda;
108 return result;
109}
110
111JointTorques operator*(const Eigen::MatrixXd& lambda, const JointTorques& torques) {
112 JointTorques result(torques);
113 result.multiply_state_variable(lambda, JointStateVariable::TORQUES);
114 return result;
115}
116
118 this->JointState::operator/=(lambda);
119 return (*this);
120}
121
123 return this->JointState::operator/(lambda);
124}
125
126JointTorques& JointTorques::operator+=(const JointTorques& torques) {
127 this->JointState::operator+=(torques);
128 return (*this);
129}
130
131JointTorques& JointTorques::operator+=(const JointState& state) {
132 this->JointState::operator+=(state);
133 return (*this);
134}
135
136JointTorques JointTorques::operator+(const JointTorques& torques) const {
137 return this->JointState::operator+(torques);
138}
139
140JointState JointTorques::operator+(const JointState& state) const {
141 return this->JointState::operator+(state);
142}
143
147
148JointTorques& JointTorques::operator-=(const JointTorques& torques) {
149 this->JointState::operator-=(torques);
150 return (*this);
151}
152
153JointTorques& JointTorques::operator-=(const JointState& state) {
154 this->JointState::operator-=(state);
155 return (*this);
156}
157
159 return this->JointState::operator-(torques);
160}
161
163 return this->JointState::operator-(state);
164}
165
166std::ostream& operator<<(std::ostream& os, const JointTorques& torques) {
167 os << torques.to_string();
168 return os;
169}
170}// namespace state_representation
Class to define a state in joint space.
const Eigen::VectorXd & get_torques() const
Getter of the torques attribute.
JointState operator+(const JointState &state) const
Add another joint sate.
void multiply_state_variable(const Eigen::MatrixXd &lambda, const JointStateVariable &state_variable_type)
Proxy function that scale the specified state variable by a matrix.
JointState & operator*=(double lambda)
Scale inplace by a scalar.
void set_zero()
Set the joint state to a zero value.
static JointState Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for a zero joint state.
JointState & operator+=(const JointState &state)
Add inplace another joint state.
void set_torques(const Eigen::VectorXd &torques)
Setter of the torques attribute.
std::string to_string() const override
Convert the state to its string representation.
JointState & operator-=(const JointState &state)
Compute inplace the difference with another joint state.
JointState & operator/=(double lambda)
Scale inplace by a scalar.
JointState operator-() const
Negate a joint state.
friend JointState operator*(double lambda, const JointState &state)
Scale a joint state by a scalar.
JointState operator/(double lambda) const
Scale a joint state by a scalar.
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 joint torques.
JointTorques clamped(double max_absolute_value, double noise_ratio=0.) const
Return the torque clamped to the values in argument.
virtual void set_data(const Eigen::VectorXd &data) override
Set the torques data from an Eigen vector.
JointTorques operator-() const
Negate joint torques.
static JointTorques Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for random joint torques.
static JointTorques Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for zero joint torques.
JointTorques & operator/=(double lambda)
Scale inplace by a scalar.
JointTorques operator/(double lambda) const
Scale joint torques by a scalar.
JointTorques & operator*=(double lambda)
Scale inplace by a scalar.
Eigen::VectorXd data() const override
Returns the torques data as an Eigen vector.
friend JointTorques operator*(double lambda, const JointTorques &torques)
Scale joint torques by a scalar.
void set_type(const StateType &type)
Setter of the state type attribute.
Definition State.cpp:41
Core state variables and objects.
std::ostream & operator<<(std::ostream &os, const AnalogIOState &state)
CartesianAcceleration operator*(double lambda, const CartesianAcceleration &acceleration)