C++๋กœ ์ˆ˜ํ•™์  ํ‘œํ˜„์„ ๋‹ค๋ฃจ๋‹ค๋ณด๋ฉด ํ–‰๋ ฌ ํ‘œํ˜„์„ ํ”ผํ•  ์ˆ˜ ์—†๋‹ค
๋ณดํ†ต Eigen ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋งŽ์ด๋“ค ํ‘œํ˜„ํ•˜๋Š”๋ฐ, ์ด ๋•Œ Rotation๊ณผ Translation์ด ๋‹ด๊ธด Transformation matrix๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค.
๊ธฐ๋ณธ์ ์œผ๋กœ 4x4 ํ–‰๋ ฌ์ด๋ฉฐ ์ƒํ˜ธ ๋ณ€ํ™˜ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฒ•์„ ์•Œ์•„๋ณด์ž
๋”๋ถˆ์–ด Eigen์˜ block ๊ธฐ๋Šฅ์„ ์ด์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•ด๋ณธ๋‹ค


Geometry_msgs/Pose -> Eigen::Matrix4d

// Input : (geometry_msgs::Pose pose)
Eigen::Matrix4d xpose = Eigen::Matrix4d::Identity();
xpose.block<3,3>(0,0) = Eigen::Quaterniond(quat.w(), quat.x(), quat.y(), quat.z()).normalized().toRotationMatrix();
xpose.block<3,1>(0,3) = Eigen::Vector3d(pose.position.x, pose.position.y, pose.position.z);


๋ฐ˜๋Œ€๋กœ


Eigen::Matrix4d -> geometry_msgs/Pose

// Input : Eigen::Matrix4d xpose)
geometry_msgs::Pose pose;

Eigen::Quaterniond q(xpose.block<3, 3>(0, 0));
pose.orientation.x = q.x();
pose.orientation.y = q.y();
pose.orientation.z = q.z();
pose.orientation.w = q.w();

pose.position.x = xpose(0,3);
pose.position.y = xpose(1,3);
pose.position.z = xpose(2,3);

Reference

Leave a comment