Control Libraries 7.4.0
Loading...
Searching...
No Matches
DualQuaternionState.cpp
1#include "state_representation/space/dual_quaternion/DualQuaternionState.hpp"
2
3namespace state_representation {
6
7DualQuaternionState::DualQuaternionState(const std::string& name, const std::string& reference) :
8 SpatialState(StateType::DUALQUATERNIONSTATE, name, reference) {
9 this->initialize();
10}
11
13 SpatialState(state),
14 primary(state.primary),
15 dual(state.dual) {}
16
18 const Eigen::Quaterniond& primary,
19 const Eigen::Quaterniond& dual,
20 const std::string& reference) :
21 SpatialState(StateType::DUALQUATERNIONSTATE, name, reference) {
22 this->set_primary(primary);
23 this->set_dual(dual);
24}
25
27 Eigen::Quaterniond primary = this->get_primary() * q.get_primary();
28 Eigen::Quaterniond dual =
29 Eigen::Quaterniond((this->get_primary() * q.get_dual()).coeffs() + (this->get_dual() * q.get_primary()).coeffs());
30 this->set_primary(primary);
31 this->set_dual(dual);
32 this->set_name(q.get_name());
33 return (*this);
34}
35
37 DualQuaternionState result(*this);
38 result *= p;
39 return result;
40}
41
43 DualQuaternionState result(*this);
44 result.set_primary(result.get_primary().conjugate());
45 result.set_dual(result.get_dual().conjugate());
46 return result;
47}
48
50 this->State::initialize();
51 this->primary = Eigen::Quaterniond::Identity();
52 this->dual = Eigen::Quaterniond(0, 0, 0, 0);
53}
54
55const DualQuaternionState operator*(const float& lambda, const DualQuaternionState& state) {
56 DualQuaternionState result(state.get_name(), state.get_reference_frame());
57 result.set_primary(Eigen::Quaterniond(lambda * state.get_primary().coeffs()));
58 result.set_dual(Eigen::Quaterniond(lambda * state.get_dual().coeffs()));
59 return result;
60}
61
63 DualQuaternionState result(state.get_name(), state.get_reference_frame());
64 Eigen::Quaterniond pexps;
65 if (state.get_primary().norm() > 1e-5) {
66 Eigen::Array4d
67 coeffs = (sin(state.get_primary().norm()) / state.get_primary().norm()) * state.get_primary().coeffs();
68 // to be extra carefulm Quaternion coeffs are returned as (x,y,z,w)
69 pexps = Eigen::Quaterniond(coeffs(3) + cos(state.get_primary().norm()), coeffs(0), coeffs(1), coeffs(2));
70 } else {
71 pexps = Eigen::Quaterniond::Identity();
72 }
73 result.set_primary(pexps);
74 result.set_dual(state.get_dual() * pexps);
75 return result;
76}
77
79 DualQuaternionState result(*this);
80 return result;
81}
82
83std::ostream& operator<<(std::ostream& os, const DualQuaternionState& state) {
84 if (state.is_empty()) {
85 os << "Empty DualQuaternionState";
86 } else {
87 os << state.get_name() << " DualQuaternionState expressed in " << state.get_reference_frame() << " frame"
88 << std::endl;
89 os << "primary: (" << state.primary.w() << ", ";
90 os << state.primary.x() << ", ";
91 os << state.primary.y() << ", ";
92 os << state.primary.z() << ")" << std::endl;
93 os << "dual: (" << state.dual.w() << ", ";
94 os << state.dual.x() << ", ";
95 os << state.dual.y() << ", ";
96 os << state.dual.z() << ")";
97 }
98 return os;
99}
100}
Class to represent a state in Dual Quaternion space.
const Eigen::Quaterniond & get_dual() const
Getter of the dual attribute.
const Eigen::Quaterniond & get_primary() const
Getter of the primary attribute.
void set_primary(const Eigen::Quaterniond &primary)
Setter of the primary attribute.
void set_dual(const Eigen::Quaterniond &dual)
Setter of the dual attribute.
DualQuaternionState & operator*=(const DualQuaternionState &q)
Overload the *= operator.
const DualQuaternionState copy() const
Return a copy of the DualQuaternionState.
virtual void initialize()
Initialize the DualQuaternionState to a zero value.
friend const DualQuaternionState operator*(const float &lambda, const DualQuaternionState &state)
Overload the * operator with a scalar.
const DualQuaternionState conjugate() const
compute the conjugate of the current DualQuaternion
const std::string & get_name() const
Getter of the name attribute.
Definition State.cpp:29
virtual void set_name(const std::string &name)
Setter of the name attribute.
Definition State.cpp:45
Core state variables and objects.
std::ostream & operator<<(std::ostream &os, const AnalogIOState &state)
const DualQuaternionState exp(const DualQuaternionState &state)
StateType
The class types inheriting from State.
Definition StateType.hpp:13
CartesianAcceleration operator*(double lambda, const CartesianAcceleration &acceleration)