Control Libraries 7.4.0
Loading...
Searching...
No Matches
CartesianWrench.cpp
1#include "state_representation/space/cartesian/CartesianWrench.hpp"
2#include "state_representation/exceptions/EmptyStateException.hpp"
3
4namespace state_representation {
5
6using namespace exceptions;
7
9 this->set_type(StateType::CARTESIAN_WRENCH);
10}
11
12CartesianWrench::CartesianWrench(const std::string& name, const std::string& reference) :
13 CartesianState(name, reference) {
14 this->set_type(StateType::CARTESIAN_WRENCH);
15}
16
17CartesianWrench::CartesianWrench(const std::string& name, const Eigen::Vector3d& force, const std::string& reference) :
18 CartesianState(name, reference) {
19 this->set_type(StateType::CARTESIAN_WRENCH);
20 this->set_force(force);
21}
22
24 const std::string& name, const Eigen::Vector3d& force, const Eigen::Vector3d& torque, const std::string& reference
25) : CartesianState(name, reference) {
26 this->set_type(StateType::CARTESIAN_WRENCH);
27 this->set_force(force);
28 this->set_torque(torque);
29}
30
32 const std::string& name, const Eigen::Matrix<double, 6, 1>& wrench, const std::string& reference
33) : CartesianState(name, reference) {
34 this->set_type(StateType::CARTESIAN_WRENCH);
35 this->set_wrench(wrench);
36}
37
39 this->set_type(StateType::CARTESIAN_WRENCH);
40 if (state) {
41 this->set_zero();
42 this->set_wrench(state.get_wrench());
43 }
44}
45
47 CartesianWrench(static_cast<const CartesianState&>(wrench)) {}
48
49CartesianWrench CartesianWrench::Zero(const std::string& name, const std::string& reference) {
50 return CartesianState::Identity(name, reference);
51}
52
53CartesianWrench CartesianWrench::Random(const std::string& name, const std::string& reference) {
54 // separating in the two lines in needed to avoid compilation error due to ambiguous constructor call
55 Eigen::Matrix<double, 6, 1> random = Eigen::Matrix<double, 6, 1>::Random();
56 return CartesianWrench(name, random, reference);
57}
58
59Eigen::VectorXd CartesianWrench::data() const {
60 return this->get_wrench();
61}
62
63void CartesianWrench::set_data(const Eigen::VectorXd& data) {
64 if (data.size() != 6) {
66 "Input is of incorrect size: expected 6, given " + std::to_string(data.size()));
67 }
68 this->set_wrench(data);
69}
70
71void CartesianWrench::set_data(const std::vector<double>& data) {
72 this->set_data(Eigen::VectorXd::Map(data.data(), data.size()));
73}
74
75void CartesianWrench::clamp(double max_force, double max_torque, double force_noise_ratio, double torque_noise_ratio) {
76 // clamp force
77 this->clamp_state_variable(max_force, CartesianStateVariable::FORCE, force_noise_ratio);
78 // clamp torque
79 this->clamp_state_variable(max_torque, CartesianStateVariable::TORQUE, torque_noise_ratio);
80}
81
83 double max_force, double max_torque, double force_noise_ratio, double torque_noise_ratio
84) const {
85 CartesianWrench result(*this);
86 result.clamp(max_force, max_torque, force_noise_ratio, torque_noise_ratio);
87 return result;
88}
89
91 CartesianWrench result(*this);
92 return result;
93}
94
95CartesianWrench CartesianWrench::normalized(const CartesianStateVariable& state_variable_type) const {
96 return CartesianState::normalized(state_variable_type);
97}
98
99std::vector<double> CartesianWrench::norms(const CartesianStateVariable& state_variable_type) const {
100 return CartesianState::norms(state_variable_type);
101}
102
103CartesianWrench& CartesianWrench::operator*=(double lambda) {
104 this->CartesianState::operator*=(lambda);
105 return (*this);
106}
107
108CartesianWrench operator*(double lambda, const CartesianWrench& wrench) {
109 return wrench * lambda;
110}
111
113 return this->CartesianState::operator*(lambda);
114}
115
116CartesianWrench operator*(const Eigen::Matrix<double, 6, 6>& lambda, const CartesianWrench& wrench) {
117 CartesianWrench result(wrench);
118 result.set_wrench(lambda * result.get_wrench());
119 return result;
120}
121
123 this->CartesianState::operator/=(lambda);
124 return (*this);
125}
126
128 return this->CartesianState::operator/(lambda);
129}
130
131CartesianWrench& CartesianWrench::operator+=(const CartesianWrench& wrench) {
132 this->CartesianState::operator+=(wrench);
133 return (*this);
134}
135
136CartesianWrench& CartesianWrench::operator+=(const CartesianState& state) {
137 this->CartesianState::operator+=(state);
138 return (*this);
139}
140
141CartesianWrench CartesianWrench::operator+(const CartesianWrench& wrench) const {
142 return this->CartesianState::operator+(wrench);
143}
144
145CartesianState CartesianWrench::operator+(const CartesianState& state) const {
146 return this->CartesianState::operator+(state);
147}
148
152
153CartesianWrench& CartesianWrench::operator-=(const CartesianWrench& wrench) {
154 this->CartesianState::operator-=(wrench);
155 return (*this);
156}
157
158CartesianWrench& CartesianWrench::operator-=(const CartesianState& state) {
159 this->CartesianState::operator-=(state);
160 return (*this);
161}
162
164 return this->CartesianState::operator-(wrench);
165}
166
168 return this->CartesianState::operator-(state);
169}
170
171std::ostream& operator<<(std::ostream& os, const CartesianWrench& wrench) {
172 os << wrench.to_string();
173 return os;
174}
175
176}// namespace state_representation
Class to represent a state in Cartesian space.
void set_zero()
Set the State to a zero value.
virtual std::vector< double > norms(const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL) const
Compute the norms of the state variable specified by the input type. Default is full state.
void set_force(const Eigen::Vector3d &force)
Setter of the force attribute.
CartesianState normalized(const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL) const
Compute the normalized state at the state variable given in argument. Default is full state.
static CartesianState Identity(const std::string &name, const std::string &reference="world")
Constructor for the identity Cartesian state (identity pose and 0 for the rest)
CartesianState & operator/=(double lambda)
Scale inplace by a scalar.
std::string to_string() const override
Convert the state to its string representation.
void set_wrench(const Eigen::Matrix< double, 6, 1 > &wrench)
Setter of the force and torque from a 6d wrench vector.
Eigen::Matrix< double, 6, 1 > get_wrench() const
Getter of the 6d wrench from force and torque attributes.
CartesianState & operator+=(const CartesianState &state)
Add inplace another Cartesian state.
CartesianState operator-() const
Negate a Cartesian state.
CartesianState & operator-=(const CartesianState &state)
Compute inplace the difference with another Cartesian state.
void set_torque(const Eigen::Vector3d &torque)
Setter of the torque attribute.
CartesianState & operator*=(const CartesianState &state)
Transform inplace a Cartesian state into the current reference frame.
CartesianState operator/(double lambda) const
Scale a Cartesian state by a scalar.
friend CartesianState operator*(double lambda, const CartesianState &state)
Scale a Cartesian state by a scalar.
CartesianState operator+(const CartesianState &state) const
Add another Cartesian state.
Class to define wrench in Cartesian space as 3D force and torque vectors.
Eigen::VectorXd data() const override
Returns the wrench data as an Eigen vector.
friend CartesianWrench operator*(double lambda, const CartesianWrench &wrench)
Scale a Cartesian wrench by a scalar.
CartesianWrench normalized(const CartesianStateVariable &state_variable_type=CartesianStateVariable::WRENCH) const
Compute the normalized wrench at the state variable given in argument (default is full wrench)
CartesianWrench operator/(double lambda) const
Scale a Cartesian wrench by a scalar.
static CartesianWrench Zero(const std::string &name, const std::string &reference="world")
Constructor for the zero wrench.
void set_data(const Eigen::VectorXd &data) override
Set the wrench data from an Eigen vector.
CartesianWrench clamped(double max_force, double max_torque, double force_noise_ratio=0, double torque_noise_ratio=0) const
Return the clamped wrench.
std::vector< double > norms(const CartesianStateVariable &state_variable_type=CartesianStateVariable::WRENCH) const override
Compute the norms of the state variable specified by the input type (default is full wrench)
CartesianWrench copy() const
Return a copy of the Cartesian wrench.
CartesianWrench operator-() const
Negate a Cartesian wrench.
void clamp(double max_force, double max_torque, double force_noise_ratio=0, double torque_noise_ratio=0)
Clamp inplace the magnitude of the wrench to the values in argument.
CartesianWrench & operator/=(double lambda)
Scale inplace by a scalar.
static CartesianWrench Random(const std::string &name, const std::string &reference="world")
Constructor for a random wrench.
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)