40 : m_translation{
std::move(translation)},
41 m_rotation{
std::move(rotation)} {}
52 constexpr Transform3d(wpi::units::meter_t x, wpi::units::meter_t y,
54 : m_translation{x, y, z}, m_rotation{
std::move(rotation)} {}
63 : m_translation{
Eigen::Vector3d{
64 {matrix(0, 3)}, {matrix(1, 3)}, {matrix(2, 3)}}},
66 Eigen::Matrix3d{{matrix(0, 0), matrix(0, 1), matrix(0, 2)},
67 {matrix(1, 0), matrix(1, 1), matrix(1, 2)},
68 {matrix(2, 0), matrix(2, 1), matrix(2, 2)}}} {
69 if (matrix(3, 0) != 0.0 || matrix(3, 1) != 0.0 || matrix(3, 2) != 0.0 ||
70 matrix(3, 3) != 1.0) {
71 throw std::domain_error(
"Affine transformation matrix is invalid");
103 constexpr wpi::units::meter_t
X()
const {
return m_translation.X(); }
110 constexpr wpi::units::meter_t
Y()
const {
return m_translation.Y(); }
117 constexpr wpi::units::meter_t
Z()
const {
return m_translation.Z(); }
124 auto vec = m_translation.ToVector();
125 auto mat = m_rotation.ToMatrix();
126 return Eigen::Matrix4d{{mat(0, 0), mat(0, 1), mat(0, 2), vec(0)},
127 {mat(1, 0), mat(1, 1), mat(1, 2), vec(1)},
128 {mat(2, 0), mat(2, 1), mat(2, 2), vec(2)},
129 {0.0, 0.0, 0.0, 1.0}};
167 return Transform3d(m_translation * scalar, m_rotation * scalar);
177 return *
this * (1.0 / scalar);
210 m_translation = (
final.Translation() - initial.
Translation())
213 m_rotation =
final.Rotation().RelativeTo(initial.
Rotation());
223 auto impl = [
this]<
typename Matrix3d,
typename Vector3d>() ->
Twist3d {
224 Vector3d u{{m_translation.X().value(), m_translation.Y().value(),
225 m_translation.Z().value()}};
226 Vector3d rvec = m_rotation.ToVector();
228 Matrix3d omegaSq = omega * omega;
229 double theta = rvec.norm();
230 double thetaSq = theta * theta;
245 C = 1 / 12.0 + thetaSq / 720 + thetaSq * thetaSq / 30240;
251 double B = (1 -
gcem::cos(theta)) / thetaSq;
252 C = (1 - A / (2 * B)) / thetaSq;
255 Matrix3d V_inv = Matrix3d::Identity() - 0.5 * omega + C * omegaSq;
257 Vector3d translation_component = V_inv * u;
259 return Twist3d{wpi::units::meter_t{translation_component(0)},
260 wpi::units::meter_t{translation_component(1)},
261 wpi::units::meter_t{translation_component(2)},
262 wpi::units::radian_t{rvec(0)},
263 wpi::units::radian_t{rvec(1)},
264 wpi::units::radian_t{rvec(2)}};
267 if (std::is_constant_evaluated()) {
270 return impl.template operator()<Eigen::Matrix3d, Eigen::Vector3d>();
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Represents a 3D pose containing translational and rotational elements.
Definition Pose3d.hpp:28
constexpr Pose3d TransformBy(const Transform3d &other) const
Transforms the pose by the given transformation and returns the new transformed pose.
Definition Pose3d.hpp:324
constexpr const Translation3d & Translation() const
Returns the underlying translation.
Definition Pose3d.hpp:120
constexpr const Rotation3d & Rotation() const
Returns the underlying rotation.
Definition Pose3d.hpp:148
A rotation in a 3D coordinate frame, represented by a quaternion.
Definition Rotation3d.hpp:69
constexpr Rotation3d Inverse() const
Takes the inverse of the current rotation.
Definition Rotation3d.hpp:290
Represents a translation in 3D space.
Definition Translation3d.hpp:31
Definition variable.hpp:916
constexpr T abs(const T x) noexcept
Compile-time absolute value function.
Definition abs.hpp:40
constexpr return_t< T > cos(const T x) noexcept
Compile-time cosine function.
Definition cos.hpp:83
constexpr return_t< T > sin(const T x) noexcept
Compile-time sine function.
Definition sin.hpp:85
Definition StringMap.hpp:773
Definition RobotBase.hpp:26
constexpr ct_matrix3d RotationVectorToMatrix(const ct_vector3d &rotation)
Definition RotationVectorToMatrix.hpp:13
Definition LinearSystem.hpp:20
ct_vector< double, 3 > ct_vector3d
Definition ct_matrix.hpp:387
ct_matrix< double, 3, 3 > ct_matrix3d
Definition ct_matrix.hpp:385
Definition CvSource.hpp:15
A change in distance along a 3D arc since the last pose update.
Definition Twist3d.hpp:23