39 std::cout <<
"==============================================" << std::endl;
40 std::cout <<
"MoveG Pose Library Example Usage" << std::endl;
41 std::cout <<
"==============================================" << std::endl;
44 std::cout <<
"\n1. Creating poses using different constructors:" << std::endl;
48 std::cout <<
"Identity pose at origin:" << std::endl;
53 Eigen::Vector3d position(1.0, 2.0, 3.0);
54 Eigen::Quaterniond orientation(Eigen::AngleAxisd(M_PI / 4, Eigen::Vector3d::UnitZ()));
56 Pose pose_from_quat(position, orientation);
57 std::cout <<
"\nPose from position and quaternion:" << std::endl;
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;
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()));
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;
82 Pose pose_from_rotation(position, rotation);
83 std::cout <<
"\nPose from position and Rotation object:" << std::endl;
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);
93 Pose pose_from_homogeneous(homogeneous);
94 std::cout <<
"\nPose from homogeneous transformation matrix:" << std::endl;
99 std::cout <<
"\n2. Getting different representations of a pose:" << std::endl;
101 Pose example_pose(Eigen::Vector3d(1.0, 2.0, 3.0),
102 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 4, Eigen::Vector3d::UnitZ())));
105 std::cout <<
"Individual position components: x=" << example_pose.
getX()
106 <<
", y=" << example_pose.
getY() <<
", z=" << example_pose.
getZ() << std::endl;
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;
114 std::cout <<
"Rotation matrix:\n" << example_pose.
getRotationMatrix() << std::endl;
118 std::cout <<
"Affine transformation translation: [" << example_affine.translation().x() <<
", "
119 << example_affine.translation().y() <<
", " << example_affine.translation().z() <<
"]"
121 std::cout <<
"Affine transformation rotation:\n" << example_affine.rotation() << std::endl;
128 std::cout <<
"\n3. Modifying poses:" << std::endl;
130 Pose modifiable_pose;
131 std::cout <<
"Initial pose:" << std::endl;
136 modifiable_pose.
setPosition(Eigen::Vector3d(5.0, 6.0, 7.0));
140 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 3, Eigen::Vector3d::UnitY())));
142 std::cout <<
"\nAfter modification:" << std::endl;
147 Eigen::Matrix3d new_rotation =
148 Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitZ()).toRotationMatrix();
151 std::cout <<
"\nAfter setting rotation matrix:" << std::endl;
153 std::cout <<
"Rotation matrix:\n" << modifiable_pose.
getRotationMatrix() << std::endl;
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);
163 std::cout <<
"\nAfter setting homogeneous transformation:" << std::endl;
168 std::cout <<
"\n4. Pose operations:" << std::endl;
171 Pose pose1(Eigen::Vector3d(1.0, 0.0, 0.0),
172 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitZ())));
174 Pose pose2(Eigen::Vector3d(0.0, 1.0, 0.0),
175 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitZ())));
177 std::cout <<
"Pose 1:" << std::endl;
181 std::cout <<
"\nPose 2:" << std::endl;
186 Pose composed = pose1 * pose2;
187 std::cout <<
"\nComposed pose (pose1 * pose2):" << std::endl;
193 std::cout <<
"\nInverse of pose1:" << std::endl;
198 Pose identity_check = pose1 * inverse;
199 std::cout <<
"\nPose1 * Inverse (should be identity):" << std::endl;
204 std::cout <<
"\n5. Distance metrics:" << std::endl;
206 Pose pose_a(Eigen::Vector3d(1.0, 2.0, 3.0),
207 Eigen::Quaterniond(Eigen::AngleAxisd(0.0, Eigen::Vector3d::UnitZ())));
209 Pose pose_b(Eigen::Vector3d(4.0, 6.0, 8.0),
210 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 2, Eigen::Vector3d::UnitZ())));
215 std::cout <<
"Position distance: " << position_distance <<
" meters" << std::endl;
216 std::cout <<
"Orientation distance: " << orientation_distance <<
" radians ("
220 std::cout <<
"\n6. Coordinate transformations:" << std::endl;
224 Eigen::Vector3d(2.0, 3.0, 0.0),
225 Eigen::AngleAxisd(M_PI / 4, Eigen::Vector3d::UnitZ())
229 Eigen::Vector3d point_in_robot(1.0, 0.0, 0.0);
232 Eigen::Vector3d point_in_world = robot_in_world.
localToGlobal(point_in_robot);
234 std::cout <<
"Robot pose in world:" << std::endl;
236 std::cout <<
"Rotation: "
238 <<
"° around " << Eigen::AngleAxisd(robot_in_world.
getQuaternion()).axis().transpose()
241 std::cout <<
"\nPoint in robot's local frame: [" << point_in_robot.x() <<
", "
242 << point_in_robot.y() <<
", " << point_in_robot.z() <<
"]" << std::endl;
244 std::cout <<
"Same point in world frame: [" << point_in_world.x() <<
", " << point_in_world.y()
245 <<
", " << point_in_world.z() <<
"]" << std::endl;
248 Eigen::Vector3d point_back_in_robot = robot_in_world.
globalToLocal(point_in_world);
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;
255 Pose sensor_in_robot(
256 Eigen::Vector3d(0.0, 0.0, 0.5),
257 Eigen::AngleAxisd(0.0, Eigen::Vector3d::UnitZ())
263 std::cout <<
"\nSensor pose in robot frame:" << std::endl;
267 std::cout <<
"\nSensor pose in world frame:" << std::endl;
271 std::cout <<
"==============================================" << std::endl;