-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wpimath] Alliance Coordinate Symmetry Utility #7118
base: main
Are you sure you want to change the base?
Conversation
* @return If you are on red alliance. | ||
*/ | ||
public static boolean onRed() { | ||
return DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should throw or something if there isn't an alliance color, not assume blue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, the driver station is often not available when robot code is first booting. This would result in many ds connectivity checks or the user bypassing these functions altogether to prevent silly crashes. So it's really either they don't throw or we don't include these methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would result in many ds connectivity checks or the user bypassing these functions altogether to prevent silly crashes.
No, that's exactly the point. Throwing and then the code restarting while the DS is disconnected is far better than the code starting up and latching to the wrong alliance. See #5229, #5230
This library addition seems a bit overly complex. The minimum API you could get away with is 6 AllianceFlipper member functions, one for each geometry type. public class AllianceFlipper {
public AllianceFlipper(int year);
public Rotation2d flip(Rotation2d);
...
}; template <int Year>
class AllianceFlipper {
public:
static Rotation2d Flip(const Rotation2d&) const;
...
}; In Java, they'd use an if statement on the year to decide which flipping method to use. In C++, they can use constexpr if. Here's the usage (note that we recommend sampling the alliance color when autonomous starts, not when the robot program starts): constexpr AllianceFlipper<2024> flipper;
Rotation2d rot = ...;
if (auto alliance = frc::DriverStation::GetAlliance(); alliance.has_value() && alliance.value() == kRed) {
rot = flipper.Flip(rot);
} I don't see a reason to support custom flippers because unlike custom AprilTag field layouts at home, alliance flipping only really makes sense to do on regulation fields. Also, if your regulation field isn't in-spec, you'll have other problems like the provided AprilTagFieldLayouts not working. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the simplicity of commit 1 as opposed to tendriling this to all of the geometry classes
* | ||
* @param year The year to set the flipper to. [2022 - 2024] | ||
*/ | ||
public static void setYear(int year) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other libraries (fieldImages / AprilTagLayout) do this with a game enum.
public static boolean onRed() { | ||
return onRed.getAsBoolean(); | ||
} | ||
|
||
/** | ||
* Returns if you are on blue alliance, if the alliance is unknown it will return true. | ||
* | ||
* @return If you are on blue alliance. | ||
*/ | ||
public static boolean onBlue() { | ||
return !onRed.getAsBoolean(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be part of the library. It doesn't buy the user / vendordep much over having the user control it.
Moved text to first comment |
/format |
wpimath/src/main/java/edu/wpi/first/math/geometry/AllianceFlipper.java
Outdated
Show resolved
Hide resolved
wpimath/src/main/java/edu/wpi/first/math/geometry/AllianceFlipper.java
Outdated
Show resolved
Hide resolved
wpimath/src/main/java/edu/wpi/first/math/geometry/AllianceFlipper.java
Outdated
Show resolved
Hide resolved
wpimath/src/main/java/edu/wpi/first/math/geometry/AllianceFlipper.java
Outdated
Show resolved
Hide resolved
wpimath/src/main/java/edu/wpi/first/math/geometry/AllianceFlipper.java
Outdated
Show resolved
Hide resolved
I think this is cool! Perhaps add another |
As of the current implementation, the user never has to provide the year if they don't want to, the year is set as static and defaults to the current year. |
wpimath/src/main/java/edu/wpi/first/math/geometry/AllianceSymetry.java
Outdated
Show resolved
Hide resolved
…try.java Co-authored-by: Tim Winters <[email protected]>
Motivations behind this pr:
Pose2d
based on the alliance, this is borderline required for modern autos and having to reset odometry.The reason I made
Flippable
an interface, beyond what is said above abt API continuity, is to help with discoverability. Having aflip()
method on these objects will make it much easier to find this functionality than locking it behind a utility class(also helps with verbosity). Moving to this interface meant moving the utility to be part of wpimath instead of wpilibj/c.I am unsure if all of the flipping in this is mathematically correct, they were just put together quickly to show what would go in this util.