Control Libraries 6.3.4
Loading...
Searching...
No Matches
CartesianWrench.cpp
1#include "state_representation/space/cartesian/CartesianWrench.hpp"
2
3using namespace state_representation::exceptions;
4
5namespace state_representation {
7 this->set_type(StateType::CARTESIAN_WRENCH);
8}
9
10CartesianWrench::CartesianWrench(const std::string& name, const std::string& reference) :
11 CartesianState(name, reference) {
12 this->set_type(StateType::CARTESIAN_WRENCH);
13}
14
15CartesianWrench::CartesianWrench(const std::string& name, const Eigen::Vector3d& force, const std::string& reference) :
16 CartesianState(name, reference) {
17 this->set_type(StateType::CARTESIAN_WRENCH);
18 this->set_force(force);
19}
20
22 const std::string& name, const Eigen::Vector3d& force, const Eigen::Vector3d& torque, const std::string& reference
23) : CartesianState(name, reference) {
24 this->set_type(StateType::CARTESIAN_WRENCH);
25 this->set_force(force);
26 this->set_torque(torque);
27}
28
30 const std::string& name, const Eigen::Matrix<double, 6, 1>& wrench, const std::string& reference
31) : CartesianState(name, reference) {
32 this->set_type(StateType::CARTESIAN_WRENCH);
33 this->set_wrench(wrench);
34}
35
37 // set all the state variables to 0 except force and torque
38 this->set_type(StateType::CARTESIAN_WRENCH);
39 this->set_zero();
40 this->set_wrench(state.get_wrench());
41 this->set_empty(state.is_empty());
42}
43
45 CartesianWrench(static_cast<const CartesianState&>(wrench)) {}
46
47CartesianWrench CartesianWrench::Zero(const std::string& name, const std::string& reference) {
48 return CartesianState::Identity(name, reference);
49}
50
51CartesianWrench CartesianWrench::Random(const std::string& name, const std::string& reference) {
52 // separating in the two lines in needed to avoid compilation error due to ambiguous constructor call
53 Eigen::Matrix<double, 6, 1> random = Eigen::Matrix<double, 6, 1>::Random();
54 return CartesianWrench(name, random, reference);
55}
56
58 this->CartesianState::operator+=(wrench);
59 return (*this);
60}
61
63 return this->CartesianState::operator+(wrench);
64}
65
67 this->CartesianState::operator-=(wrench);
68 return (*this);
69}
70
72 return this->CartesianState::operator-(wrench);
73}
74
75CartesianWrench& CartesianWrench::operator*=(double lambda) {
76 this->CartesianState::operator*=(lambda);
77 return (*this);
78}
79
81 return this->CartesianState::operator*(lambda);
82}
83
85 this->CartesianState::operator/=(lambda);
86 return (*this);
87}
88
90 return this->CartesianState::operator/(lambda);
91}
92
93void CartesianWrench::clamp(double max_force, double max_torque, double force_noise_ratio, double torque_noise_ratio) {
94 // clamp force
95 this->clamp_state_variable(max_force, CartesianStateVariable::FORCE, force_noise_ratio);
96 // clamp torque
97 this->clamp_state_variable(max_torque, CartesianStateVariable::TORQUE, torque_noise_ratio);
98}
99
101 double max_force, double max_torque, double force_noise_ratio, double torque_noise_ratio
102) const {
103 CartesianWrench result(*this);
104 result.clamp(max_force, max_torque, force_noise_ratio, torque_noise_ratio);
105 return result;
106}
107
109 CartesianWrench result(*this);
110 return result;
111}
112
113Eigen::VectorXd CartesianWrench::data() const {
114 return this->get_wrench();
115}
116
117void CartesianWrench::set_data(const Eigen::VectorXd& data) {
118 if (data.size() != 6) {
120 "Input is of incorrect size: expected 6, given " + std::to_string(data.size()));
121 }
122 this->set_wrench(data);
123}
124
125void CartesianWrench::set_data(const std::vector<double>& data) {
126 this->set_data(Eigen::VectorXd::Map(data.data(), data.size()));
127}
128
130 return this->CartesianState::inverse();
131}
132
133std::ostream& operator<<(std::ostream& os, const CartesianWrench& wrench) {
134 if (wrench.is_empty()) {
135 os << "Empty CartesianWrench";
136 } else {
137 os << wrench.get_name() << " CartesianWrench expressed in " << wrench.get_reference_frame() << " frame"
138 << std::endl;
139 os << "force: (" << wrench.get_force()(0) << ", ";
140 os << wrench.get_force()(1) << ", ";
141 os << wrench.get_force()(2) << ")" << std::endl;
142 os << "torque: (" << wrench.get_torque()(0) << ", ";
143 os << wrench.get_torque()(1) << ", ";
144 os << wrench.get_torque()(2) << ")";
145 }
146 return os;
147}
148
150 return state.operator*(wrench);
151}
152
153CartesianWrench operator*(double lambda, const CartesianWrench& wrench) {
154 return wrench * lambda;
155}
156}// namespace state_representation
Class to represent a state in Cartesian space.
void set_zero()
Set the State to a zero value.
const Eigen::Vector3d & get_force() const
Getter of the force attribute.
CartesianState inverse() const
Compute the inverse of the current CartesianState.
const Eigen::Vector3d & get_torque() const
Getter of the torque attribute.
CartesianState operator-(const CartesianState &state) const
Overload the - operator.
void set_force(const Eigen::Vector3d &force)
Setter of the force attribute.
static CartesianState Identity(const std::string &name, const std::string &reference="world")
Constructor for the identity CartesianState (identity pose and 0 for the rest)
CartesianState & operator/=(double lambda)
Overload the /= operator with a scalar.
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)
Overload the += operator.
CartesianState & operator-=(const CartesianState &state)
Overload the -= operator.
void set_torque(const Eigen::Vector3d &torque)
Setter of the torque attribute.
CartesianState & operator*=(const CartesianState &state)
Overload the *= operator with another state by deriving the equations of motions.
CartesianState operator/(double lambda) const
Overload the / operator with a scalar.
friend CartesianState operator*(double lambda, const CartesianState &state)
Overload the * operator with a scalar.
CartesianState operator+(const CartesianState &state) const
Overload the + operator.
Class to define wrench in cartesian space as 3D force and torque vectors.
CartesianWrench & operator+=(const CartesianWrench &wrench)
Overload the += operator.
CartesianWrench & operator-=(const CartesianWrench &wrench)
Overload the -= operator.
Eigen::VectorXd data() const override
Returns the wrench data as an Eigen vector.
CartesianWrench operator/(double lambda) const
Overload the / operator with 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.
friend CartesianWrench operator*(const CartesianState &state, const CartesianWrench &wrench)
Overload the * operator with a CartesianState.
CartesianWrench clamped(double max_force, double max_torque, double force_noise_ratio=0, double torque_noise_ratio=0) const
Return the clamped wrench.
CartesianWrench operator-(const CartesianWrench &wrench) const
Overload the - operator.
CartesianWrench copy() const
Return a copy of the CartesianWrench.
CartesianWrench inverse() const
Compute the inverse of the current CartesianWrench.
CartesianWrench operator+(const CartesianWrench &wrench) const
Overload the + operator.
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)
Overload the /= operator with a scalar.
static CartesianWrench Random(const std::string &name, const std::string &reference="world")
Constructor for a random wrench.
const std::string & get_reference_frame() const
Getter of the reference frame as const reference.
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