From d796d5a10270a5db835d46944e730fe4edfed522 Mon Sep 17 00:00:00 2001 From: Yishai Levy <96019039+levyishai@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:25:00 +0200 Subject: [PATCH 1/3] Remade mirrorable as flippable --- .../Flippable.java} | 49 +++++++------- .../utilities/flippable/FlippablePose2d.java | 60 +++++++++++++++++ .../flippable/FlippableRotation2d.java | 67 +++++++++++++++++++ .../flippable/FlippableTranslation2d.java | 36 ++++++++++ .../flippable/FlippableTranslation3d.java | 39 +++++++++++ .../mirrorable/MirrorablePose2d.java | 55 --------------- .../mirrorable/MirrorableRotation2d.java | 60 ----------------- .../mirrorable/MirrorableTranslation3d.java | 39 ----------- 8 files changed, 226 insertions(+), 179 deletions(-) rename src/main/java/org/trigon/utilities/{mirrorable/Mirrorable.java => flippable/Flippable.java} (51%) create mode 100644 src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java create mode 100644 src/main/java/org/trigon/utilities/flippable/FlippableRotation2d.java create mode 100644 src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java create mode 100644 src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java delete mode 100644 src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java delete mode 100644 src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java delete mode 100644 src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/flippable/Flippable.java similarity index 51% rename from src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java rename to src/main/java/org/trigon/utilities/flippable/Flippable.java index 4046f13c..15bc2c82 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/flippable/Flippable.java @@ -1,6 +1,5 @@ -package org.trigon.utilities.mirrorable; +package org.trigon.utilities.flippable; -import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj2.command.Command; @@ -10,22 +9,22 @@ import java.util.Optional; /** - * A class that allows for objects to be mirrored across the center of the field when the robot is on the red alliance. - * This is useful for placing field elements and other objects that are mirrored across the field, or for mirroring the target heading to face a field element. + * A class that allows for objects to be flipped across the center of the field when the robot is on the red alliance. + * This is useful for placing field elements and other objects that are flipped across the field, or for flipping the target heading to face a field element. + * This either represents a field that is mirrored vertically over the center of the field, or a field that is rotationally symmetric: the red alliance side is the blue alliance side rotated by 180 degrees. + * The code will automatically determine which type of field the robot is on and flip the object accordingly. * - * @param the type of object to mirror + * @param the type of object to flip */ -public abstract class Mirrorable { - protected static final Rotation2d HALF_ROTATION = new Rotation2d(Math.PI); - protected static final double FIELD_LENGTH_METERS = 16.54175; +public abstract class Flippable { private static final Timer UPDATE_ALLIANCE_TIMER = new Timer(); private static boolean IS_RED_ALLIANCE = notCachedIsRedAlliance(); - protected final T nonMirroredObject, mirroredObject; + protected final T nonFlippedObject, flippedObject; - protected final boolean shouldMirrorWhenRedAlliance; + protected final boolean shouldFlipWhenRedAlliance; /** - * Initializes the mirrorable class. This should be called once in RobotContainer. + * Initializes the Flippable class. This should be called once in RobotContainer. */ public static void init() { UPDATE_ALLIANCE_TIMER.start(); @@ -57,32 +56,32 @@ private static boolean notCachedIsRedAlliance() { } /** - * Creates a new mirrorable object. + * Creates a new Flippable object. * - * @param nonMirroredObject the object when the robot is on the blue alliance, or the non-mirrored object - * @param shouldMirrorWhenRedAlliance should the object should be mirrored when the robot is on the red alliance + * @param nonFlippedObject the object when the robot is on the blue alliance; the non-flipped object + * @param shouldFlipWhenRedAlliance should the object should be flipped when the robot is on the red alliance */ - protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { - this.nonMirroredObject = nonMirroredObject; - this.mirroredObject = mirror(nonMirroredObject); - this.shouldMirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; + protected Flippable(T nonFlippedObject, boolean shouldFlipWhenRedAlliance) { + this.nonFlippedObject = nonFlippedObject; + this.flippedObject = flip(nonFlippedObject); + this.shouldFlipWhenRedAlliance = shouldFlipWhenRedAlliance; } /** - * If the robot is on the red alliance and the object should be mirrored, the mirrored object is returned. - * Otherwise, the non-mirrored object is returned. + * If the robot is on the red alliance and the object should be flipped, the flipped object is returned. + * Otherwise, the non-flipped object is returned. * * @return the current object */ public T get() { - return isRedAlliance() && shouldMirrorWhenRedAlliance ? mirroredObject : nonMirroredObject; + return isRedAlliance() && shouldFlipWhenRedAlliance ? flippedObject : nonFlippedObject; } /** - * Mirrors the object across the center of the field. + * Flips the object across the center of the field. * - * @param object the object to mirror - * @return the mirrored object + * @param object the object to flip + * @return the flipped object */ - protected abstract T mirror(T object); + protected abstract T flip(T object); } \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java b/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java new file mode 100644 index 00000000..f21aa3b3 --- /dev/null +++ b/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java @@ -0,0 +1,60 @@ +package org.trigon.utilities.flippable; + +import com.pathplanner.lib.util.FlippingUtil; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; + +/** + * A class that represents a {@link Pose2d} that can be flipped when the robot is on the red alliance. + */ +public class FlippablePose2d extends Flippable { + + + /** + * Creates a new FlippablePose2d with the given x, y, and rotation. + * + * @param nonFlippedPose the pose when the robot is on the blue alliance + * @param shouldFlipWhenRedAlliance should the pose be flipped when the robot is on the red alliance + */ + public FlippablePose2d(Pose2d nonFlippedPose, boolean shouldFlipWhenRedAlliance) { + super(nonFlippedPose, shouldFlipWhenRedAlliance); + } + + /** + * Creates a new FlippablePose2d with the given x, y, and rotation. + * + * @param x the x value of the pose + * @param y the y value of the pose + * @param rotation the rotation of the pose + * @param shouldFlipWhenRedAlliance should the pose be flipped when the robot is on the red alliance + */ + public FlippablePose2d(double x, double y, Rotation2d rotation, boolean shouldFlipWhenRedAlliance) { + this(new Pose2d(x, y, rotation), shouldFlipWhenRedAlliance); + } + + /** + * Creates a new FlippablePose2d with the given translation and rotation. + * + * @param translation2d the translation of the pose. + * @param rotation the rotation of the pose. + * @param shouldFlipWhenRedAlliance should the pose be flipped when the robot is on the red alliance + */ + public FlippablePose2d(Translation2d translation2d, double rotation, boolean shouldFlipWhenRedAlliance) { + this(new Pose2d(translation2d, new Rotation2d(rotation)), shouldFlipWhenRedAlliance); + } + + /** + * Gets the rotation value of the pose. The pose will be flipped if the robot is on the red alliance and {@link #shouldFlipWhenRedAlliance} is true. + * + * @return the rotation value of the pose. + */ + public FlippableRotation2d getRotation() { + return new FlippableRotation2d(nonFlippedObject.getRotation(), shouldFlipWhenRedAlliance); + } + + @Override + protected Pose2d flip(Pose2d pose) { + return FlippingUtil.flipFieldPose(pose); + } +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/flippable/FlippableRotation2d.java b/src/main/java/org/trigon/utilities/flippable/FlippableRotation2d.java new file mode 100644 index 00000000..d639b3a9 --- /dev/null +++ b/src/main/java/org/trigon/utilities/flippable/FlippableRotation2d.java @@ -0,0 +1,67 @@ +package org.trigon.utilities.flippable; + +import com.pathplanner.lib.util.FlippingUtil; +import edu.wpi.first.math.geometry.Rotation2d; + +/** + * A class that represents a {@link Rotation2d} that can be flipped when the robot is on the red alliance. + */ +public class FlippableRotation2d extends Flippable { + /** + * Creates a new FlippableRotation2d with the given Rotation2d. + * + * @param nonFlippedRotation the non flipped rotation when the robot is on the blue alliance + * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance + */ + public FlippableRotation2d(Rotation2d nonFlippedRotation, boolean shouldFlipWhenRedAlliance) { + super(nonFlippedRotation, shouldFlipWhenRedAlliance); + } + + /** + * Creates a new FlippableRotation2d with the given rotation value. + * + * @param radians the value of the angle in radians + * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance + */ + public FlippableRotation2d(double radians, boolean shouldFlipWhenRedAlliance) { + this(new Rotation2d(radians), shouldFlipWhenRedAlliance); + } + + /** + * Constructs and returns a FlippableRotation2d with the given degree value. + * + * @param degrees the value of the angle in degrees + * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance + * @return the rotation object with the desired angle value + */ + public static FlippableRotation2d fromDegrees(double degrees, boolean shouldFlipWhenRedAlliance) { + return new FlippableRotation2d(Rotation2d.fromDegrees(degrees), shouldFlipWhenRedAlliance); + } + + /** + * Constructs and returns a FlippableRotation2d with the given radian value. + * + * @param radians the value of the angle in radians + * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance + * @return the rotation object with the desired angle value + */ + public static FlippableRotation2d fromRadians(double radians, boolean shouldFlipWhenRedAlliance) { + return new FlippableRotation2d(Rotation2d.fromRadians(radians), shouldFlipWhenRedAlliance); + } + + /** + * Constructs a FlippableRotation2d with the given number of rotations. + * + * @param rotations the value of the angle in rotations + * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance + * @return the rotation object with the desired angle value + */ + public static FlippableRotation2d fromRotations(double rotations, boolean shouldFlipWhenRedAlliance) { + return new FlippableRotation2d(Rotation2d.fromRotations(rotations), shouldFlipWhenRedAlliance); + } + + @Override + protected Rotation2d flip(Rotation2d rotation) { + return FlippingUtil.flipFieldRotation(rotation); + } +} diff --git a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java new file mode 100644 index 00000000..505229e0 --- /dev/null +++ b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java @@ -0,0 +1,36 @@ +package org.trigon.utilities.flippable; + +import com.pathplanner.lib.util.FlippingUtil; +import edu.wpi.first.math.geometry.Translation2d; + +/** + * A class that represents a {@link Translation2d} that can be flipped when the robot is on the red alliance. + */ +public class FlippableTranslation2d extends Flippable { + /** + * Creates a new FlippableTranslation3d with the given translation. + * + * @param nonFlippedTranslation the translation to flip + * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance + */ + public FlippableTranslation2d(Translation2d nonFlippedTranslation, boolean shouldFlipWhenRedAlliance) { + super(nonFlippedTranslation, shouldFlipWhenRedAlliance); + } + + + /** + * Creates a new FlippableTranslation3d with the given x and y values. + * + * @param x the x value of the translation + * @param y the y value of the translation + * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance + */ + public FlippableTranslation2d(double x, double y, boolean shouldFlipWhenRedAlliance) { + this(new Translation2d(x, y), shouldFlipWhenRedAlliance); + } + + @Override + protected Translation2d flip(Translation2d translation) { + return FlippingUtil.flipFieldPosition(translation); + } +} diff --git a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java new file mode 100644 index 00000000..1312de5e --- /dev/null +++ b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java @@ -0,0 +1,39 @@ +package org.trigon.utilities.flippable; + +import com.pathplanner.lib.util.FlippingUtil; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.geometry.Translation3d; + +/** + * A class that represents a {@link Translation3d} that can be flipped when the robot is on the red alliance. + * The Z value will have no change. + */ +public class FlippableTranslation3d extends Flippable { + /** + * Creates a new FlippableTranslation3d with the given translation. + * + * @param nonFlippedTranslation the translation to flip + * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance + */ + public FlippableTranslation3d(Translation3d nonFlippedTranslation, boolean shouldFlipWhenRedAlliance) { + super(nonFlippedTranslation, shouldFlipWhenRedAlliance); + } + + /** + * Creates a new FlippableTranslation3d with the given x, y, and z values. + * + * @param x the x value of the translation + * @param y the y value of the translation + * @param z the z value of the translation + * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance + */ + public FlippableTranslation3d(double x, double y, double z, boolean shouldFlipWhenRedAlliance) { + this(new Translation3d(x, y, z), shouldFlipWhenRedAlliance); + } + + @Override + protected Translation3d flip(Translation3d translation) { + final Translation2d flippedTranslation2d = FlippingUtil.flipFieldPosition(translation.toTranslation2d()); + return new Translation3d(flippedTranslation2d.getX(), flippedTranslation2d.getY(), translation.getZ()); + } +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java deleted file mode 100644 index 952e40e8..00000000 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.trigon.utilities.mirrorable; - -import edu.wpi.first.math.geometry.Pose2d; -import edu.wpi.first.math.geometry.Rotation2d; -import edu.wpi.first.math.geometry.Translation2d; - -/** - * A class that represents a {@link Pose2d} that can be mirrored, reversing its position and orientation across the center of the field when the robot is on the red alliance. - */ -public class MirrorablePose2d extends Mirrorable { - public MirrorablePose2d(Pose2d nonMirroredPose, boolean shouldMirrorWhenRedAlliance) { - super(nonMirroredPose, shouldMirrorWhenRedAlliance); - } - - /** - * Creates a new MirrorablePose2d with the given x, y, and rotation. - * - * @param x the x value of the pose. - * @param y the y value of the pose. - * @param rotation the rotation of the pose. - * @param shouldMirrorWhenRedAlliance should the pose be mirrored when the robot is on the red alliance - */ - public MirrorablePose2d(double x, double y, Rotation2d rotation, boolean shouldMirrorWhenRedAlliance) { - this(new Pose2d(x, y, rotation), shouldMirrorWhenRedAlliance); - } - - /** - * Creates a new MirrorablePose2d with the given translation and rotation. - * - * @param translation2d the translation of the pose. - * @param rotation the rotation of the pose. - * @param shouldMirrorWhenRedAlliance should the pose be mirrored when the robot is on the red alliance - */ - public MirrorablePose2d(Translation2d translation2d, double rotation, boolean shouldMirrorWhenRedAlliance) { - this(new Pose2d(translation2d, new Rotation2d(rotation)), shouldMirrorWhenRedAlliance); - } - - /** - * Gets the rotation value of the pose. The pose will be mirrored if the robot is on the red alliance and {@link #shouldMirrorWhenRedAlliance} is true. - * - * @return the rotation value of the pose. - */ - public MirrorableRotation2d getRotation() { - return new MirrorableRotation2d(nonMirroredObject.getRotation(), shouldMirrorWhenRedAlliance); - } - - @Override - protected Pose2d mirror(Pose2d pose) { - return new Pose2d( - FIELD_LENGTH_METERS - pose.getX(), - pose.getY(), - HALF_ROTATION.minus(pose.getRotation()) - ); - } -} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java deleted file mode 100644 index 8227901b..00000000 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.trigon.utilities.mirrorable; - -import edu.wpi.first.math.geometry.Rotation2d; - -/** - * A class that represents a {@link Rotation2d} that can be mirrored, reversing its orientation across the center of the field when the robot is on the red alliance. - */ -public class MirrorableRotation2d extends Mirrorable { - public MirrorableRotation2d(Rotation2d nonMirroredRotation, boolean shouldMirrorWhenRedAlliance) { - super(nonMirroredRotation, shouldMirrorWhenRedAlliance); - } - - /** - * Creates a new MirrorableRotation2d with the given rotation value. - * - * @param radians the value of the angle in radians - * @param shouldMirrorWhenRedAlliance should the rotation be mirrored when the robot is on the red alliance - */ - public MirrorableRotation2d(double radians, boolean shouldMirrorWhenRedAlliance) { - this(new Rotation2d(radians), shouldMirrorWhenRedAlliance); - } - - /** - * Constructs and returns a MirrorableRotation2d with the given degree value. - * - * @param degrees the value of the angle in degrees - * @param shouldMirrorWhenRedAlliance should the rotation be mirrored when the robot is on the red alliance - * @return the rotation object with the desired angle value - */ - public static MirrorableRotation2d fromDegrees(double degrees, boolean shouldMirrorWhenRedAlliance) { - return new MirrorableRotation2d(Rotation2d.fromDegrees(degrees), shouldMirrorWhenRedAlliance); - } - - /** - * Constructs and returns a MirrorableRotation2d with the given radian value. - * - * @param radians the value of the angle in radians - * @param shouldMirrorWhenRedAlliance should the rotation be mirrored when the robot is on the red alliance - * @return the rotation object with the desired angle value - */ - public static MirrorableRotation2d fromRadians(double radians, boolean shouldMirrorWhenRedAlliance) { - return new MirrorableRotation2d(Rotation2d.fromRadians(radians), shouldMirrorWhenRedAlliance); - } - - /** - * Constructs and returns a MirrorableRotation2d with the given number of rotations. - * - * @param rotations the value of the angle in rotations - * @param shouldMirrorWhenRedAlliance should the rotation be mirrored when the robot is on the red alliance - * @return the rotation object with the desired angle value - */ - public static MirrorableRotation2d fromRotations(double rotations, boolean shouldMirrorWhenRedAlliance) { - return new MirrorableRotation2d(Rotation2d.fromRotations(rotations), shouldMirrorWhenRedAlliance); - } - - @Override - protected Rotation2d mirror(Rotation2d rotation) { - return HALF_ROTATION.minus(rotation); - } -} diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java deleted file mode 100644 index 122ae60c..00000000 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.trigon.utilities.mirrorable; - -import edu.wpi.first.math.geometry.Translation3d; - -/** - * A class that represents a {@link Translation3d} that can be mirrored by reversing its position across the center of the field when the robot is on the red alliance. - */ -public class MirrorableTranslation3d extends Mirrorable { - /** - * Creates a new MirrorableTranslation3d with the given translation. - * - * @param nonMirroredTranslation the translation to mirror - * @param shouldMirrorWhenRedAlliance should the position be mirrored when the robot is on the red alliance - */ - public MirrorableTranslation3d(Translation3d nonMirroredTranslation, boolean shouldMirrorWhenRedAlliance) { - super(nonMirroredTranslation, shouldMirrorWhenRedAlliance); - } - - /** - * Creates a new MirrorableTranslation3d with the given x, y, and z values. - * - * @param x the x value of the translation - * @param y the y value of the translation - * @param z the z value of the translation - * @param shouldMirrorWhenRedAlliance should the position be mirrored when the robot is on the red alliance - */ - public MirrorableTranslation3d(double x, double y, double z, boolean shouldMirrorWhenRedAlliance) { - this(new Translation3d(x, y, z), shouldMirrorWhenRedAlliance); - } - - @Override - protected Translation3d mirror(Translation3d translation) { - return new Translation3d( - FIELD_LENGTH_METERS - translation.getX(), - translation.getY(), - translation.getZ() - ); - } -} \ No newline at end of file From d3fd8d5e54237573afd19223bbe4e9520ba2a231 Mon Sep 17 00:00:00 2001 From: Yishai Levy <96019039+levyishai@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:43:56 +0200 Subject: [PATCH 2/3] Formatted --- .../utilities/flippable/FlippablePose2d.java | 22 +++++----- .../flippable/FlippableRotation2d.java | 40 +++++++++---------- .../flippable/FlippableTranslation2d.java | 21 +++++----- .../flippable/FlippableTranslation3d.java | 20 +++++----- 4 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java b/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java index f21aa3b3..52c53701 100644 --- a/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java +++ b/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java @@ -9,18 +9,6 @@ * A class that represents a {@link Pose2d} that can be flipped when the robot is on the red alliance. */ public class FlippablePose2d extends Flippable { - - - /** - * Creates a new FlippablePose2d with the given x, y, and rotation. - * - * @param nonFlippedPose the pose when the robot is on the blue alliance - * @param shouldFlipWhenRedAlliance should the pose be flipped when the robot is on the red alliance - */ - public FlippablePose2d(Pose2d nonFlippedPose, boolean shouldFlipWhenRedAlliance) { - super(nonFlippedPose, shouldFlipWhenRedAlliance); - } - /** * Creates a new FlippablePose2d with the given x, y, and rotation. * @@ -44,6 +32,16 @@ public FlippablePose2d(Translation2d translation2d, double rotation, boolean sho this(new Pose2d(translation2d, new Rotation2d(rotation)), shouldFlipWhenRedAlliance); } + /** + * Creates a new FlippablePose2d with the given x, y, and rotation. + * + * @param nonFlippedPose the pose when the robot is on the blue alliance + * @param shouldFlipWhenRedAlliance should the pose be flipped when the robot is on the red alliance + */ + public FlippablePose2d(Pose2d nonFlippedPose, boolean shouldFlipWhenRedAlliance) { + super(nonFlippedPose, shouldFlipWhenRedAlliance); + } + /** * Gets the rotation value of the pose. The pose will be flipped if the robot is on the red alliance and {@link #shouldFlipWhenRedAlliance} is true. * diff --git a/src/main/java/org/trigon/utilities/flippable/FlippableRotation2d.java b/src/main/java/org/trigon/utilities/flippable/FlippableRotation2d.java index d639b3a9..b23a54c7 100644 --- a/src/main/java/org/trigon/utilities/flippable/FlippableRotation2d.java +++ b/src/main/java/org/trigon/utilities/flippable/FlippableRotation2d.java @@ -7,26 +7,6 @@ * A class that represents a {@link Rotation2d} that can be flipped when the robot is on the red alliance. */ public class FlippableRotation2d extends Flippable { - /** - * Creates a new FlippableRotation2d with the given Rotation2d. - * - * @param nonFlippedRotation the non flipped rotation when the robot is on the blue alliance - * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance - */ - public FlippableRotation2d(Rotation2d nonFlippedRotation, boolean shouldFlipWhenRedAlliance) { - super(nonFlippedRotation, shouldFlipWhenRedAlliance); - } - - /** - * Creates a new FlippableRotation2d with the given rotation value. - * - * @param radians the value of the angle in radians - * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance - */ - public FlippableRotation2d(double radians, boolean shouldFlipWhenRedAlliance) { - this(new Rotation2d(radians), shouldFlipWhenRedAlliance); - } - /** * Constructs and returns a FlippableRotation2d with the given degree value. * @@ -60,6 +40,26 @@ public static FlippableRotation2d fromRotations(double rotations, boolean should return new FlippableRotation2d(Rotation2d.fromRotations(rotations), shouldFlipWhenRedAlliance); } + /** + * Creates a new FlippableRotation2d with the given rotation value. + * + * @param radians the value of the angle in radians + * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance + */ + public FlippableRotation2d(double radians, boolean shouldFlipWhenRedAlliance) { + this(new Rotation2d(radians), shouldFlipWhenRedAlliance); + } + + /** + * Creates a new FlippableRotation2d with the given Rotation2d. + * + * @param nonFlippedRotation the non flipped rotation when the robot is on the blue alliance + * @param shouldFlipWhenRedAlliance should the rotation be flipped when the robot is on the red alliance + */ + public FlippableRotation2d(Rotation2d nonFlippedRotation, boolean shouldFlipWhenRedAlliance) { + super(nonFlippedRotation, shouldFlipWhenRedAlliance); + } + @Override protected Rotation2d flip(Rotation2d rotation) { return FlippingUtil.flipFieldRotation(rotation); diff --git a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java index 505229e0..78bed29c 100644 --- a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java +++ b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java @@ -7,17 +7,6 @@ * A class that represents a {@link Translation2d} that can be flipped when the robot is on the red alliance. */ public class FlippableTranslation2d extends Flippable { - /** - * Creates a new FlippableTranslation3d with the given translation. - * - * @param nonFlippedTranslation the translation to flip - * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance - */ - public FlippableTranslation2d(Translation2d nonFlippedTranslation, boolean shouldFlipWhenRedAlliance) { - super(nonFlippedTranslation, shouldFlipWhenRedAlliance); - } - - /** * Creates a new FlippableTranslation3d with the given x and y values. * @@ -28,6 +17,16 @@ public FlippableTranslation2d(Translation2d nonFlippedTranslation, boolean shoul public FlippableTranslation2d(double x, double y, boolean shouldFlipWhenRedAlliance) { this(new Translation2d(x, y), shouldFlipWhenRedAlliance); } + + /** + * Creates a new FlippableTranslation3d with the given translation. + * + * @param nonFlippedTranslation the translation to flip + * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance + */ + public FlippableTranslation2d(Translation2d nonFlippedTranslation, boolean shouldFlipWhenRedAlliance) { + super(nonFlippedTranslation, shouldFlipWhenRedAlliance); + } @Override protected Translation2d flip(Translation2d translation) { diff --git a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java index 1312de5e..3737bd8a 100644 --- a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java +++ b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java @@ -9,16 +9,6 @@ * The Z value will have no change. */ public class FlippableTranslation3d extends Flippable { - /** - * Creates a new FlippableTranslation3d with the given translation. - * - * @param nonFlippedTranslation the translation to flip - * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance - */ - public FlippableTranslation3d(Translation3d nonFlippedTranslation, boolean shouldFlipWhenRedAlliance) { - super(nonFlippedTranslation, shouldFlipWhenRedAlliance); - } - /** * Creates a new FlippableTranslation3d with the given x, y, and z values. * @@ -31,6 +21,16 @@ public FlippableTranslation3d(double x, double y, double z, boolean shouldFlipWh this(new Translation3d(x, y, z), shouldFlipWhenRedAlliance); } + /** + * Creates a new FlippableTranslation3d with the given translation. + * + * @param nonFlippedTranslation the translation to flip + * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance + */ + public FlippableTranslation3d(Translation3d nonFlippedTranslation, boolean shouldFlipWhenRedAlliance) { + super(nonFlippedTranslation, shouldFlipWhenRedAlliance); + } + @Override protected Translation3d flip(Translation3d translation) { final Translation2d flippedTranslation2d = FlippingUtil.flipFieldPosition(translation.toTranslation2d()); From dc90198cca7c54e67617af8a24224518fb2eda68 Mon Sep 17 00:00:00 2001 From: Yishai Levy <96019039+levyishai@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:47:33 +0200 Subject: [PATCH 3/3] Fixed javadocs --- .../trigon/utilities/flippable/FlippablePose2d.java | 10 +++++----- .../utilities/flippable/FlippableTranslation2d.java | 6 +++--- .../utilities/flippable/FlippableTranslation3d.java | 7 +++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java b/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java index 52c53701..68facc9d 100644 --- a/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java +++ b/src/main/java/org/trigon/utilities/flippable/FlippablePose2d.java @@ -24,12 +24,12 @@ public FlippablePose2d(double x, double y, Rotation2d rotation, boolean shouldFl /** * Creates a new FlippablePose2d with the given translation and rotation. * - * @param translation2d the translation of the pose. - * @param rotation the rotation of the pose. + * @param translation2d the translation of the pose + * @param rotationRadians the rotation of the pose in radians * @param shouldFlipWhenRedAlliance should the pose be flipped when the robot is on the red alliance */ - public FlippablePose2d(Translation2d translation2d, double rotation, boolean shouldFlipWhenRedAlliance) { - this(new Pose2d(translation2d, new Rotation2d(rotation)), shouldFlipWhenRedAlliance); + public FlippablePose2d(Translation2d translation2d, double rotationRadians, boolean shouldFlipWhenRedAlliance) { + this(new Pose2d(translation2d, new Rotation2d(rotationRadians)), shouldFlipWhenRedAlliance); } /** @@ -45,7 +45,7 @@ public FlippablePose2d(Pose2d nonFlippedPose, boolean shouldFlipWhenRedAlliance) /** * Gets the rotation value of the pose. The pose will be flipped if the robot is on the red alliance and {@link #shouldFlipWhenRedAlliance} is true. * - * @return the rotation value of the pose. + * @return the rotation value of the pose */ public FlippableRotation2d getRotation() { return new FlippableRotation2d(nonFlippedObject.getRotation(), shouldFlipWhenRedAlliance); diff --git a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java index 78bed29c..bb605126 100644 --- a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java +++ b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation2d.java @@ -8,7 +8,7 @@ */ public class FlippableTranslation2d extends Flippable { /** - * Creates a new FlippableTranslation3d with the given x and y values. + * Creates a new FlippableTranslation2d with the given x and y values. * * @param x the x value of the translation * @param y the y value of the translation @@ -17,9 +17,9 @@ public class FlippableTranslation2d extends Flippable { public FlippableTranslation2d(double x, double y, boolean shouldFlipWhenRedAlliance) { this(new Translation2d(x, y), shouldFlipWhenRedAlliance); } - + /** - * Creates a new FlippableTranslation3d with the given translation. + * Creates a new FlippableTranslation2d with the given translation. * * @param nonFlippedTranslation the translation to flip * @param shouldFlipWhenRedAlliance should the position be flipped when the robot is on the red alliance diff --git a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java index 3737bd8a..99e697ad 100644 --- a/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java +++ b/src/main/java/org/trigon/utilities/flippable/FlippableTranslation3d.java @@ -31,6 +31,13 @@ public FlippableTranslation3d(Translation3d nonFlippedTranslation, boolean shoul super(nonFlippedTranslation, shouldFlipWhenRedAlliance); } + /** + * Flips the given translation. The translation will be flipped if the robot is on the red alliance and {@link #shouldFlipWhenRedAlliance} is true. + * The Z value will have no change. + * + * @param translation the object to flip + * @return the flipped translation + */ @Override protected Translation3d flip(Translation3d translation) { final Translation2d flippedTranslation2d = FlippingUtil.flipFieldPosition(translation.toTranslation2d());