Package edu.wpi.first.math.geometry
Class Pose2d
java.lang.Object
edu.wpi.first.math.geometry.Pose2d
- All Implemented Interfaces:
Interpolatable<Pose2d>
,ProtobufSerializable
,StructSerializable
,WPISerializable
public class Pose2d
extends Object
implements Interpolatable<Pose2d>, ProtobufSerializable, StructSerializable
Represents a 2D pose containing translational and rotational elements.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Pose2d
A preallocated Pose2d representing the origin.static final Pose2dProto
Pose2d protobuf for serialization.static final Pose2dStruct
Pose2d struct for serialization. -
Constructor Summary
ConstructorDescriptionPose2d()
Constructs a pose at the origin facing toward the positive X axis.Pose2d
(double x, double y, Rotation2d rotation) Constructs a pose with x and y translations instead of a separate Translation2d.Pose2d
(Translation2d translation, Rotation2d rotation) Constructs a pose with the specified translation and rotation.Constructs a pose with the specified affine transformation matrix.Pose2d
(Distance x, Distance y, Rotation2d rotation) Constructs a pose with x and y translations instead of a separate Translation2d. -
Method Summary
Modifier and TypeMethodDescriptiondiv
(double scalar) Divides the current pose by a scalar.boolean
Checks equality between this Pose2d and another object.Obtain a new Pose2d from a (constant curvature) velocity.Returns the X component of the pose's translation in a measure.Returns the Y component of the pose's translation in a measure.Returns the rotational component of the transformation.Returns the translation component of the transformation.double
getX()
Returns the X component of the pose's translation.double
getY()
Returns the Y component of the pose's translation.int
hashCode()
interpolate
(Pose2d endValue, double t) Return the interpolated value.Returns a Twist2d that maps this pose to the end pose.Returns the Transform2d that maps the one pose to another.Returns the nearest Pose2d from a list of poses.plus
(Transform2d other) Transforms the pose by the given transformation and returns the new transformed pose.relativeTo
(Pose2d other) Returns the current pose relative to the given pose.rotateBy
(Rotation2d other) Rotates the pose around the origin and returns the new pose.times
(double scalar) Multiplies the current pose by a scalar.toMatrix()
Returns an affine transformation matrix representation of this pose.toString()
transformBy
(Transform2d other) Transforms the pose by the given transformation and returns the new pose.
-
Field Details
-
kZero
A preallocated Pose2d representing the origin.This exists to avoid allocations for common poses.
-
proto
Pose2d protobuf for serialization. -
struct
Pose2d struct for serialization.
-
-
Constructor Details
-
Pose2d
public Pose2d()Constructs a pose at the origin facing toward the positive X axis. -
Pose2d
Constructs a pose with the specified translation and rotation.- Parameters:
translation
- The translational component of the pose.rotation
- The rotational component of the pose.
-
Pose2d
Constructs a pose with x and y translations instead of a separate Translation2d.- Parameters:
x
- The x component of the translational component of the pose.y
- The y component of the translational component of the pose.rotation
- The rotational component of the pose.
-
Pose2d
Constructs a pose with x and y translations instead of a separate Translation2d. The X and Y translations will be converted to and tracked as meters.- Parameters:
x
- The x component of the translational component of the pose.y
- The y component of the translational component of the pose.rotation
- The rotational component of the pose.
-
Pose2d
Constructs a pose with the specified affine transformation matrix.- Parameters:
matrix
- The affine transformation matrix.- Throws:
IllegalArgumentException
- if the affine transformation matrix is invalid.
-
-
Method Details
-
plus
Transforms the pose by the given transformation and returns the new transformed pose.[x_new] [cos, -sin, 0][transform.x] [y_new] += [sin, cos, 0][transform.y] [t_new] [ 0, 0, 1][transform.t]
- Parameters:
other
- The transform to transform the pose by.- Returns:
- The transformed pose.
-
minus
Returns the Transform2d that maps the one pose to another.- Parameters:
other
- The initial pose of the transformation.- Returns:
- The transform that maps the other pose to the current pose.
-
getTranslation
Returns the translation component of the transformation.- Returns:
- The translational component of the pose.
-
getX
Returns the X component of the pose's translation.- Returns:
- The x component of the pose's translation.
-
getY
Returns the Y component of the pose's translation.- Returns:
- The y component of the pose's translation.
-
getMeasureX
Returns the X component of the pose's translation in a measure.- Returns:
- The x component of the pose's translation in a measure.
-
getMeasureY
Returns the Y component of the pose's translation in a measure.- Returns:
- The y component of the pose's translation in a measure.
-
getRotation
Returns the rotational component of the transformation.- Returns:
- The rotational component of the pose.
-
times
Multiplies the current pose by a scalar.- Parameters:
scalar
- The scalar.- Returns:
- The new scaled Pose2d.
-
div
Divides the current pose by a scalar.- Parameters:
scalar
- The scalar.- Returns:
- The new scaled Pose2d.
-
rotateBy
Rotates the pose around the origin and returns the new pose.- Parameters:
other
- The rotation to transform the pose by.- Returns:
- The transformed pose.
-
transformBy
Transforms the pose by the given transformation and returns the new pose. See + operator for the matrix multiplication performed.- Parameters:
other
- The transform to transform the pose by.- Returns:
- The transformed pose.
-
relativeTo
Returns the current pose relative to the given pose.This function can often be used for trajectory tracking or pose stabilization algorithms to get the error between the reference and the current pose.
- Parameters:
other
- The pose that is the origin of the new coordinate frame that the current pose will be converted into.- Returns:
- The current pose relative to the new origin pose.
-
exp
Obtain a new Pose2d from a (constant curvature) velocity.See Controls Engineering in the FIRST Robotics Competition section 10.2 "Pose exponential" for a derivation.
The twist is a change in pose in the robot's coordinate frame since the previous pose update. When the user runs exp() on the previous known field-relative pose with the argument being the twist, the user will receive the new field-relative pose.
"Exp" represents the pose exponential, which is solving a differential equation moving the pose forward in time.
- Parameters:
twist
- The change in pose in the robot's coordinate frame since the previous pose update. For example, if a non-holonomic robot moves forward 0.01 meters and changes angle by 0.5 degrees since the previous pose update, the twist would be Twist2d(0.01, 0.0, Units.degreesToRadians(0.5)).- Returns:
- The new pose of the robot.
-
log
Returns a Twist2d that maps this pose to the end pose. If c is the output ofa.Log(b)
, thena.Exp(c)
would yield b.- Parameters:
end
- The end pose for the transformation.- Returns:
- The twist that maps this to end.
-
toMatrix
Returns an affine transformation matrix representation of this pose.- Returns:
- An affine transformation matrix representation of this pose.
-
nearest
Returns the nearest Pose2d from a list of poses. If two or more poses in the list have the same distance from this pose, return the one with the closest rotation component.- Parameters:
poses
- The list of poses to find the nearest.- Returns:
- The nearest Pose2d from the list.
-
toString
-
equals
Checks equality between this Pose2d and another object. -
hashCode
-
interpolate
Description copied from interface:Interpolatable
Return the interpolated value. This object is assumed to be the starting position, or lower bound.- Specified by:
interpolate
in interfaceInterpolatable<Pose2d>
- Parameters:
endValue
- The upper bound, or end.t
- How far between the lower and upper bound we are. This should be bounded in [0, 1].- Returns:
- The interpolated value.
-