Changement reset gyro

This commit is contained in:
Olivier Demers 2022-11-29 19:45:02 -05:00
parent 3ac1697bb4
commit ed8f05fc64
3 changed files with 14 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.button.JoystickButton; import edu.wpi.first.wpilibj2.command.button.JoystickButton;
@ -73,7 +74,12 @@ public class RobotContainer {
JoystickButton buttonX = new JoystickButton(manette, XboxController.Button.kX.value); JoystickButton buttonX = new JoystickButton(manette, XboxController.Button.kX.value);
buttonX.whenPressed(ActiverBlockeur); buttonX.whenPressed(ActiverBlockeur);
JoystickButton buttonstart = new JoystickButton(manette, XboxController.Button.kStart.value); JoystickButton buttonstart = new JoystickButton(manette, XboxController.Button.kStart.value);
buttonstart.whenPressed(resetGyro); buttonstart.whenPressed(
new InstantCommand(
() -> basePilotable.resetgyro(),
basePilotable
)
);
} }
/** /**

View File

@ -4,7 +4,6 @@
package frc.robot.commands; package frc.robot.commands;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj2.command.CommandBase; import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.BasePilotable; import frc.robot.subsystems.BasePilotable;
@ -20,12 +19,7 @@ public class ResetGyro extends CommandBase {
// Called when the command is initially scheduled. // Called when the command is initially scheduled.
@Override @Override
public void initialize() { public void initialize() {
try {
basePilotable.resetgyro();
} catch( Exception e) {
DriverStation.reportError("Samuel", e.getStackTrace());
}
} }
// Called every time the scheduler runs while the command is scheduled. // Called every time the scheduler runs while the command is scheduled.

View File

@ -32,7 +32,12 @@ public void drive(double y, double x, double rot){
mecanum.driveCartesian(y, rot, x, -getangle()); mecanum.driveCartesian(y, rot, x, -getangle());
} }
public void resetgyro(){ public void resetgyro(){
gyroscope.zeroYaw(); try {
gyroscope.zeroYaw();
} catch( Exception e) {
e.printStackTrace();
}
} }
/** Creates a new BasePilotable. */ /** Creates a new BasePilotable. */
public BasePilotable() { public BasePilotable() {