From b4ecec276532a7f2283f83d8d31b885ec00d2e11 Mon Sep 17 00:00:00 2001 From: doinkythederp Date: Wed, 15 Jan 2025 14:48:50 -0800 Subject: [PATCH] docs: explain inversion --- .../com/frcteam3636/frc2025/utils/Inputs.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/frcteam3636/frc2025/utils/Inputs.kt b/src/main/kotlin/com/frcteam3636/frc2025/utils/Inputs.kt index 7b41682..547728c 100644 --- a/src/main/kotlin/com/frcteam3636/frc2025/utils/Inputs.kt +++ b/src/main/kotlin/com/frcteam3636/frc2025/utils/Inputs.kt @@ -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 @@ -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 @@ -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 + )