Control Libraries 7.4.0
Loading...
Searching...
No Matches
CartesianPose.cpp
1#include "state_representation/space/cartesian/CartesianPose.hpp"
2#include "state_representation/exceptions/EmptyStateException.hpp"
3#include "state_representation/exceptions/IncompatibleSizeException.hpp"
4
5using namespace state_representation::exceptions;
6
7namespace state_representation {
8
10 this->set_type(StateType::CARTESIAN_POSE);
11}
12
13CartesianPose::CartesianPose(const std::string& name, const std::string& reference) : CartesianState(name, reference) {
14 this->set_type(StateType::CARTESIAN_POSE);
15}
16
17CartesianPose::CartesianPose(const std::string& name, const Eigen::Vector3d& position, const std::string& reference) :
18 CartesianState(name, reference) {
19 this->set_type(StateType::CARTESIAN_POSE);
20 this->set_position(position);
21}
22
24 const std::string& name, double x, double y, double z, const std::string& reference
25) : CartesianState(name, reference) {
26 this->set_type(StateType::CARTESIAN_POSE);
27 this->set_position(x, y, z);
28}
29
31 const std::string& name, const Eigen::Quaterniond& orientation, const std::string& reference
32) : CartesianState(name, reference) {
33 this->set_type(StateType::CARTESIAN_POSE);
34 this->set_orientation(orientation);
35}
36
38 const std::string& name, const Eigen::Vector3d& position, const Eigen::Quaterniond& orientation,
39 const std::string& reference
40) : CartesianState(name, reference) {
41 this->set_type(StateType::CARTESIAN_POSE);
42 this->set_position(position);
43 this->set_orientation(orientation);
44}
45
47 this->set_type(StateType::CARTESIAN_POSE);
48 if (state) {
49 this->set_zero();
50 this->set_pose(state.get_pose());
51 }
52}
53
54CartesianPose::CartesianPose(const CartesianPose& pose) : CartesianPose(static_cast<const CartesianState&>(pose)) {}
55
56CartesianPose::CartesianPose(const CartesianTwist& twist) : CartesianPose(std::chrono::seconds(1) * twist) {}
57
58CartesianPose CartesianPose::Identity(const std::string& name, const std::string& reference) {
59 return CartesianState::Identity(name, reference);
60}
61
62CartesianPose CartesianPose::Random(const std::string& name, const std::string& reference) {
63 return CartesianPose(name, Eigen::Vector3d::Random(), Eigen::Quaterniond::UnitRandom(), reference);
64}
65
66Eigen::VectorXd CartesianPose::data() const {
67 return this->get_pose();
68}
69
70void CartesianPose::set_data(const Eigen::VectorXd& data) {
71 if (data.size() != 7) {
73 "Input is of incorrect size: expected 7, given " + std::to_string(data.size()));
74 }
75 this->set_pose(data);
76}
77
78void CartesianPose::set_data(const std::vector<double>& data) {
79 this->set_data(Eigen::VectorXd::Map(data.data(), data.size()));
80}
81
83 CartesianPose result(*this);
84 return result;
85}
86
90
91CartesianPose CartesianPose::normalized(const CartesianStateVariable& state_variable_type) const {
92 return CartesianState::normalized(state_variable_type);
93}
94
95std::vector<double> CartesianPose::norms(const CartesianStateVariable& state_variable_type) const {
96 return CartesianState::norms(state_variable_type);
97}
98
99CartesianPose& CartesianPose::operator*=(const CartesianState& state) {
100 this->CartesianState::operator*=(state);
101 return (*this);
102}
103
104CartesianPose& CartesianPose::operator*=(const CartesianPose& pose) {
105 this->CartesianState::operator*=(pose);
106 return (*this);
107}
108
110 return this->CartesianState::operator*(state);
111}
112
114 return this->CartesianState::operator*(pose);
115}
116
118 return this->CartesianState::operator*(twist);
119}
120
122 return this->CartesianState::operator*(acceleration);
123}
124
126 return this->CartesianState::operator*(wrench);
127}
128
129CartesianPose& CartesianPose::operator*=(double lambda) {
130 this->CartesianState::operator*=(lambda);
131 return (*this);
132}
133
135 return this->CartesianState::operator*(lambda);
136}
137
138CartesianPose operator*(double lambda, const CartesianPose& pose) {
139 return pose * lambda;
140}
141
143 this->CartesianState::operator/=(lambda);
144 return (*this);
145}
146
148 return this->CartesianState::operator/(lambda);
149}
150
151CartesianTwist CartesianPose::operator/(const std::chrono::nanoseconds& dt) const {
152 // operations
153 CartesianTwist twist(this->get_name(), this->get_reference_frame());
154 // convert the period to a double with the second as reference
155 double period = dt.count();
156 period /= 1e9;
157 // set linear velocity
158 twist.set_linear_velocity(this->get_position() / period);
159 // set angular velocity from the log of the quaternion error
160 Eigen::Quaterniond log_q = math_tools::log(this->get_orientation());
161 twist.set_angular_velocity(2 * log_q.vec() / period);
162 return twist;
163}
164
165CartesianPose& CartesianPose::operator+=(const CartesianPose& pose) {
166 this->CartesianState::operator+=(pose);
167 return (*this);
168}
169
170CartesianPose& CartesianPose::operator+=(const CartesianState& state) {
171 this->CartesianState::operator+=(state);
172 return (*this);
173}
174
175CartesianPose CartesianPose::operator+(const CartesianPose& pose) const {
176 return this->CartesianState::operator+(pose);
177}
178
179CartesianState CartesianPose::operator+(const CartesianState& state) const {
180 return this->CartesianState::operator+(state);
181}
182
186
187CartesianPose& CartesianPose::operator-=(const CartesianPose& pose) {
188 this->CartesianState::operator-=(pose);
189 return (*this);
190}
191
192CartesianPose& CartesianPose::operator-=(const CartesianState& state) {
193 this->CartesianState::operator-=(state);
194 return (*this);
195}
196
198 return this->CartesianState::operator-(pose);
199}
200
202 return this->CartesianState::operator-(state);
203}
204
205std::ostream& operator<<(std::ostream& os, const CartesianPose& pose) {
206 os << pose.to_string();
207 return os;
208}
209
210}// namespace state_representation
Class to define acceleration in Cartesian space as 3D linear and angular acceleration vectors.
Class to define Cartesian pose in Cartesian space as 3D position and quaternion based orientation.
void set_data(const Eigen::VectorXd &data) override
Set the pose data from an Eigen vector.
CartesianPose operator-() const
Negate a Cartesian pose.
std::vector< double > norms(const CartesianStateVariable &state_variable_type=CartesianStateVariable::POSE) const override
Compute the norms of the state variable specified by the input type (default is full pose)
CartesianPose & operator/=(double lambda)
Scale inplace by a scalar.
static CartesianPose Identity(const std::string &name, const std::string &reference="world")
Constructor for the identity pose.
Eigen::VectorXd data() const override
Returns the pose data as an Eigen vector.
CartesianPose normalized(const CartesianStateVariable &state_variable_type=CartesianStateVariable::POSE) const
Compute the normalized pose at the state variable given in argument (default is full pose)
CartesianPose operator/(double lambda) const
Scale a Cartesian pose by a scalar.
CartesianPose copy() const
Return a copy of the Cartesian pose.
friend CartesianPose operator*(double lambda, const CartesianPose &pose)
Scale a Cartesian pose by a scalar.
CartesianPose inverse() const
Compute the inverse of the current Cartesian pose.
static CartesianPose Random(const std::string &name, const std::string &reference="world")
Constructor for a random pose.
Class to represent a state in Cartesian space.
void set_zero()
Set the State to a zero value.
CartesianState inverse() const
Compute the inverse of the current Cartesian state.
void set_orientation(const Eigen::Quaterniond &orientation)
Setter of the orientation.
const Eigen::Vector3d & get_position() const
Getter of the position attribute.
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.
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.
Eigen::Matrix< double, 7, 1 > get_pose() const
Getter of the pose from position and orientation attributes.
void set_position(const Eigen::Vector3d &position)
Setter of the position.
std::string to_string() const override
Convert the state to its string representation.
const Eigen::Quaterniond & get_orientation() const
Getter of the orientation attribute.
CartesianState & operator+=(const CartesianState &state)
Add inplace another Cartesian state.
CartesianState operator-() const
Negate a Cartesian state.
void set_pose(const Eigen::Vector3d &position, const Eigen::Quaterniond &orientation)
Setter of the pose from both position and orientation.
CartesianState & operator-=(const CartesianState &state)
Compute inplace the difference with another Cartesian state.
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.
void set_linear_velocity(const Eigen::Vector3d &linear_velocity)
Setter of the linear velocity attribute.
void set_angular_velocity(const Eigen::Vector3d &angular_velocity)
Setter of the angular velocity attribute.
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 twist in Cartesian space as 3D linear and angular velocity vectors.
Class to define wrench in Cartesian space as 3D force and torque vectors.
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 attribute.
Definition State.cpp:29
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)