From 52c72e9a6153a04e977a4760b0aafbb7d96bad19 Mon Sep 17 00:00:00 2001 From: Antoine PerreaultE Date: Tue, 31 Mar 2026 19:52:24 -0400 Subject: [PATCH] inverser --- src/main/java/frc/robot/RobotContainer.java | 2 + .../java/frc/robot/commands/Inverser.java | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/frc/robot/commands/Inverser.java diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index ce353e8..f4d6ba0 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -20,6 +20,7 @@ import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import frc.robot.commands.Aspirer; import frc.robot.commands.DescendreBalyeuse; import frc.robot.commands.DescendreGrimpeur; +import frc.robot.commands.Inverser; import frc.robot.commands.Lancer; import frc.robot.commands.LancerAspirer; import frc.robot.commands.LancerBaseVitesse; @@ -132,6 +133,7 @@ public class RobotContainer { manette1.y().whileTrue(new ModeOposerBalayeuse(balayeuse)); manette1.povRight().whileTrue(new BougerDroiteAuto(drivetrain)); manette1.povLeft().whileTrue(new BougerGaucheAuto(drivetrain)); + manette1.start().whileTrue(new Inverser(drivetrain)); } public Command getAutonomousCommand() { diff --git a/src/main/java/frc/robot/commands/Inverser.java b/src/main/java/frc/robot/commands/Inverser.java new file mode 100644 index 0000000..3b8f0a0 --- /dev/null +++ b/src/main/java/frc/robot/commands/Inverser.java @@ -0,0 +1,42 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package frc.robot.commands; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.CommandSwerveDrivetrain; + +/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */ +public class Inverser extends Command { + CommandSwerveDrivetrain drivetrain; + boolean inverse = false; + /** Creates a new Inverser. */ + public Inverser(CommandSwerveDrivetrain drivetrain) { + addRequirements(drivetrain); + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() {} + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + if(!inverse){ + drivetrain.getPigeon2().setYaw(drivetrain.getPigeon2().getYaw().getValueAsDouble()+180); + inverse = true; + } + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +}