Control Libraries 7.4.0
Loading...
Searching...
No Matches
DualQuaternionPose.cpp
1#include "state_representation/space/dual_quaternion/DualQuaternionPose.hpp"
2
3namespace state_representation {
4DualQuaternionPose::DualQuaternionPose(const std::string& name, const std::string& reference) :
5 DualQuaternionState(name, reference) {
6 this->initialize();
7}
8
10 DualQuaternionState(state), position(state.position) {}
11
16
18 const Eigen::Vector3d& position,
19 const Eigen::Quaterniond& orientation,
20 const std::string& reference) :
21 DualQuaternionState(name, reference) {
22 this->initialize();
23 this->set_position(position);
24 this->set_orientation(orientation);
25}
26
28 return static_cast<const DualQuaternionState&>(*this).conjugate();
29}
30
32 DualQuaternionPose result(*this);
33 // inverse name and reference frame
34 std::string ref = this->get_reference_frame();
35 std::string name = this->get_name();
36 result.set_reference_frame(name);
37 result.set_name(ref);
38 return result.conjugate();
39}
40
42 Eigen::Quaterniond primary = this->get_primary() * q.get_primary();
43 Eigen::Quaterniond dual =
44 Eigen::Quaterniond((this->get_primary() * q.get_dual()).coeffs() + (this->get_dual() * q.get_primary()).coeffs());
45 this->set_primary(primary);
46 this->set_dual(dual);
47 this->set_position(this->get_dual());
48 this->set_name(q.get_name());
49 return (*this);
50}
51
53 DualQuaternionState result(*this);
54 result *= p;
55 return result;
56}
57
59 // Why two functions DualQuaternionState/DualQuaternionPose and referenced via base-pointer?
60 Eigen::Quaterniond primary = this->get_primary() * s.get_primary();
61 Eigen::Quaterniond dual =
62 Eigen::Quaterniond((this->get_primary() * s.get_dual()).coeffs() + (this->get_dual() * s.get_primary()).coeffs());
63 this->set_primary(primary);
64 this->set_dual(dual);
65 this->set_position(this->get_dual());
66 this->set_name(s.get_name());
67 return (*this);
68}
69
71 DualQuaternionState result(*this);
72 result *= s;
73 return result;
74}
75
77 this->set_primary(s.get_primary());
78 this->set_dual(s.get_dual());
79 this->set_position(this->get_dual());
80 this->set_name(s.get_name());
82}
83
86 this->position = Eigen::Vector3d(0, 0, 0);
87}
88
90 DualQuaternionPose result(*this);
91 return result;
92}
93
95 DualQuaternionState result(state.get_name(), state.get_reference_frame());
96 Eigen::AngleAxisd axis_angle(state.get_primary());
97 Eigen::Vector3d rotation = (axis_angle.angle() * axis_angle.axis()) / 2;
98 Eigen::Vector3d position = state.get_position() / 2;
99 result.set_primary(Eigen::Quaterniond(0, rotation(0), rotation(1), rotation(2)));
100 result.set_dual(Eigen::Quaterniond(0, position(0), position(1), position(2)));
101 return result;
102}
103
104std::ostream& operator<<(std::ostream& os, const DualQuaternionPose& state) {
105 if (state.is_empty()) {
106 os << "Empty DualQuaternionPose";
107 } else {
108 os << state.get_name() << " DualQuaternionPose expressed in " << state.get_reference_frame() << " frame"
109 << std::endl;
110 os << "primary/orientation: (" << state.get_primary().w() << ", ";
111 os << state.get_primary().x() << ", ";
112 os << state.get_primary().y() << ", ";
113 os << state.get_primary().z() << ")";
114 Eigen::AngleAxisd axis_angle(state.get_primary());
115 os << " <=> theta: " << axis_angle.angle() << ", ";
116 os << "axis: (" << axis_angle.axis()(0) << ", ";
117 os << axis_angle.axis()(1) << ", ";
118 os << axis_angle.axis()(2) << ")" << std::endl;
119 os << "dual: (" << state.get_dual().w() << ", ";
120 os << state.get_dual().x() << ", ";
121 os << state.get_dual().y() << ", ";
122 os << state.get_dual().z() << ")";
123 Eigen::Vector3d position = state.get_position();
124 os << " => position: (" << position(0) << ", ";
125 os << position(1) << ", ";
126 os << position(2) << ")";
127 }
128 return os;
129}
130}
Class to represent a Pose in Dual Quaternion space.
void set_orientation(const Eigen::Quaterniond &orientation)
Setter of the orientation.
const DualQuaternionPose inverse() const
compute the inverse of the current DualQuaternionPose
void set_position(const Eigen::Vector3d &position)
Setter of the psotion from a vector.
void initialize()
Initialize the DualQuaternionPose to a zero value.
DualQuaternionPose & operator*=(const DualQuaternionPose &q)
Overload the *= operator.
void operator=(const DualQuaternionState &s)
Overload the = operator with a DualQuaternionState.
const DualQuaternionPose conjugate() const
compute the conjugate of the current DualQuaternionPose
DualQuaternionPose(const std::string &name, const std::string &reference="world")
Constructor with name and reference frame provided.
const DualQuaternionPose copy() const
Return a copy of the DualQuaternionPose.
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.
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
virtual void set_reference_frame(const std::string &reference_frame)
Setter of the reference frame.
const std::string & get_reference_frame() const
Getter of the reference frame as const reference.
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 log(const DualQuaternionPose &state)