38{
39 std::cout << "==============================================" << std::endl;
40 std::cout << "MoveG Pose Library Example Usage" << std::endl;
41 std::cout << "==============================================" << std::endl;
42
43
44 std::cout << "\n1. Creating poses using different constructors:" << std::endl;
45
46
48 std::cout << "Identity pose at origin:" << std::endl;
51
52
53 Eigen::Vector3d position(1.0, 2.0, 3.0);
54 Eigen::Quaterniond orientation(Eigen::AngleAxisd(M_PI / 4, Eigen::Vector3d::UnitZ()));
55
56 Pose pose_from_quat(position, orientation);
57 std::cout << "\nPose from position and quaternion:" << std::endl;
60
61
62 Eigen::Matrix3d rot_matrix =
63 Eigen::AngleAxisd(M_PI / 3, Eigen::Vector3d::UnitY()).toRotationMatrix();
64 Pose pose_from_matrix(position, rot_matrix);
65 std::cout << "\nPose from position and rotation matrix:" << std::endl;
67 std::cout << "Rotation matrix:\n" << pose_from_matrix.getRotationMatrix() << std::endl;
68
69
70 Eigen::Affine3d affine = Eigen::Affine3d::Identity();
71 affine.translation() = Eigen::Vector3d(4.0, 5.0, 6.0);
72 affine.rotate(Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitX()));
73
74 Pose pose_from_affine(affine);
75 std::cout << "\nPose from Affine3d transformation:" << std::endl;
77 std::cout << "Rotation matrix:\n" << pose_from_affine.getRotationMatrix() << std::endl;
78
79
82 Pose pose_from_rotation(position, rotation);
83 std::cout << "\nPose from position and Rotation object:" << std::endl;
86
87
88 Eigen::Matrix4d homogeneous = Eigen::Matrix4d::Identity();
89 homogeneous.block<3, 3>(0, 0) =
90 Eigen::AngleAxisd(M_PI / 3, Eigen::Vector3d::UnitZ()).toRotationMatrix();
91 homogeneous.block<3, 1>(0, 3) = Eigen::Vector3d(7.0, 8.0, 9.0);
92
93 Pose pose_from_homogeneous(homogeneous);
94 std::cout << "\nPose from homogeneous transformation matrix:" << std::endl;
95 printVector3d(pose_from_homogeneous.getPosition(),
"Position");
97
98
99 std::cout << "\n2. Getting different representations of a pose:" << std::endl;
100
101 Pose example_pose(Eigen::Vector3d(1.0, 2.0, 3.0),
102 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 4, Eigen::Vector3d::UnitZ())));
103
104
105 std::cout << "Individual position components: x=" << example_pose.getX()
106 << ", y=" << example_pose.getY() << ", z=" << example_pose.getZ() << std::endl;
107
108
109 std::cout << "Individual quaternion components: w=" << example_pose.getQw()
110 << ", x=" << example_pose.getQx() << ", y=" << example_pose.getQy()
111 << ", z=" << example_pose.getQz() << std::endl;
112
113
114 std::cout << "Rotation matrix:\n" << example_pose.getRotationMatrix() << std::endl;
115
116
117 Eigen::Affine3d example_affine = example_pose.getAffineTransformation();
118 std::cout << "Affine transformation translation: [" << example_affine.translation().x() << ", "
119 << example_affine.translation().y() << ", " << example_affine.translation().z() << "]"
120 << std::endl;
121 std::cout << "Affine transformation rotation:\n" << example_affine.rotation() << std::endl;
122
123
124 Eigen::Matrix4d example_homogeneous = example_pose.getHomogeneousT();
126
127
128 std::cout << "\n3. Modifying poses:" << std::endl;
129
130 Pose modifiable_pose;
131 std::cout << "Initial pose:" << std::endl;
134
135
136 modifiable_pose.
setPosition(Eigen::Vector3d(5.0, 6.0, 7.0));
137
138
140 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 3, Eigen::Vector3d::UnitY())));
141
142 std::cout << "\nAfter modification:" << std::endl;
145
146
147 Eigen::Matrix3d new_rotation =
148 Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitZ()).toRotationMatrix();
150
151 std::cout << "\nAfter setting rotation matrix:" << std::endl;
153 std::cout <<
"Rotation matrix:\n" << modifiable_pose.
getRotationMatrix() << std::endl;
154
155
156 Eigen::Matrix4d new_homogeneous = Eigen::Matrix4d::Identity();
157 new_homogeneous.block<3, 3>(0, 0) =
158 Eigen::AngleAxisd(M_PI / 6, Eigen::Vector3d::UnitX()).toRotationMatrix();
159 new_homogeneous.block<3, 1>(0, 3) = Eigen::Vector3d(10.0, 11.0, 12.0);
160
162
163 std::cout << "\nAfter setting homogeneous transformation:" << std::endl;
166
167
168 std::cout << "\n4. Pose operations:" << std::endl;
169
170
171 Pose pose1(Eigen::Vector3d(1.0, 0.0, 0.0),
172 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitZ())));
173
174 Pose pose2(Eigen::Vector3d(0.0, 1.0, 0.0),
175 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitZ())));
176
177 std::cout << "Pose 1:" << std::endl;
180
181 std::cout << "\nPose 2:" << std::endl;
184
185
186 Pose composed = pose1 * pose2;
187 std::cout << "\nComposed pose (pose1 * pose2):" << std::endl;
190
191
193 std::cout << "\nInverse of pose1:" << std::endl;
196
197
198 Pose identity_check = pose1 * inverse;
199 std::cout << "\nPose1 * Inverse (should be identity):" << std::endl;
202
203
204 std::cout << "\n5. Distance metrics:" << std::endl;
205
206 Pose pose_a(Eigen::Vector3d(1.0, 2.0, 3.0),
207 Eigen::Quaterniond(Eigen::AngleAxisd(0.0, Eigen::Vector3d::UnitZ())));
208
209 Pose pose_b(Eigen::Vector3d(4.0, 6.0, 8.0),
210 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitZ())));
211
212 double position_distance = pose_a.positionDistance(pose_b);
213 double orientation_distance = pose_a.orientationDistance(pose_b);
214
215 std::cout << "Position distance: " << position_distance << " meters" << std::endl;
216 std::cout << "Orientation distance: " << orientation_distance << " radians ("
218
219
220 std::cout << "\n6. Coordinate transformations:" << std::endl;
221
222
224 Eigen::Vector3d(2.0, 3.0, 0.0),
225 Eigen::AngleAxisd(M_PI / 4, Eigen::Vector3d::UnitZ())
226 );
227
228
229 Eigen::Vector3d point_in_robot(1.0, 0.0, 0.0);
230
231
232 Eigen::Vector3d point_in_world = robot_in_world.localToGlobal(point_in_robot);
233
234 std::cout << "Robot pose in world:" << std::endl;
236 std::cout << "Rotation: "
238 << "° around " << Eigen::AngleAxisd(robot_in_world.getQuaternion()).axis().transpose()
239 << std::endl;
240
241 std::cout << "\nPoint in robot's local frame: [" << point_in_robot.x() << ", "
242 << point_in_robot.y() << ", " << point_in_robot.z() << "]" << std::endl;
243
244 std::cout << "Same point in world frame: [" << point_in_world.x() << ", " << point_in_world.y()
245 << ", " << point_in_world.z() << "]" << std::endl;
246
247
248 Eigen::Vector3d point_back_in_robot = robot_in_world.globalToLocal(point_in_world);
249
250 std::cout << "Point transformed back to robot frame: [" << point_back_in_robot.x() << ", "
251 << point_back_in_robot.y() << ", " << point_back_in_robot.z() << "]" << std::endl;
252
253
254
255 Pose sensor_in_robot(
256 Eigen::Vector3d(0.0, 0.0, 0.5),
257 Eigen::AngleAxisd(0.0, Eigen::Vector3d::UnitZ())
258 );
259
260
262
263 std::cout << "\nSensor pose in robot frame:" << std::endl;
266
267 std::cout << "\nSensor pose in world frame:" << std::endl;
270
271 std::cout << "==============================================" << std::endl;
272
273 return 0;
274}
Class representing a pose in 3D space.
void setOrientation(const Eigen::Quaterniond &orientation)
Sets the orientation via quaternion.
Pose transformPose(const Pose &transform) const
Transforms this pose from one coordinate frame to another.
Eigen::Vector3d getPosition() const
Gets the position.
void setRotationMatrix(const Eigen::Matrix3d &rotation_matrix)
Sets the rotation matrix.
void setPosition(const Eigen::Vector3d &position)
Sets the position.
void setHomogeneousT(const Eigen::Matrix4d &homogeneousT)
Sets the homogeneous transformation matrix.
Pose inverse() const
Calculates the inverse of the pose.
Eigen::Quaterniond getQuaternion() const
Gets the orientation quaternion.
Eigen::Matrix3d getRotationMatrix() const
Gets the rotation matrix.
Class for representing and managing rotations in three-dimensional space.
static Rotation fromAngleAxis(const Eigen::AngleAxisd &angle_axis)
Creates a rotation from an axis-angle representation.
static double rad2deg(double radian)
Converts radians to degrees.
void printHomogeneousMatrix(const Eigen::Matrix4d &mat, const std::string &description)
void printQuaternion(const Eigen::Quaterniond &quat, const std::string &description)
void printVector3d(const Eigen::Vector3d &vec, const std::string &description)