Skip to content

Commit

Permalink
docs: explain inversion
Browse files Browse the repository at this point in the history
  • Loading branch information
doinkythederp committed Jan 15, 2025
1 parent 1ba7038 commit b4ecec2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/kotlin/com/frcteam3636/frc2025/utils/Inputs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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
Expand All @@ -13,7 +14,6 @@ import kotlin.jvm.optionals.getOrNull
val Joystick.fieldRelativeTranslation2d: Translation2d
get() {
val base = translation2d
// Joystick x/y are inverted from the standard coordinate system+
return when (DriverStation.getAlliance().getOrNull()) {
Alliance.Red -> -base
else -> base
Expand All @@ -23,5 +23,15 @@ val Joystick.fieldRelativeTranslation2d: Translation2d
/**
* Returns the translation of the joystick input.
*/
val Joystick.translation2d: Translation2d // Joystick x/y are inverted from the standard coordinate system
get() = Translation2d(-y, -x)
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
)

0 comments on commit b4ecec2

Please sign in to comment.