ros2---位姿转换--eigen/tf2
转换公式
转换代码--python
使用transforms3d库。
小鱼教程
检查和安装:
pip show transforms3d
pip install transforms3d -i https://pypi.tuna.tsinghua.edu.cn/simple
转换代码--c++
tf2
tf2::Quaternion
三种构造:
TF2_PUBLICQuaternion() {}// template <typename tf2Scalar>// explicit Quaternion(const tf2Scalar *v) : Tuple4<tf2Scalar>(v) {}/**@brief Constructor from scalars */TF2_PUBLICQuaternion(const tf2Scalar& x, const tf2Scalar& y, const tf2Scalar& z, const tf2Scalar& w) : QuadWord(x, y, z, w) {}/**@brief Axis angle Constructor* @param axis The axis which the rotation is around* @param angle The magnitude of the rotation around the angle (Radians) */TF2_PUBLICQuaternion(const Vector3& axis, const tf2Scalar& angle) { setRotation(axis, angle); }
轴角/欧拉角/RPY设置接口
轴角设置
/**@brief Set the rotation using axis angle notation * @param axis The axis around which to rotate* @param angle The magnitude of the rotation in Radians */TF2_PUBLICvoid setRotation(const Vector3& axis, const tf2Scalar& angle)
欧拉角设置
/**@brief Set the quaternion using Euler angles* @param yaw Angle around Y* @param pitch Angle around X* @param roll Angle around Z */TF2_PUBLICvoid setEuler(const tf2Scalar& yaw, const tf2Scalar& pitch, const tf2Scalar& roll)
上面是源码中的注释,但是xyz----rpy对应关系不对,不知为何。
RPY设置
/**@brief Set the quaternion using fixed axis RPY* @param roll Angle around X * @param pitch Angle around Y* @param yaw Angle around Z*/TF2_PUBLICvoid setRPY(const tf2Scalar& roll, const tf2Scalar& pitch, const tf2Scalar& yaw)