15 #ifndef __RDL_SPATIALALGEBRAOPERATORS_H__ 16 #define __RDL_SPATIALALGEBRAOPERATORS_H__ 38 double sqw = q.
w() * q.
w();
39 double sqx = q.
x() * q.
x();
40 double sqy = q.
y() * q.
y();
41 double sqz = q.
z() * q.
z();
42 double unit = sqx + sqy + sqz + sqw;
43 double test = q.
w() * q.
y() - q.
z() * q.
x();
44 if (test > 0.499 * unit)
46 return Vector3d(yaw_at_pitch_singularity, M_PI_2, 2. * atan2(q.
x(), q.
y()) + yaw_at_pitch_singularity);
48 if (test < -0.499 * unit)
50 return Vector3d(yaw_at_pitch_singularity, -M_PI_2, 2. * atan2(q.
x(), q.
w()) - yaw_at_pitch_singularity);
53 return Vector3d(atan2(2. * (q.
w() * q.
z() + q.
x() * q.
y()), 1. - 2. * (sqy + sqz)), asin(2. * test / unit),
54 atan2(2. * (q.
w() * q.
x() + q.
y() * q.
z()), 1. - 2. * (sqx + sqy)));
65 double d = axis.norm();
66 double s2 = std::sin(angle_rad * 0.5) / d;
68 return Quaternion(axis[0] * s2, axis[1] * s2, axis[2] * s2, std::cos(angle_rad * 0.5));
76 return toQuaternion(axisAngle.axis(), axisAngle.angle());
134 double n = q.
vec().norm();
135 if (n < std::numeric_limits<double>::epsilon())
137 n = q.
vec().stableNorm();
143 axisAngle.angle() = 2.0 * atan2(n, q.
w());
144 axisAngle.axis() = q.
vec() / n;
148 axisAngle.angle() = 0.0;
149 axisAngle.axis() << 1.0, 0.0, 0.0;
160 double trace = mat.trace();
164 double s = 2. * std::sqrt(trace + 1.);
165 return Quaternion((mat(1, 2) - mat(2, 1)) / s, (mat(2, 0) - mat(0, 2)) / s, (mat(0, 1) - mat(1, 0)) / s, 0.25 * s);
167 else if ((mat(0, 0) > mat(1, 1)) && (mat(0, 0) > mat(2, 2)))
169 double s = 2. * std::sqrt(1. + mat(0, 0) - mat(1, 1) - mat(2, 2));
170 return Quaternion(-0.25 * s, (-mat(0, 1) - mat(1, 0)) / s, (-mat(0, 2) - mat(2, 0)) / s, (mat(2, 1) - mat(1, 2)) / s);
172 else if (mat(1, 1) > mat(2, 2))
174 double s = 2. * std::sqrt(1. + mat(1, 1) - mat(0, 0) - mat(2, 2));
175 return Quaternion((-mat(0, 1) - mat(1, 0)) / s, -0.25 * s, (-mat(1, 2) - mat(2, 1)) / s, (mat(0, 2) - mat(2, 0)) / s);
179 double s = 2. * std::sqrt(1. + mat(2, 2) - mat(0, 0) - mat(1, 1));
180 return Quaternion((-mat(0, 2) - mat(2, 0)) / s, (-mat(1, 2) - mat(2, 1)) / s, -0.25 * s, (mat(1, 0) - mat(0, 1)) / s);
194 return Matrix3d(1. - 2. * (y * y + z * z), 2. * x * y + 2. * w * z, 2. * x * z - 2. * w * y, 2. * x * y - 2. * w * z, 1. - 2. * (x * x + z * z),
195 2. * y * z + 2. * w * x, 2. * x * z + 2. * w * y, 2. * y * z - 2. * w * x, 1. - 2. * (x * x + y * y));
208 if (m(0, 2) < -0.999)
210 return Vector3d(yaw_at_pitch_singularity, M_PI_2, yaw_at_pitch_singularity + atan2(m(1, 0), m(1, 1)));
214 return Vector3d(yaw_at_pitch_singularity, -M_PI_2, -yaw_at_pitch_singularity + atan2(-m(1, 0), m(1, 1)));
217 return Vector3d(atan2(m(0, 1), m(0, 0)), asin(-m(0, 2)), atan2(m(1, 2), m(2, 2)));
229 return Matrix3d(0., -vector[2], vector[1], vector[2], 0., -vector[0], -vector[1], vector[0], 0.);
234 return Matrix3d(0., -z, y, z, 0., -x, -y, z, 0.);
239 output <<
"X.E = " << std::endl << X.
E << std::endl;
240 output <<
"X.r = " << X.
r.transpose();
257 return SpatialTransform(
Matrix3d(axis[0] * axis[0] * (1.0f - c) + c, axis[1] * axis[0] * (1.0f - c) + axis[2] * s, axis[0] * axis[2] * (1.0f - c) - axis[1] * s,
259 axis[0] * axis[1] * (1.0f - c) - axis[2] * s, axis[1] * axis[1] * (1.0f - c) + c, axis[1] * axis[2] * (1.0f - c) + axis[0] * s,
261 axis[0] * axis[2] * (1.0f - c) + axis[1] * s, axis[1] * axis[2] * (1.0f - c) - axis[0] * s, axis[2] * axis[2] * (1.0f - c) + c
278 return SpatialTransform(
Matrix3d(1., 0., 0., 0., c, s, 0., -s, c),
Vector3d(0., 0., 0.));
292 return SpatialTransform(
Matrix3d(c, 0., -s, 0., 1., 0., s, 0., c),
Vector3d(0., 0., 0.));
306 return SpatialTransform(
Matrix3d(c, s, 0., -s, c, 0., 0., 0., 1.),
Vector3d(0., 0., 0.));
329 return XeulerZYX(ypr[0], ypr[1], ypr[2]);
351 return XeulerXYZ(xyz_angles[0], xyz_angles[1], xyz_angles[2]);
381 return SpatialMatrix(0, -v[2], v[1], 0, 0, 0, v[2], 0, -v[0], 0, 0, 0, -v[1], v[0], 0, 0, 0, 0, 0, -v[5], v[4], 0, -v[2], v[1], v[5], 0, -v[3], v[2], 0, -v[0], -v[4],
382 v[3], 0, -v[1], v[0], 0);
393 return SpatialVector(-v1[2] * v2[1] + v1[1] * v2[2], v1[2] * v2[0] - v1[0] * v2[2], -v1[1] * v2[0] + v1[0] * v2[1],
394 -v1[5] * v2[1] + v1[4] * v2[2] - v1[2] * v2[4] + v1[1] * v2[5], v1[5] * v2[0] - v1[3] * v2[2] + v1[2] * v2[3] - v1[0] * v2[5],
395 -v1[4] * v2[0] + v1[3] * v2[1] - v1[1] * v2[3] + v1[0] * v2[4]);
405 return SpatialMatrix(0, -v[2], v[1], 0, -v[5], v[4], v[2], 0, -v[0], v[5], 0, -v[3], -v[1], v[0], 0, -v[4], v[3], 0, 0, 0, 0, 0, -v[2], v[1], 0, 0, 0, v[2], 0, -v[0],
406 0, 0, 0, -v[1], v[0], 0);
417 return SpatialVector(-v1[2] * v2[1] + v1[1] * v2[2] - v1[5] * v2[4] + v1[4] * v2[5], v1[2] * v2[0] - v1[0] * v2[2] + v1[5] * v2[3] - v1[3] * v2[5],
418 -v1[1] * v2[0] + v1[0] * v2[1] - v1[4] * v2[3] + v1[3] * v2[4], -v1[2] * v2[4] + v1[1] * v2[5], +v1[2] * v2[3] - v1[0] * v2[5],
419 -v1[1] * v2[3] + v1[0] * v2[4]);
430 double v_rxw_x = v[3] - X.
r[1] * v[2] + X.
r[2] * v[1];
431 double v_rxw_y = v[4] - X.
r[2] * v[0] + X.
r[0] * v[2];
432 double v_rxw_z = v[5] - X.
r[0] * v[1] + X.
r[1] * v[0];
434 return Vector3d(X.
E(0, 0) * v_rxw_x + X.
E(0, 1) * v_rxw_y + X.
E(0, 2) * v_rxw_z, X.
E(1, 0) * v_rxw_x + X.
E(1, 1) * v_rxw_y + X.
E(1, 2) * v_rxw_z,
435 X.
E(2, 0) * v_rxw_x + X.
E(2, 1) * v_rxw_y + X.
E(2, 2) * v_rxw_z);
443 #endif // ifndef __RDL_SPATIALALGEBRAOPERATORS_H__ static Vector3d toIntrinsicZYXAngles(const Quaternion &q, double yaw_at_pitch_singularity=0.)
Converte quaternion to intrinsic ZYX euler angles.
EIGEN_STRONG_INLINE double & w()
SpatialTransform XrotQuat(double x, double y, double z, double w)
EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(RobotDynamics::Joint)
static Quaternion intrinsicXYZAnglesToQuaternion(double roll, double pitch, double yaw)
Convert RPY angles to quaternion.
SpatialTransform Xroty(const double &yrot)
Get transform with zero translation and pure rotation about y axis.
SpatialMatrix crossf(const SpatialVector &v)
Get the spatial force cross matrix.
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
EIGEN_STRONG_INLINE Vector3d vec() const
Get vector part.
static Quaternion toQuaternion(const Vector3d &axis, double angle_rad)
Get quaternion representation of axis and angle.
static Matrix3d toTildeForm(const Point3d &p)
static Quaternion intrinsicYXZAnglesToQuaternion(double pitch, double roll, double yaw)
Convert PRY angles to quaternion.
Vector3d getLinearPartTransformed(const SpatialVector &v, const SpatialTransform &X)
Get the rotated linear portion of the spatial vector.
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
EIGEN_STRONG_INLINE double & y()
Quaternion that are used for singularity free joints.
std::ostream & operator<<(std::ostream &output, const FramePoint &framePoint)
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
EIGEN_STRONG_INLINE double & x()
SpatialTransform XeulerZYX(double yaw, double pitch, double roll)
Get transform with zero translation and intrinsic euler z/y/x rotation.
SpatialTransform XeulerXYZ(double roll, double pitch, double yaw)
Get transform with zero translation and intrinsic euler x/y/z rotation.
EIGEN_STRONG_INLINE double & z()
SpatialMatrix crossm(const SpatialVector &v)
Get the spatial motion cross matrix.
Eigen::AngleAxisd AxisAngle
static Quaternion intrinsicZYXAnglesToQuaternion(double yaw, double pitch, double roll)
Convert YPR angles to quaternion.
static Matrix3d toMatrix(const Quaternion &q)
Convert quaternion to rotation matrix.
Namespace for all structures of the RobotDynamics library.
SpatialTransform Xrot(double angle_rad, const Vector3d &axis)
Get spatial transform from angle and axis.
static AxisAngle toAxisAngle(Quaternion q)
Get axis angle representation of a quaternion.