-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly specify chassis speeds (#40)
- Loading branch information
Showing
2 changed files
with
37 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
package com.frcteam3636.frc2025.utils | ||
|
||
import com.frcteam3636.frc2025.Robot | ||
import edu.wpi.first.math.geometry.Translation2d | ||
import edu.wpi.first.wpilibj.DriverStation | ||
import edu.wpi.first.wpilibj.DriverStation.Alliance | ||
import edu.wpi.first.wpilibj.Joystick | ||
import kotlin.jvm.optionals.getOrNull | ||
|
||
// Joystick x/y are inverted from the standard coordinate system | ||
val Joystick.translation2d get() = Translation2d(y, x) | ||
|
||
/** | ||
* Returns the translation of the joystick input, flipped to match the current alliance. | ||
*/ | ||
val Joystick.fieldRelativeTranslation2d: Translation2d | ||
get() { | ||
val base = translation2d | ||
return when (DriverStation.getAlliance().getOrNull()) { | ||
Alliance.Red -> -base | ||
else -> base | ||
} | ||
} | ||
|
||
/** | ||
* Returns the translation of the joystick input. | ||
*/ | ||
val Joystick.translation2d: Translation2d | ||
// The field-space translation returned by this method is rotated 90 degrees from the joystick's | ||
// perspective. (x, y) -> (y, -x) The joystick's Y-axis is also inverted because of our physical | ||
// hardware, but this isn't an issue in simulation. | ||
get() = Translation2d( | ||
if (Robot.model == Robot.Model.SIMULATION) { | ||
y | ||
} else { | ||
-y | ||
}, | ||
-x | ||
) |