From 09e7f3f44c9cd8aef22a099b8efe2ac026528c6c Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 5 Dec 2023 19:25:21 -0500 Subject: [PATCH] mode auto + modif --- src/main/java/frc/robot/RobotContainer.java | 13 ++++-- src/main/java/frc/robot/commands/AccAuto.java | 41 +++++++++++++++++++ src/main/java/frc/robot/commands/Avancer.java | 16 ++++---- src/main/java/frc/robot/commands/Force1.java | 2 +- .../java/frc/robot/commands/LanceurAuto.java | 12 ++++-- 5 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 src/main/java/frc/robot/commands/AccAuto.java diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index adc8e01..6c93e0c 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -11,11 +11,13 @@ import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.ParallelCommandGroup; import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; import edu.wpi.first.wpilibj2.command.button.CommandJoystick; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; +import frc.robot.commands.AccAuto; import frc.robot.commands.Avancer; import frc.robot.commands.Force1; //import frc.robot.commands.Lancer; @@ -25,6 +27,7 @@ import frc.robot.commands.Force4; import frc.robot.commands.Force5; import frc.robot.commands.Force6; import frc.robot.commands.Force7; +import frc.robot.commands.LanceurAuto; import frc.robot.commands.Force1; import frc.robot.commands.Reculer; import frc.robot.commands.accumulateurtest; @@ -35,7 +38,8 @@ import frc.robot.subsystems.Lanceur; public class RobotContainer { Lanceur lanceur = new Lanceur(); Accumulateur accumulateur = new Accumulateur(); - + Drive drive = new Drive(); + Avancer avancer = new Avancer(drive); ShuffleboardTab dashboard = Shuffleboard.getTab("Dashboard"); @@ -53,7 +57,6 @@ public class RobotContainer { CommandXboxController manette = new CommandXboxController(0); CommandJoystick joystick1 = new CommandJoystick(0); - Drive drive = new Drive(); public RobotContainer() { configureBindings(); @@ -87,8 +90,10 @@ public class RobotContainer { public Command getAutonomousCommand() { - return new SequentialCommandGroup(new ParallelCommandGroup(new Force1(lanceur).withTimeout(5),new accumulateurtest(accumulateur).withTimeout(5)) - ,new Avancer(drive)); + return Commands.deadline(Commands.waitSeconds(12) + ,new SequentialCommandGroup(new ParallelCommandGroup(new LanceurAuto(lanceur).withTimeout(6) + ,new AccAuto(accumulateur).withTimeout(6)) + )).andThen(avancer); } } diff --git a/src/main/java/frc/robot/commands/AccAuto.java b/src/main/java/frc/robot/commands/AccAuto.java new file mode 100644 index 0000000..b174a32 --- /dev/null +++ b/src/main/java/frc/robot/commands/AccAuto.java @@ -0,0 +1,41 @@ +// 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.CommandBase; +import frc.robot.subsystems.Accumulateur; + +public class AccAuto extends CommandBase { + private Accumulateur accumulateur; + /** Creates a new AccAuto. */ + public AccAuto(Accumulateur accumulateur) { + this.accumulateur = accumulateur; + addRequirements(accumulateur); + // 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() { + accumulateur.reaccumuler(); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + accumulateur.stop(); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/commands/Avancer.java b/src/main/java/frc/robot/commands/Avancer.java index c0ee5c7..4886a11 100644 --- a/src/main/java/frc/robot/commands/Avancer.java +++ b/src/main/java/frc/robot/commands/Avancer.java @@ -19,10 +19,10 @@ public class Avancer extends CommandBase { .withSize(3, 3); /** Creates a new Avancer. */ public Avancer(Drive drive) { - avancer.add("vitesse x", 1); - avancer.add("vitesse y", 2); - avancer.add("vitesse z", 3); - avancer.add("distance", 4); + //avancer.add("vitesse x", 1); + // avancer.add("vitesse y", 2); + // avancer.add("vitesse z", 3); + // avancer.add("distance", 4); this.drive = drive; addRequirements(drive); // Use addRequirements() here to declare subsystem dependencies. @@ -37,16 +37,18 @@ public class Avancer extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - drive.drive(0.5, 0.2, 0); + drive.drive(0.5, -0.2, 0); } // Called once the command ends or is interrupted. @Override - public void end(boolean interrupted) {} + public void end(boolean interrupted) { + drive.drive(0, 0, 0); + } // Returns true when the command should end. @Override public boolean isFinished() { - return drive.distance()[0].distanceMeters>1; + return drive.distance()[0].distanceMeters>0.01; } } diff --git a/src/main/java/frc/robot/commands/Force1.java b/src/main/java/frc/robot/commands/Force1.java index 31d2ae0..4a8e3d7 100644 --- a/src/main/java/frc/robot/commands/Force1.java +++ b/src/main/java/frc/robot/commands/Force1.java @@ -15,7 +15,7 @@ public class Force1 extends CommandBase { private Lanceur lanceur; /** Creates a new LancerTest. */ - public Force1(Lanceur lanceur, g) { + public Force1(Lanceur lanceur, GenericEntry force1) { dashboard.add("vitesse lanceur", 0.5); this.lanceur = lanceur; addRequirements(lanceur); diff --git a/src/main/java/frc/robot/commands/LanceurAuto.java b/src/main/java/frc/robot/commands/LanceurAuto.java index 72b12f9..24fbad4 100644 --- a/src/main/java/frc/robot/commands/LanceurAuto.java +++ b/src/main/java/frc/robot/commands/LanceurAuto.java @@ -12,22 +12,26 @@ public class LanceurAuto extends CommandBase { /** Creates a new LanceurAuto. */ public LanceurAuto(Lanceur lanceur) { this.lanceur = lanceur; + addRequirements(lanceur); // Use addRequirements() here to declare subsystem dependencies. } // Called when the command is initially scheduled. @Override public void initialize() { - lanceur.setPID(0, 0, 0); - } + lanceur.setPID(0.000000000000075572, 0, 0);} // Called every time the scheduler runs while the command is scheduled. @Override - public void execute() {} + public void execute() { + lanceur.lancer(0.6); + } // Called once the command ends or is interrupted. @Override - public void end(boolean interrupted) {} + public void end(boolean interrupted) { + lanceur.lancer(0); + } // Returns true when the command should end. @Override