Control Libraries 7.4.0
Loading...
Searching...
No Matches
CartesianState.hpp
1#pragma once
2
3#include "state_representation/space/SpatialState.hpp"
4#include "state_representation/exceptions/IncompatibleSizeException.hpp"
5
6namespace state_representation {
7
8class CartesianState;
9
15enum class CartesianStateVariable {
16 POSITION,
17 ORIENTATION,
18 POSE,
19 LINEAR_VELOCITY,
20 ANGULAR_VELOCITY,
21 TWIST,
22 LINEAR_ACCELERATION,
23 ANGULAR_ACCELERATION,
24 ACCELERATION,
25 FORCE,
26 TORQUE,
27 WRENCH,
28 ALL
29};
30
39double dist(
40 const CartesianState& s1, const CartesianState& s2,
41 const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL
42);
43
49public:
54
58 explicit CartesianState(const std::string& name, const std::string& reference = "world");
59
63 CartesianState(const CartesianState& state);
64
68 static CartesianState Identity(const std::string& name, const std::string& reference = "world");
69
73 static CartesianState Random(const std::string& name, const std::string& reference = "world");
74
80 friend void swap(CartesianState& state1, CartesianState& state2);
81
88
92 const Eigen::Vector3d& get_position() const;
93
97 const Eigen::Quaterniond& get_orientation() const;
98
103 Eigen::Vector4d get_orientation_coefficients() const;
104
110 Eigen::Matrix<double, 7, 1> get_pose() const;
111
116 Eigen::Matrix4d get_transformation_matrix() const;
117
121 const Eigen::Vector3d& get_linear_velocity() const;
122
126 const Eigen::Vector3d& get_angular_velocity() const;
127
131 Eigen::Matrix<double, 6, 1> get_twist() const;
132
136 const Eigen::Vector3d& get_linear_acceleration() const;
137
141 const Eigen::Vector3d& get_angular_acceleration() const;
142
146 Eigen::Matrix<double, 6, 1> get_acceleration() const;
147
151 const Eigen::Vector3d& get_force() const;
152
156 const Eigen::Vector3d& get_torque() const;
157
161 Eigen::Matrix<double, 6, 1> get_wrench() const;
162
166 virtual Eigen::VectorXd data() const;
167
171 Eigen::ArrayXd array() const;
172
176 std::vector<double> to_std_vector() const;
177
181 void set_position(const Eigen::Vector3d& position);
182
186 void set_position(const std::vector<double>& position);
187
191 void set_position(const double& x, const double& y, const double& z);
192
196 void set_orientation(const Eigen::Quaterniond& orientation);
197
203 void set_orientation(const Eigen::Vector4d& orientation);
204
210 void set_orientation(const std::vector<double>& orientation);
211
215 void set_orientation(const double& w, const double& x, const double& y, const double& z);
216
220 void set_pose(const Eigen::Vector3d& position, const Eigen::Quaterniond& orientation);
221
227 void set_pose(const Eigen::Matrix<double, 7, 1>& pose);
228
234 void set_pose(const std::vector<double>& pose);
235
239 void set_linear_velocity(const Eigen::Vector3d& linear_velocity);
240
244 void set_linear_velocity(const std::vector<double>& linear_velocity);
245
249 void set_linear_velocity(const double& x, const double& y, const double& z);
250
254 void set_angular_velocity(const Eigen::Vector3d& angular_velocity);
255
259 void set_angular_velocity(const std::vector<double>& angular_velocity);
260
264 void set_angular_velocity(const double& x, const double& y, const double& z);
265
269 void set_twist(const Eigen::Matrix<double, 6, 1>& twist);
270
274 void set_twist(const std::vector<double>& twist);
275
279 void set_linear_acceleration(const Eigen::Vector3d& linear_acceleration);
280
284 void set_linear_acceleration(const std::vector<double>& linear_acceleration);
285
289 void set_linear_acceleration(const double& x, const double& y, const double& z);
290
294 void set_angular_acceleration(const Eigen::Vector3d& angular_acceleration);
295
299 void set_angular_acceleration(const std::vector<double>& angular_acceleration);
300
304 void set_angular_acceleration(const double& x, const double& y, const double& z);
305
309 void set_acceleration(const Eigen::Matrix<double, 6, 1>& acceleration);
310
314 void set_acceleration(const std::vector<double>& acceleration);
315
319 void set_force(const Eigen::Vector3d& force);
320
324 void set_force(const std::vector<double>& force);
325
329 void set_force(const double& x, const double& y, const double& z);
330
334 void set_torque(const Eigen::Vector3d& torque);
335
339 void set_torque(const std::vector<double>& torque);
340
344 void set_torque(const double& x, const double& y, const double& z);
345
349 void set_wrench(const Eigen::Matrix<double, 6, 1>& wrench);
350
354 void set_wrench(const std::vector<double>& wrench);
355
359 virtual void set_data(const Eigen::VectorXd& data) override;
360
364 virtual void set_data(const std::vector<double>& data) override;
365
369 void set_zero();
370
378 void clamp_state_variable(double max_norm, const CartesianStateVariable& state_variable_type, double noise_ratio = 0);
379
383 CartesianState copy() const;
384
392 double dist(
393 const CartesianState& state, const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL
394 ) const;
395
404 friend double dist(
405 const CartesianState& s1, const CartesianState& s2, const CartesianStateVariable& state_variable_type
406 );
407
411 void reset() override;
412
422 CartesianState inverse() const;
423
428 void normalize(const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL);
429
435 CartesianState normalized(const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL) const;
436
442 virtual std::vector<double>
443 norms(const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL) const;
444
453
461 CartesianState operator*(const CartesianState& state) const;
462
469 CartesianState& operator*=(double lambda);
470
477 CartesianState operator*(double lambda) const;
478
486 friend CartesianState operator*(double lambda, const CartesianState& state);
487
493 Eigen::Vector3d operator*(const Eigen::Vector3d& vector) const;
494
501 CartesianState& operator/=(double lambda);
502
509 CartesianState operator/(double lambda) const;
510
517
523 CartesianState operator+(const CartesianState& state) const;
524
530
537
543 CartesianState operator-(const CartesianState& state) const;
544
551 friend std::ostream& operator<<(std::ostream& os, const CartesianState& state);
552
553protected:
558 Eigen::VectorXd get_state_variable(const CartesianStateVariable& state_variable_type) const;
559
565 void set_state_variable(const Eigen::VectorXd& new_value, const CartesianStateVariable& state_variable_type);
566
572 void set_state_variable(const std::vector<double>& new_value, const CartesianStateVariable& state_variable_type);
573
577 std::string to_string() const override;
578
579private:
580 Eigen::Vector3d position_;
581 Eigen::Quaterniond orientation_;
582 Eigen::Vector3d linear_velocity_;
583 Eigen::Vector3d angular_velocity_;
584 Eigen::Vector3d linear_acceleration_;
585 Eigen::Vector3d angular_acceleration_;
586 Eigen::Vector3d force_;
587 Eigen::Vector3d torque_;
588};
589
590inline void swap(CartesianState& state1, CartesianState& state2) {
591 swap(static_cast<SpatialState&>(state1), static_cast<SpatialState&>(state2));
592 std::swap(state1.position_, state2.position_);
593 std::swap(state1.orientation_, state2.orientation_);
594 std::swap(state1.linear_velocity_, state2.linear_velocity_);
595 std::swap(state1.angular_velocity_, state2.angular_velocity_);
596 std::swap(state1.linear_acceleration_, state2.linear_acceleration_);
597 std::swap(state1.angular_acceleration_, state2.angular_acceleration_);
598 std::swap(state1.force_, state2.force_);
599 std::swap(state1.torque_, state2.torque_);
600}
601}// 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.
void set_acceleration(const Eigen::Matrix< double, 6, 1 > &acceleration)
Setter of the linear and angular acceleration from a 6d acceleration vector.
CartesianState inverse() const
Compute the inverse of the current Cartesian state.
Eigen::ArrayXd array() const
Return the data vector as an Eigen Array.
const Eigen::Vector3d & get_torque() const
Getter of the torque attribute.
static CartesianState Random(const std::string &name, const std::string &reference="world")
Constructor for a random Cartesian state.
void set_state_variable(const Eigen::VectorXd &new_value, const CartesianStateVariable &state_variable_type)
Setter of the variable value corresponding to the input.
void set_orientation(const Eigen::Quaterniond &orientation)
Setter of the orientation.
friend std::ostream & operator<<(std::ostream &os, const CartesianState &state)
Overload the ostream operator for printing.
const Eigen::Vector3d & get_linear_velocity() const
Getter of the linear velocity attribute.
void set_angular_acceleration(const Eigen::Vector3d &angular_acceleration)
Setter of the angular velocity attribute.
const Eigen::Vector3d & get_position() const
Getter of the position attribute.
void normalize(const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL)
Normalize inplace the state at the state variable given in argument. Default is full state.
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.
Eigen::Matrix< double, 6, 1 > get_twist() const
Getter of the 6d twist from linear and angular velocity attributes.
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.
friend double dist(const CartesianState &s1, const CartesianState &s2, const CartesianStateVariable &state_variable_type)
Compute the distance between two Cartesian states.
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.
const Eigen::Vector3d & get_linear_acceleration() const
Getter of the linear acceleration attribute.
Eigen::Matrix4d get_transformation_matrix() const
Getter of a pose from position and orientation attributes.
void set_linear_acceleration(const Eigen::Vector3d &linear_acceleration)
Setter of the linear acceleration attribute.
void clamp_state_variable(double max_norm, const CartesianStateVariable &state_variable_type, double noise_ratio=0)
Clamp inplace the norm of the a specific state variable.
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.
void set_wrench(const Eigen::Matrix< double, 6, 1 > &wrench)
Setter of the force and torque from a 6d wrench vector.
const Eigen::Quaterniond & get_orientation() const
Getter of the orientation attribute.
Eigen::Matrix< double, 6, 1 > get_wrench() const
Getter of the 6d wrench from force and torque attributes.
Eigen::VectorXd get_state_variable(const CartesianStateVariable &state_variable_type) const
Getter of the variable value corresponding to the input.
void set_twist(const Eigen::Matrix< double, 6, 1 > &twist)
Setter of the linear and angular velocities from a 6d twist vector.
CartesianState & operator+=(const CartesianState &state)
Add inplace another Cartesian state.
CartesianState operator-() const
Negate a Cartesian state.
CartesianState & operator=(const CartesianState &state)
Copy assignment operator that has to be defined to the custom assignment operator.
virtual Eigen::VectorXd data() const
Return the data as the concatenation of all the state variables in a single vector.
const Eigen::Vector3d & get_angular_velocity() const
Getter of the angular velocity attribute.
void set_pose(const Eigen::Vector3d &position, const Eigen::Quaterniond &orientation)
Setter of the pose from both position and orientation.
CartesianState copy() const
Return a copy of the 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.
virtual void set_data(const Eigen::VectorXd &data) override
Set the data of the state from all the state variables in a single Eigen vector.
Eigen::Vector4d get_orientation_coefficients() const
Getter of the orientation attribute as Vector4d of coefficients.
CartesianState & operator*=(const CartesianState &state)
Transform inplace a Cartesian state into the current reference frame.
const Eigen::Vector3d & get_angular_acceleration() const
Getter of the angular acceleration attribute.
CartesianState operator/(double lambda) const
Scale a Cartesian state by a scalar.
std::vector< double > to_std_vector() const
Return the state as a std vector.
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.
Eigen::Matrix< double, 6, 1 > get_acceleration() const
Getter of the 6d acceleration from linear and angular acceleration attributes.
friend void swap(CartesianState &state1, CartesianState &state2)
Swap the values of two Cartesian states.
void reset() override
Reset the object to a post-construction state.
CartesianState operator+(const CartesianState &state) const
Add another Cartesian state.
Core state variables and objects.
double dist(const CartesianState &s1, const CartesianState &s2, const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL)
Compute the distance between two Cartesian states.
void swap(AnalogIOState &state1, AnalogIOState &state2)