3#include "state_representation/space/SpatialState.hpp"
4#include "state_representation/exceptions/IncompatibleSizeException.hpp"
14enum class CartesianStateVariable {
39 const CartesianState& s1,
const CartesianState& s2,
40 const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL
49 Eigen::Vector3d position_;
50 Eigen::Quaterniond orientation_;
51 Eigen::Vector3d linear_velocity_;
52 Eigen::Vector3d angular_velocity_;
53 Eigen::Vector3d linear_acceleration_;
54 Eigen::Vector3d angular_acceleration_;
55 Eigen::Vector3d force_;
56 Eigen::Vector3d torque_;
62 void set_all_state_variables(
const Eigen::VectorXd& new_values);
69 void set_state_variable(Eigen::Vector3d& state_variable,
const Eigen::Vector3d& new_value);
76 void set_state_variable(Eigen::Vector3d& state_variable,
const std::vector<double>& new_value);
84 void set_state_variable(
85 Eigen::Vector3d& linear_state_variable, Eigen::Vector3d& angular_state_variable,
86 const Eigen::Matrix<double, 6, 1>& new_value
95 Eigen::VectorXd
get_state_variable(
const CartesianStateVariable& state_variable_type)
const;
102 void set_state_variable(
const Eigen::VectorXd& new_value,
const CartesianStateVariable& state_variable_type);
115 explicit CartesianState(
const std::string& name,
const std::string& reference =
"world");
173 Eigen::Matrix<double, 7, 1>
get_pose()
const;
194 Eigen::Matrix<double, 6, 1>
get_twist()
const;
214 const Eigen::Vector3d&
get_force()
const;
224 Eigen::Matrix<double, 6, 1>
get_wrench()
const;
239 void set_position(
const double& x,
const double& y,
const double& z);
263 void set_orientation(
const double& w,
const double& x,
const double& y,
const double& z);
270 void set_pose(
const Eigen::Vector3d& position,
const Eigen::Quaterniond& orientation);
277 void set_pose(
const Eigen::Matrix<double, 7, 1>& pose);
284 void set_pose(
const std::vector<double>& pose);
319 void set_twist(
const Eigen::Matrix<double, 6, 1>& twist);
324 void set_twist(
const std::vector<double>& twist);
369 void set_force(
const Eigen::Vector3d& force);
374 void set_force(
const std::vector<double>& force);
379 void set_force(
const double& x,
const double& y,
const double& z);
384 void set_torque(
const Eigen::Vector3d& torque);
389 void set_torque(
const std::vector<double>& torque);
394 void set_torque(
const double& x,
const double& y,
const double& z);
399 void set_wrench(
const Eigen::Matrix<double, 6, 1>& wrench);
404 void set_wrench(
const std::vector<double>& wrench);
423 void clamp_state_variable(
double max_norm,
const CartesianStateVariable& state_variable_type,
double noise_ratio = 0);
436 virtual Eigen::VectorXd
data()
const;
442 Eigen::ArrayXd
array()
const;
449 virtual void set_data(
const Eigen::VectorXd&
data)
override;
456 virtual void set_data(
const std::vector<double>&
data)
override;
542 const CartesianState& state,
const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL
550 virtual std::vector<double>
551 norms(
const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL)
const;
557 void normalize(
const CartesianStateVariable& state_variable_type = CartesianStateVariable::ALL);
602 std::swap(state1.position_, state2.position_);
603 std::swap(state1.orientation_, state2.orientation_);
604 std::swap(state1.linear_velocity_, state2.linear_velocity_);
605 std::swap(state1.angular_velocity_, state2.angular_velocity_);
606 std::swap(state1.linear_acceleration_, state2.linear_acceleration_);
607 std::swap(state1.angular_acceleration_, state2.angular_acceleration_);
608 std::swap(state1.force_, state2.force_);
609 std::swap(state1.torque_, state2.torque_);
619 switch (state_variable_type) {
620 case CartesianStateVariable::POSITION:
623 case CartesianStateVariable::ORIENTATION:
626 case CartesianStateVariable::POSE:
629 case CartesianStateVariable::LINEAR_VELOCITY:
632 case CartesianStateVariable::ANGULAR_VELOCITY:
635 case CartesianStateVariable::TWIST:
638 case CartesianStateVariable::LINEAR_ACCELERATION:
641 case CartesianStateVariable::ANGULAR_ACCELERATION:
644 case CartesianStateVariable::ACCELERATION:
647 case CartesianStateVariable::FORCE:
650 case CartesianStateVariable::TORQUE:
653 case CartesianStateVariable::WRENCH:
656 case CartesianStateVariable::ALL:
657 Eigen::VectorXd all_fields(25);
662 return Eigen::Vector3d::Zero();
665inline void CartesianState::set_all_state_variables(
const Eigen::VectorXd& new_values) {
666 if (new_values.size() != 25) {
668 "Input is of incorrect size: expected 25, given " + std::to_string(new_values.size()));
670 this->
set_pose(new_values.segment(0, 7));
671 this->
set_twist(new_values.segment(7, 6));
676inline void CartesianState::set_state_variable(Eigen::Vector3d& state_variable,
const Eigen::Vector3d& new_value) {
678 state_variable = new_value;
681inline void CartesianState::set_state_variable(Eigen::Vector3d& state_variable,
const std::vector<double>& new_value) {
682 if (new_value.size() != 3) {
683 throw exceptions::IncompatibleSizeException(
684 "Input vector is of incorrect size: expected 3, given " + std::to_string(new_value.size()));
686 this->set_state_variable(state_variable, Eigen::Vector3d::Map(new_value.data(), new_value.size()));
689inline void CartesianState::set_state_variable(
690 Eigen::Vector3d& linear_state_variable, Eigen::Vector3d& angular_state_variable,
691 const Eigen::Matrix<double, 6, 1>& new_value
693 this->set_state_variable(linear_state_variable, new_value.head(3));
694 this->set_state_variable(angular_state_variable, new_value.tail(3));
697inline void CartesianState::set_state_variable(
698 const Eigen::VectorXd& new_value,
const CartesianStateVariable& state_variable_type
700 switch (state_variable_type) {
701 case CartesianStateVariable::POSITION:
705 case CartesianStateVariable::ORIENTATION:
709 case CartesianStateVariable::POSE:
713 case CartesianStateVariable::LINEAR_VELOCITY:
717 case CartesianStateVariable::ANGULAR_VELOCITY:
721 case CartesianStateVariable::TWIST:
725 case CartesianStateVariable::LINEAR_ACCELERATION:
729 case CartesianStateVariable::ANGULAR_ACCELERATION:
733 case CartesianStateVariable::ACCELERATION:
737 case CartesianStateVariable::FORCE:
741 case CartesianStateVariable::TORQUE:
745 case CartesianStateVariable::WRENCH:
749 case CartesianStateVariable::ALL:
750 this->
set_pose(new_value.segment(0, 7));
751 this->
set_twist(new_value.segment(7, 6));
759 Eigen::VectorXd
data = this->
data();
760 return std::vector<double>(
data.data(),
data.data() +
data.size());
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 CartesianState.
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 state.
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)
CartesianState operator-(const CartesianState &state) const
Overload the - operator.
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 CartesianStates
CartesianState()
Empty constructor.
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.
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 a pose from position and orientation attributes.
void set_position(const Eigen::Vector3d &position)
Setter of the position.
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)
Overload the += operator.
CartesianState & operator=(const CartesianState &state)
Copy assignment operator that have 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 CartesianState.
CartesianState & operator-=(const CartesianState &state)
Overload the -= operator.
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 Beware, quaternion coefficients are r...
CartesianState & operator*=(const CartesianState &state)
Overload the *= operator with another state by deriving the equations of motions.
const Eigen::Vector3d & get_angular_acceleration() const
Getter of the angular acceleration attribute.
CartesianState(const CartesianState &state)=default
Copy constructor of a CartesianState.
CartesianState operator/(double lambda) const
Overload the / operator with a scalar.
void initialize() override
Initialize the CartesianState to a zero value.
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)
Overload the * operator with 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 the two CartesianState.
CartesianState operator+(const CartesianState &state) const
Overload the + operator.
void set_filled()
Setter of the empty attribute to false and also reset the timestamp.
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 CartesianStates
void swap(CartesianState &state1, CartesianState &state2)