2025-07-11 14:07:53 -06:00
|
|
|
package frc4388.utility.compute;
|
2025-02-24 17:59:44 -07:00
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
2025-02-25 11:48:39 -07:00
|
|
|
import edu.wpi.first.math.geometry.Rotation2d;
|
2025-02-24 17:59:44 -07:00
|
|
|
import edu.wpi.first.math.geometry.Translation2d;
|
|
|
|
|
import edu.wpi.first.wpilibj.DriverStation;
|
|
|
|
|
import edu.wpi.first.wpilibj.DriverStation.Alliance;
|
2025-02-25 19:49:10 -07:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
2025-07-11 14:07:53 -06:00
|
|
|
import frc4388.robot.constants.DriveConstants;
|
2025-02-24 17:59:44 -07:00
|
|
|
|
|
|
|
|
// Class that holds weather the drivers sticks should be inverted
|
|
|
|
|
public class TimesNegativeOne {
|
|
|
|
|
|
2025-07-11 14:07:53 -06:00
|
|
|
public static boolean XAxis = DriveConstants.INVERT_X;
|
|
|
|
|
public static boolean YAxis = DriveConstants.INVERT_Y;
|
|
|
|
|
public static boolean RotAxis = DriveConstants.INVERT_ROTATION;
|
2025-02-24 17:59:44 -07:00
|
|
|
public static boolean isRed = false;
|
2025-07-11 14:07:53 -06:00
|
|
|
public static Rotation2d ForwardOffset = Rotation2d.fromDegrees(DriveConstants.FORWARD_OFFSET);
|
2025-02-24 17:59:44 -07:00
|
|
|
|
|
|
|
|
private static boolean isRed() {
|
|
|
|
|
Optional<Alliance> alliance = DriverStation.getAlliance();
|
|
|
|
|
if(alliance.isEmpty()) return false;
|
|
|
|
|
return (alliance.get() == Alliance.Red);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void update(){
|
|
|
|
|
isRed = isRed();
|
2025-07-11 14:07:53 -06:00
|
|
|
XAxis = DriveConstants.INVERT_X ^ isRed;
|
|
|
|
|
YAxis = DriveConstants.INVERT_Y ^ isRed;
|
|
|
|
|
RotAxis = DriveConstants.INVERT_ROTATION;
|
|
|
|
|
ForwardOffset = Rotation2d.fromDegrees((DriveConstants.FORWARD_OFFSET + (isRed ? 0 : 0)));
|
2025-02-25 19:49:10 -07:00
|
|
|
SmartDashboard.putBoolean("Is red alliance", isRed);
|
2025-02-24 17:59:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double invert(double num, boolean invert){
|
|
|
|
|
return invert ? -num : num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Translation2d invert(Translation2d stick, boolean invertXY){
|
|
|
|
|
if(invertXY) return stick.times(-1);
|
|
|
|
|
else return stick;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Translation2d invert(Translation2d stick, boolean invertX, boolean invertY){
|
|
|
|
|
return new Translation2d(
|
|
|
|
|
invert(stick.getX(), invertX),
|
|
|
|
|
invert(stick.getY(), invertY)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|