3#include "state_representation/State.hpp"
4#include "state_representation/exceptions/IncompatibleSizeException.hpp"
16 POSITIONS, VELOCITIES, ACCELERATIONS, TORQUES, ALL
28 const JointState& s1,
const JointState& s2,
const JointStateVariable& state_variable_type = JointStateVariable::ALL
47 explicit JointState(
const std::string& robot_name,
unsigned int nb_joints = 0);
54 JointState(
const std::string& robot_name,
const std::vector<std::string>& joint_names);
68 static JointState Zero(
const std::string& robot_name,
unsigned int nb_joints);
76 static JointState Zero(
const std::string& robot_name,
const std::vector<std::string>& joint_names);
84 static JointState Random(
const std::string& robot_name,
unsigned int nb_joints);
92 static JointState Random(
const std::string& robot_name,
const std::vector<std::string>& joint_names);
117 const std::vector<std::string>&
get_names()
const;
139 double get_position(
const std::string& joint_name)
const;
161 double get_velocity(
const std::string& joint_name)
const;
205 double get_torque(
const std::string& joint_name)
const;
213 double get_torque(
unsigned int joint_index)
const;
219 virtual Eigen::VectorXd
data()
const;
225 Eigen::ArrayXd
array()
const;
237 void set_names(
const std::vector<std::string>& names);
257 void set_position(
double position,
const std::string& joint_name);
265 void set_position(
double position,
unsigned int joint_index);
285 void set_velocity(
double velocity,
const std::string& joint_name);
293 void set_velocity(
double velocity,
unsigned int joint_index);
333 void set_torques(
const std::vector<double>& torques);
341 void set_torque(
double torque,
const std::string& joint_name);
349 void set_torque(
double torque,
unsigned int joint_index);
355 virtual void set_data(
const Eigen::VectorXd&
data)
override;
361 virtual void set_data(
const std::vector<double>&
data)
override;
371 double max_absolute_value,
const JointStateVariable& state_variable_type,
double noise_ratio = 0
383 const Eigen::ArrayXd& max_absolute_value_array,
const JointStateVariable& state_variable_type,
384 const Eigen::ArrayXd& noise_ratio_array
414 void reset()
override;
568 std::vector<std::string> names_;
569 Eigen::VectorXd positions_;
570 Eigen::VectorXd velocities_;
571 Eigen::VectorXd accelerations_;
572 Eigen::VectorXd torques_;
577 std::swap(state1.names_, state2.names_);
578 std::swap(state1.positions_, state2.positions_);
579 std::swap(state1.velocities_, state2.velocities_);
580 std::swap(state1.accelerations_, state2.accelerations_);
581 std::swap(state1.torques_, state2.torques_);
Class to define a state in joint space.
const Eigen::VectorXd & get_torques() const
Getter of the torques attribute.
JointState operator+(const JointState &state) const
Add another joint sate.
void set_accelerations(const Eigen::VectorXd &accelerations)
Setter of the accelerations attribute.
void reset() override
Reset the object to a post-construction state.
void multiply_state_variable(const Eigen::MatrixXd &lambda, const JointStateVariable &state_variable_type)
Proxy function that scale the specified state variable by a matrix.
double get_torque(const std::string &joint_name) const
Get the torque of a joint by its name, if it exists.
void set_positions(const Eigen::VectorXd &positions)
Setter of the positions attribute.
static JointState Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for a random joint state.
JointState()
Empty constructor for a joint state.
void set_names(unsigned int nb_joints)
Setter of the names attribute from the number of joints.
JointState & operator=(const JointState &state)
Copy assignment operator that has to be defined to the custom assignment operator.
JointState & operator*=(double lambda)
Scale inplace by a scalar.
void set_zero()
Set the joint state to a zero value.
const Eigen::VectorXd & get_velocities() const
Getter of the velocities attribute.
unsigned int get_size() const
Getter of the size from the attributes.
bool is_incompatible(const State &state) const override
Check if the joint state is incompatible for operations with the state given as argument.
Eigen::VectorXd get_state_variable(const JointStateVariable &state_variable_type) const
Getter of the variable value corresponding to the input.
void set_state_variable(const Eigen::VectorXd &new_value, const JointStateVariable &state_variable_type)
Setter of the variable value corresponding to the input.
void clamp_state_variable(double max_absolute_value, const JointStateVariable &state_variable_type, double noise_ratio=0)
Clamp inplace the magnitude of the a specific joint state variable.
void set_acceleration(double acceleration, const std::string &joint_name)
Set the acceleration of a joint by its name.
std::vector< double > to_std_vector() const
Return the joint state as a std vector.
static JointState Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for a zero joint state.
Eigen::ArrayXd array() const
Returns the data vector as an Eigen array.
JointState & operator+=(const JointState &state)
Add inplace another joint state.
unsigned int get_joint_index(const std::string &joint_name) const
Get joint index by the name of the joint, if it exists.
JointState copy() const
Return a copy of the joint state.
double get_acceleration(const std::string &joint_name) const
Get the acceleration of a joint by its name, if it exists.
void set_torques(const Eigen::VectorXd &torques)
Setter of the torques attribute.
std::string to_string() const override
Convert the state to its string representation.
void set_position(double position, const std::string &joint_name)
Set the position of a joint by its name.
double get_velocity(const std::string &joint_name) const
Get the velocity of a joint by its name, if it exists.
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.
friend std::ostream & operator<<(std::ostream &os, const JointState &state)
Overload the ostream operator for printing.
JointState & operator-=(const JointState &state)
Compute inplace the difference with another joint state.
void set_torque(double torque, const std::string &joint_name)
Set the torque of a joint by its name.
friend double dist(const JointState &s1, const JointState &s2, const JointStateVariable &state_variable_type)
Compute the distance between two joint states.
JointState & operator/=(double lambda)
Scale inplace by a scalar.
const Eigen::VectorXd & get_accelerations() const
Getter of the accelerations attribute.
JointState operator-() const
Negate a joint state.
friend JointState operator*(double lambda, const JointState &state)
Scale a joint state by a scalar.
const std::vector< std::string > & get_names() const
Getter of the names attribute.
double get_position(const std::string &joint_name) const
Get the position of a joint by its name, if it exists.
void set_velocity(double velocity, const std::string &joint_name)
Set the velocity of a joint by its name.
const Eigen::VectorXd & get_positions() const
Getter of the positions attribute.
void set_velocities(const Eigen::VectorXd &velocities)
Setter of the velocities attribute.
JointState operator/(double lambda) const
Scale a joint state by a scalar.
virtual Eigen::VectorXd data() const
Returns the data as the concatenation of all the state variables in a single vector.
friend void swap(JointState &state1, JointState &state2)
Swap the values of the two joint states.
Abstract class to represent a 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)
JointStateVariable
Enum representing all the fields (positions, velocities, accelerations and torques) of the JointState...