8#include <initializer_list>
45 : m_translation{
std::move(translation)},
46 m_rotation{
std::move(rotation)} {}
57 constexpr Pose3d(wpi::units::meter_t x, wpi::units::meter_t y,
59 : m_translation{x, y, z}, m_rotation{
std::move(rotation)} {}
67 constexpr explicit Pose3d(
const Eigen::Matrix4d& matrix)
69 Eigen::Vector3d{{matrix(0, 3)}, {matrix(1, 3)}, {matrix(2, 3)}}},
71 Eigen::Matrix3d{{matrix(0, 0), matrix(0, 1), matrix(0, 2)},
72 {matrix(1, 0), matrix(1, 1), matrix(1, 2)},
73 {matrix(2, 0), matrix(2, 1), matrix(2, 2)}}} {
74 if (matrix(3, 0) != 0.0 || matrix(3, 1) != 0.0 || matrix(3, 2) != 0.0 ||
75 matrix(3, 3) != 1.0) {
76 throw std::domain_error(
"Affine transformation matrix is invalid");
88 : m_translation{pose.
X(), pose.
Y(), 0_m},
89 m_rotation{0_rad, 0_rad, pose.
Rotation().Radians()} {}
130 constexpr wpi::units::meter_t
X()
const {
return m_translation.X(); }
137 constexpr wpi::units::meter_t
Y()
const {
return m_translation.Y(); }
144 constexpr wpi::units::meter_t
Z()
const {
return m_translation.Z(); }
161 return Pose3d{m_translation * scalar, m_rotation * scalar};
172 return *
this * (1.0 / scalar);
184 return {m_translation.RotateBy(other), m_rotation.RotateBy(other)};
223 return {m_translation.RotateAround(point, rot), m_rotation.RotateBy(rot)};
230 auto vec = m_translation.ToVector();
231 auto mat = m_rotation.ToMatrix();
232 return Eigen::Matrix4d{{mat(0, 0), mat(0, 1), mat(0, 2), vec(0)},
233 {mat(1, 0), mat(1, 1), mat(1, 2), vec(1)},
234 {mat(2, 0), mat(2, 1), mat(2, 2), vec(2)},
235 {0.0, 0.0, 0.0, 1.0}};
242 return Pose2d{m_translation.X(), m_translation.Y(), m_rotation.Z()};
255 return *std::min_element(
256 poses.begin(), poses.end(), [
this](
const Pose3d& a,
const Pose3d& b) {
257 auto aDistance = this->Translation().Distance(a.Translation());
258 auto bDistance = this->Translation().Distance(b.Translation());
261 if (aDistance == bDistance) {
262 return gcem::abs(this->Rotation()
263 .RelativeTo(a.Rotation())
266 gcem::abs(this->Rotation()
267 .RelativeTo(b.Rotation())
271 return aDistance < bDistance;
285 return *std::min_element(
286 poses.begin(), poses.end(), [
this](
const Pose3d& a,
const Pose3d& b) {
287 auto aDistance = this->Translation().Distance(a.Translation());
288 auto bDistance = this->Translation().Distance(b.Translation());
291 if (aDistance == bDistance) {
292 return gcem::abs(this->Rotation()
293 .RelativeTo(a.Rotation())
296 gcem::abs(this->Rotation()
297 .RelativeTo(b.Rotation())
301 return aDistance < bDistance;
306 Translation3d m_translation;
307 Rotation3d m_rotation;
324 return Transform3d{pose.Translation(), pose.Rotation()};
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Represents a 2D pose containing translational and rotational elements.
Definition Pose2d.hpp:30
Represents a 3D pose containing translational and rotational elements.
Definition Pose3d.hpp:31
constexpr Pose3d operator*(double scalar) const
Multiplies the current pose by a scalar.
Definition Pose3d.hpp:160
constexpr Pose3d TransformBy(const Transform3d &other) const
Transforms the pose by the given transformation and returns the new transformed pose.
Definition Pose3d.hpp:327
constexpr Pose3d(Translation3d translation, Rotation3d rotation)
Constructs a pose with the specified translation and rotation.
Definition Pose3d.hpp:44
constexpr Pose3d(const Pose2d &pose)
Constructs a 3D pose from a 2D pose in the X-Y plane.
Definition Pose3d.hpp:87
constexpr Pose3d RotateBy(const Rotation3d &other) const
Rotates the pose around the origin and returns the new pose.
Definition Pose3d.hpp:183
constexpr Pose3d Nearest(std::initializer_list< Pose3d > poses) const
Returns the nearest Pose3d from a collection of poses.
Definition Pose3d.hpp:284
constexpr Pose3d Nearest(std::span< const Pose3d > poses) const
Returns the nearest Pose3d from a collection of poses.
Definition Pose3d.hpp:254
constexpr wpi::units::meter_t Z() const
Returns the Z component of the pose's translation.
Definition Pose3d.hpp:144
constexpr wpi::units::meter_t Y() const
Returns the Y component of the pose's translation.
Definition Pose3d.hpp:137
constexpr const Translation3d & Translation() const
Returns the underlying translation.
Definition Pose3d.hpp:123
constexpr Eigen::Matrix4d ToMatrix() const
Returns an affine transformation matrix representation of this pose.
Definition Pose3d.hpp:229
constexpr const Rotation3d & Rotation() const
Returns the underlying rotation.
Definition Pose3d.hpp:151
constexpr Pose3d operator+(const Transform3d &other) const
Transforms the pose by the given transformation and returns the new transformed pose.
Definition Pose3d.hpp:101
constexpr Pose2d ToPose2d() const
Returns a Pose2d representing this Pose3d projected into the X-Y plane.
Definition Pose3d.hpp:241
constexpr bool operator==(const Pose3d &) const =default
Checks equality between this Pose3d and another object.
constexpr wpi::units::meter_t X() const
Returns the X component of the pose's translation.
Definition Pose3d.hpp:130
constexpr Pose3d operator/(double scalar) const
Divides the current pose by a scalar.
Definition Pose3d.hpp:171
constexpr Pose3d()=default
Constructs a pose at the origin facing toward the positive X axis.
constexpr Pose3d RelativeTo(const Pose3d &other) const
Returns the current pose relative to the given pose.
Definition Pose3d.hpp:335
constexpr Transform3d operator-(const Pose3d &other) const
Returns the Transform3d that maps the one pose to another.
Definition Pose3d.hpp:322
constexpr Pose3d RotateAround(const Translation3d &point, const Rotation3d &rot) const
Rotates the current pose around a point in 3D space.
Definition Pose3d.hpp:221
constexpr Pose3d(const Eigen::Matrix4d &matrix)
Constructs a pose with the specified affine transformation matrix.
Definition Pose3d.hpp:67
constexpr Pose3d(wpi::units::meter_t x, wpi::units::meter_t y, wpi::units::meter_t z, Rotation3d rotation)
Constructs a pose with x, y, and z translations instead of a separate Translation3d.
Definition Pose3d.hpp:57
A rotation in a 3D coordinate frame, represented by a quaternion.
Definition Rotation3d.hpp:72
constexpr Rotation3d RotateBy(const Rotation3d &other) const
Adds the new rotation to the current rotation.
Definition Rotation3d.hpp:336
Represents a translation in 3D space.
Definition Translation3d.hpp:34
Definition variable.hpp:1006
Definition StringMap.hpp:773
Definition LinearSystem.hpp:20
WPILIB_DLLEXPORT void to_json(wpi::util::json &json, const Translation2d &state)
WPILIB_DLLEXPORT void from_json(const wpi::util::json &json, Translation2d &state)
Definition raw_os_ostream.hpp:19