mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpilib] Add X and Y component getters to Pose2d and Transform2d (#2563)
pose.Translation().X() and pose.Translation.Y() are common operations, so shortening them to pose.X() and pose.Y() would be convenient. Java uses the getX() convention so that is used instead of X() for Java.
This commit is contained in:
@@ -119,8 +119,8 @@ public class RamseteController {
|
||||
m_poseError = poseRef.relativeTo(currentPose);
|
||||
|
||||
// Aliases for equation readability
|
||||
final double eX = m_poseError.getTranslation().getX();
|
||||
final double eY = m_poseError.getTranslation().getY();
|
||||
final double eX = m_poseError.getX();
|
||||
final double eY = m_poseError.getY();
|
||||
final double eTheta = m_poseError.getRotation().getRadians();
|
||||
final double vRef = linearVelocityRefMeters;
|
||||
final double omegaRef = angularVelocityRefRadiansPerSecond;
|
||||
|
||||
@@ -96,6 +96,24 @@ public class Pose2d {
|
||||
return m_translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the X component of the pose's translation.
|
||||
*
|
||||
* @return The x component of the pose's translation.
|
||||
*/
|
||||
public double getX() {
|
||||
return m_translation.getX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Y component of the pose's translation.
|
||||
*
|
||||
* @return The y component of the pose's translation.
|
||||
*/
|
||||
public double getY() {
|
||||
return m_translation.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rotational component of the transformation.
|
||||
*
|
||||
|
||||
@@ -70,6 +70,24 @@ public class Transform2d {
|
||||
return m_translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the X component of the transformation's translation.
|
||||
*
|
||||
* @return The x component of the transformation's translation.
|
||||
*/
|
||||
public double getX() {
|
||||
return m_translation.getX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Y component of the transformation's translation.
|
||||
*
|
||||
* @return The y component of the transformation's translation.
|
||||
*/
|
||||
public double getY() {
|
||||
return m_translation.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rotational component of the transformation.
|
||||
*
|
||||
|
||||
@@ -263,15 +263,15 @@ public final class SplineHelper {
|
||||
|
||||
private static Spline.ControlVector getCubicControlVector(double scalar, Pose2d point) {
|
||||
return new Spline.ControlVector(
|
||||
new double[]{point.getTranslation().getX(), scalar * point.getRotation().getCos()},
|
||||
new double[]{point.getTranslation().getY(), scalar * point.getRotation().getSin()}
|
||||
new double[]{point.getX(), scalar * point.getRotation().getCos()},
|
||||
new double[]{point.getY(), scalar * point.getRotation().getSin()}
|
||||
);
|
||||
}
|
||||
|
||||
private static Spline.ControlVector getQuinticControlVector(double scalar, Pose2d point) {
|
||||
return new Spline.ControlVector(
|
||||
new double[]{point.getTranslation().getX(), scalar * point.getRotation().getCos(), 0.0},
|
||||
new double[]{point.getTranslation().getY(), scalar * point.getRotation().getSin(), 0.0}
|
||||
new double[]{point.getX(), scalar * point.getRotation().getCos(), 0.0},
|
||||
new double[]{point.getY(), scalar * point.getRotation().getSin(), 0.0}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ public class EllipticalRegionConstraint implements TrajectoryConstraint {
|
||||
// If the inequality is satisfied, then it is inside the ellipse; otherwise
|
||||
// it is outside the ellipse.
|
||||
// Both sides have been multiplied by Rx^2 * Ry^2 for efficiency reasons.
|
||||
return Math.pow(robotPose.getTranslation().getX() - m_center.getX(), 2)
|
||||
return Math.pow(robotPose.getX() - m_center.getX(), 2)
|
||||
* Math.pow(m_radii.getY(), 2)
|
||||
+ Math.pow(robotPose.getTranslation().getY() - m_center.getY(), 2)
|
||||
+ Math.pow(robotPose.getY() - m_center.getY(), 2)
|
||||
* Math.pow(m_radii.getX(), 2) <= Math.pow(m_radii.getX(), 2) * Math.pow(m_radii.getY(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +65,9 @@ public class RectangularRegionConstraint implements TrajectoryConstraint {
|
||||
* @return Whether the robot pose is within the constraint region.
|
||||
*/
|
||||
public boolean isPoseInRegion(Pose2d robotPose) {
|
||||
return robotPose.getTranslation().getX() >= m_bottomLeftPoint.getX()
|
||||
&& robotPose.getTranslation().getX() <= m_topRightPoint.getX()
|
||||
&& robotPose.getTranslation().getY() >= m_bottomLeftPoint.getY()
|
||||
&& robotPose.getTranslation().getY() <= m_topRightPoint.getY();
|
||||
return robotPose.getX() >= m_bottomLeftPoint.getX()
|
||||
&& robotPose.getX() <= m_topRightPoint.getX()
|
||||
&& robotPose.getY() >= m_bottomLeftPoint.getY()
|
||||
&& robotPose.getY() <= m_topRightPoint.getY();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user