[wpimath] Java: add static instantiations of common rotations (#6563)

C++ doesn't need this because it supports value types, which are much
cheaper to construct. constexpr is also available to make construction
zero-cost.
This commit is contained in:
Tyler Veness
2024-05-03 12:39:35 -07:00
committed by GitHub
parent 9c7120e6bf
commit e172aa66f7
75 changed files with 499 additions and 429 deletions

View File

@@ -181,7 +181,7 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea
* positive.
*/
public void driveCartesian(double xSpeed, double ySpeed, double zRotation) {
driveCartesian(xSpeed, ySpeed, zRotation, new Rotation2d());
driveCartesian(xSpeed, ySpeed, zRotation, Rotation2d.kZero);
}
/**
@@ -240,7 +240,7 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea
}
driveCartesian(
magnitude * angle.getCos(), magnitude * angle.getSin(), zRotation, new Rotation2d());
magnitude * angle.getCos(), magnitude * angle.getSin(), zRotation, Rotation2d.kZero);
}
/**
@@ -256,7 +256,7 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea
* @return Wheel speeds [-1.0..1.0].
*/
public static WheelSpeeds driveCartesianIK(double xSpeed, double ySpeed, double zRotation) {
return driveCartesianIK(xSpeed, ySpeed, zRotation, new Rotation2d());
return driveCartesianIK(xSpeed, ySpeed, zRotation, Rotation2d.kZero);
}
/**

View File

@@ -34,7 +34,7 @@ public class Field2d implements NTSendable, AutoCloseable {
@SuppressWarnings("this-escape")
public Field2d() {
FieldObject2d obj = new FieldObject2d("Robot");
obj.setPose(new Pose2d());
obj.setPose(Pose2d.kZero);
m_objects.add(obj);
SendableRegistry.add(this, "Field");
}

View File

@@ -59,7 +59,7 @@ public class FieldObject2d implements AutoCloseable {
public synchronized Pose2d getPose() {
updateFromEntry();
if (m_poses.isEmpty()) {
return new Pose2d();
return Pose2d.kZero;
}
return m_poses.get(0);
}