Control Libraries 6.3.4
Loading...
Searching...
No Matches
JointAccelerations.cpp
1#include "state_representation/space/joint/JointAccelerations.hpp"
2#include "state_representation/exceptions/EmptyStateException.hpp"
3
4using namespace state_representation::exceptions;
5
6namespace state_representation {
8 this->set_type(StateType::JOINT_ACCELERATIONS);
9}
10
11JointAccelerations::JointAccelerations(const std::string& robot_name, unsigned int nb_joints) :
12 JointState(robot_name, nb_joints) {
13 this->set_type(StateType::JOINT_ACCELERATIONS);
14}
15
16JointAccelerations::JointAccelerations(const std::string& robot_name, const Eigen::VectorXd& accelerations) :
17 JointState(robot_name, accelerations.size()) {
18 this->set_type(StateType::JOINT_ACCELERATIONS);
19 this->set_accelerations(accelerations);
20}
21
22JointAccelerations::JointAccelerations(const std::string& robot_name, const std::vector<std::string>& joint_names) :
23 JointState(robot_name, joint_names) {
24 this->set_type(StateType::JOINT_ACCELERATIONS);}
25
26JointAccelerations::JointAccelerations(const std::string& robot_name,
27 const std::vector<std::string>& joint_names,
28 const Eigen::VectorXd& accelerations) : JointState(robot_name, joint_names) {
29 this->set_type(StateType::JOINT_ACCELERATIONS);
30 this->set_accelerations(accelerations);
31}
32
34 // set all the state variables to 0 except accelerations
35 this->set_type(StateType::JOINT_ACCELERATIONS);
36 this->set_zero();
38 this->set_empty(state.is_empty());
39}
40
42 JointAccelerations(static_cast<const JointState&>(accelerations)) {}
43
45 JointAccelerations(velocities / std::chrono::seconds(1)) {}
46
47JointAccelerations JointAccelerations::Zero(const std::string& robot_name, unsigned int nb_joints) {
48 return JointState::Zero(robot_name, nb_joints);
49}
50
52JointAccelerations::Zero(const std::string& robot_name, const std::vector<std::string>& joint_names) {
53 return JointState::Zero(robot_name, joint_names);
54}
55
56JointAccelerations JointAccelerations::Random(const std::string& robot_name, unsigned int nb_joints) {
57 return JointAccelerations(robot_name, Eigen::VectorXd::Random(nb_joints));
58}
59
61JointAccelerations::Random(const std::string& robot_name, const std::vector<std::string>& joint_names) {
62 return JointAccelerations(robot_name, joint_names, Eigen::VectorXd::Random(joint_names.size()));
63}
64
66 this->JointState::operator+=(accelerations);
67 return (*this);
68}
69
71 return this->JointState::operator+(accelerations);
72}
73
75 this->JointState::operator-=(accelerations);
76 return (*this);
77}
78
80 return this->JointState::operator-(accelerations);
81}
82
84 this->JointState::operator*=(lambda);
85 return (*this);
86}
87
89 return this->JointState::operator*(lambda);
90}
91
92JointAccelerations& JointAccelerations::operator*=(const Eigen::ArrayXd& lambda) {
93 this->multiply_state_variable(lambda, JointStateVariable::ACCELERATIONS);
94 return (*this);
95}
96
97JointAccelerations JointAccelerations::operator*(const Eigen::ArrayXd& lambda) const {
98 JointAccelerations result(*this);
99 result *= lambda;
100 return result;
101}
102
103JointAccelerations& JointAccelerations::operator*=(const Eigen::MatrixXd& lambda) {
104 this->multiply_state_variable(lambda, JointStateVariable::ACCELERATIONS);
105 return (*this);
106}
107
108JointAccelerations JointAccelerations::operator*(const Eigen::MatrixXd& lambda) const {
109 JointAccelerations result(*this);
110 result *= lambda;
111 return result;
112}
113
115 this->JointState::operator/=(lambda);
116 return (*this);
117}
118
120 return this->JointState::operator/(lambda);
121}
122
123JointVelocities JointAccelerations::operator*(const std::chrono::nanoseconds& dt) const {
124 if (this->is_empty()) { throw EmptyStateException(this->get_name() + " state is empty"); }
125 // operations
126 JointVelocities velocities(this->get_name(), this->get_names());
127 // convert the period to a double with the second as reference
128 double period = dt.count();
129 period /= 1e9;
130 // multiply the velocities by this period value and assign it as position
131 velocities.set_velocities(period * this->get_accelerations());
132 return velocities;
133}
134
136 JointAccelerations result(*this);
137 return result;
138}
139
140Eigen::VectorXd JointAccelerations::data() const {
141 return this->get_accelerations();
142}
143
144void JointAccelerations::set_data(const Eigen::VectorXd& data) {
145 this->set_accelerations(data);
146}
147
148void JointAccelerations::set_data(const std::vector<double>& data) {
149 this->set_accelerations(Eigen::VectorXd::Map(data.data(), data.size()));
150}
151
152void JointAccelerations::clamp(double max_absolute_value, double noise_ratio) {
153 this->clamp_state_variable(max_absolute_value, JointStateVariable::ACCELERATIONS, noise_ratio);
154}
155
156JointAccelerations JointAccelerations::clamped(double max_absolute_value, double noise_ratio) const {
157 JointAccelerations result(*this);
158 result.clamp(max_absolute_value, noise_ratio);
159 return result;
160}
161
162void
163JointAccelerations::clamp(const Eigen::ArrayXd& max_absolute_value_array, const Eigen::ArrayXd& noise_ratio_array) {
164 this->clamp_state_variable(max_absolute_value_array, JointStateVariable::ACCELERATIONS, noise_ratio_array);
165}
166
167JointAccelerations JointAccelerations::clamped(const Eigen::ArrayXd& max_absolute_value_array,
168 const Eigen::ArrayXd& noise_ratio_array) const {
169 JointAccelerations result(*this);
170 result.clamp(max_absolute_value_array, noise_ratio_array);
171 return result;
172}
173
174std::ostream& operator<<(std::ostream& os, const JointAccelerations& accelerations) {
175 if (accelerations.is_empty()) {
176 os << "Empty JointAccelerations";
177 } else {
178 os << accelerations.get_name() << " JointAccelerations" << std::endl;
179 os << "names: [";
180 for (auto& n : accelerations.get_names()) { os << n << ", "; }
181 os << "]" << std::endl;
182 os << "accelerations: [";
183 for (unsigned int i = 0; i < accelerations.get_size(); ++i) { os << accelerations.get_accelerations()(i) << ", "; }
184 os << "]";
185 }
186 return os;
187}
188
189JointAccelerations operator*(double lambda, const JointAccelerations& accelerations) {
190 JointAccelerations result(accelerations);
191 result *= lambda;
192 return result;
193}
194
195JointAccelerations operator*(const Eigen::ArrayXd& lambda, const JointAccelerations& accelerations) {
196 JointAccelerations result(accelerations);
197 result *= lambda;
198 return result;
199}
200
201JointAccelerations operator*(const Eigen::MatrixXd& lambda, const JointAccelerations& accelerations) {
202 JointAccelerations result(accelerations);
203 result *= lambda;
204 return result;
205}
206
207JointVelocities operator*(const std::chrono::nanoseconds& dt, const JointAccelerations& accelerations) {
208 return accelerations * dt;
209}
210}// namespace state_representation
Class to define accelerations of the joints.
JointAccelerations copy() const
Return a copy of the JointAccelerations.
JointAccelerations & operator-=(const JointAccelerations &accelerations)
Overload the -= operator.
JointAccelerations & operator+=(const JointAccelerations &accelerations)
Overload the += operator.
JointAccelerations operator+(const JointAccelerations &accelerations) const
Overload the + operator.
Eigen::VectorXd data() const override
Returns the accelerations data as an Eigen vector.
JointAccelerations clamped(double max_absolute_value, double noise_ratio=0.) const
Return the acceleration clamped to the values in argument.
JointAccelerations & operator/=(double lambda)
Overload the /= operator with a scalar.
JointAccelerations operator-(const JointAccelerations &accelerations) const
Overload the - operator.
friend JointAccelerations operator*(double lambda, const JointAccelerations &accelerations)
Overload the * operator with a scalar.
virtual void set_data(const Eigen::VectorXd &data) override
Set the accelerations data from an Eigen vector.
static JointAccelerations Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for the zero JointAccelerations.
void clamp(double max_absolute_value, double noise_ratio=0.)
Clamp inplace the magnitude of the acceleration to the values in argument.
JointAccelerations operator/(double lambda) const
Overload the / operator with a scalar.
JointAccelerations & operator*=(double lambda)
Overload the *= operator with a double gain.
static JointAccelerations Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for the random JointAccelerations.
Class to define a state in joint space.
Definition: JointState.hpp:36
JointState operator+(const JointState &state) const
Overload the + operator.
Definition: JointState.cpp:231
void set_accelerations(const Eigen::VectorXd &accelerations)
Setter of the accelerations attribute.
Definition: JointState.cpp:163
JointState & operator*=(double lambda)
Overload the *= operator with a double gain.
Definition: JointState.cpp:260
void set_zero()
Set the JointState to a zero value.
Definition: JointState.cpp:43
unsigned int get_size() const
Getter of the size from the attributes.
Definition: JointState.hpp:656
JointState operator-(const JointState &state) const
Overload the - operator.
Definition: JointState.cpp:254
static JointState Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for a zero JointState.
Definition: JointState.cpp:50
JointState & operator+=(const JointState &state)
Overload the += operator.
Definition: JointState.cpp:214
JointState & operator-=(const JointState &state)
Overload the -= operator.
Definition: JointState.cpp:237
void multiply_state_variable(const Eigen::ArrayXd &lambda, const JointStateVariable &state_variable_type)
Proxy function that multiply the specified state variable by an array of gain.
Definition: JointState.cpp:268
JointState & operator/=(double lambda)
Overload the /= operator with a scalar.
Definition: JointState.cpp:319
const Eigen::VectorXd & get_accelerations() const
Getter of the accelerations attribute.
Definition: JointState.cpp:150
friend JointState operator*(double lambda, const JointState &state)
Overload the * operator with a scalar.
Definition: JointState.cpp:443
const std::vector< std::string > & get_names() const
Getter of the names attribute.
Definition: JointState.hpp:660
void set_velocities(const Eigen::VectorXd &velocities)
Setter of the velocities attribute.
Definition: JointState.cpp:131
JointState operator/(double lambda) const
Overload the / operator with a scalar.
Definition: JointState.cpp:323
Class to define velocities of the joints.
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