From 74e1c8a17ae12d35f3e8896ab166ebed410565fb Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Sat, 2 Dec 2023 12:14:19 -0500 Subject: [PATCH] fchb --- src/main/java/frc/robot/RobotContainer.java | 28 +++++-------- .../java/frc/robot/commands/AccAvancer.java | 41 +++++++++++++++++++ .../java/frc/robot/commands/AccReculer.java | 40 ++++++++++++++++++ src/main/java/frc/robot/commands/Lancer.java | 34 +++++++++++++++ .../commands/{Force1.java => Lancez.java} | 34 ++++----------- 5 files changed, 133 insertions(+), 44 deletions(-) create mode 100644 src/main/java/frc/robot/commands/AccAvancer.java create mode 100644 src/main/java/frc/robot/commands/AccReculer.java create mode 100644 src/main/java/frc/robot/commands/Lancer.java rename src/main/java/frc/robot/commands/{Force1.java => Lancez.java} (55%) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 1ea9ed1..8d9b156 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -15,7 +15,7 @@ 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.Avancer; -import frc.robot.commands.Force1; +import frc.robot.commands.Lancer; import frc.robot.commands.Force2; import frc.robot.commands.Force3; import frc.robot.commands.Force4; @@ -38,7 +38,7 @@ public class RobotContainer { ShuffleboardLayout forces = Shuffleboard.getTab("Dashboard") .getLayout("Dashboard", BuiltInLayouts.kList) .withSize(3, 7); - GenericEntry force1 = forces.add("Force1", 0).getEntry(); + GenericEntry force1 = forces.add("Force1", 2).getEntry(); GenericEntry force2 = forces.add("Force2", 0).getEntry(); GenericEntry force3 = forces.add("Force3", 0).getEntry(); GenericEntry force4 = forces.add("Force4", 0).getEntry(); @@ -58,27 +58,21 @@ public class RobotContainer { } private void configureBindings() { - Force1 Force1 = new Force1(lanceur, accumulateur, null); - Force2 Force2 = new Force2(lanceur, accumulateur, null); - Force3 Force3 = new Force3(lanceur, null, accumulateur); - Force4 Force4 = new Force4(lanceur, null, accumulateur); - Force5 Force5 = new Force5(lanceur, null, accumulateur); - Force6 Force6 = new Force6(lanceur, null, accumulateur); - Force7 Force7 = new Force7(lanceur, null, accumulateur); + accumulateurtest accumulateurtest = new accumulateurtest(accumulateur); - joystick1.button(7).onTrue(Force1); - joystick1.button(8).onTrue(Force2); - joystick1.button(9).onTrue(Force3); - joystick1.button(10).onTrue(Force4); - joystick1.button(11).onTrue(Force5); - joystick1.button(12).onTrue(Force6); - joystick1.button(3).onTrue(Force7); + joystick1.button(7).onTrue(new Lancer(lanceur, accumulateur, force1)); + joystick1.button(8).onTrue(new Lancer(lanceur, accumulateur, force2)); + joystick1.button(9).onTrue(new Lancer(lanceur, accumulateur, force3)); + joystick1.button(10).onTrue(new Lancer(lanceur, accumulateur, force4)); + joystick1.button(11).onTrue(new Lancer(lanceur, accumulateur, force5)); + joystick1.button(12).onTrue(new Lancer(lanceur, accumulateur, force6)); + joystick1.button(3).onTrue(new Lancer(lanceur, accumulateur, force7)); joystick1.button(5).toggleOnTrue(accumulateurtest); } public Command getAutonomousCommand() { return new SequentialCommandGroup(new Avancer(drive), new Force7(lanceur, force7, accumulateur) - , new Force1(lanceur, accumulateur, force1), new Reculer(drive)); + , new Lancer(lanceur, accumulateur, force1), new Reculer(drive)); } } diff --git a/src/main/java/frc/robot/commands/AccAvancer.java b/src/main/java/frc/robot/commands/AccAvancer.java new file mode 100644 index 0000000..780a869 --- /dev/null +++ b/src/main/java/frc/robot/commands/AccAvancer.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 AccAvancer extends CommandBase { + private Accumulateur accumulateur; + /** Creates a new AccAvancer. */ + public AccAvancer(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.Deaccumuler(); + } + + // 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 accumulateur.tourneavant()<1024; + } +} diff --git a/src/main/java/frc/robot/commands/AccReculer.java b/src/main/java/frc/robot/commands/AccReculer.java new file mode 100644 index 0000000..e092a1d --- /dev/null +++ b/src/main/java/frc/robot/commands/AccReculer.java @@ -0,0 +1,40 @@ +// 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 AccReculer extends CommandBase { + private Accumulateur accumulateur; + /** Creates a new AccReculer. */ + public AccReculer(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 accumulateur.tournearriere()<-256; + } +} diff --git a/src/main/java/frc/robot/commands/Lancer.java b/src/main/java/frc/robot/commands/Lancer.java new file mode 100644 index 0000000..f52c69c --- /dev/null +++ b/src/main/java/frc/robot/commands/Lancer.java @@ -0,0 +1,34 @@ +// 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 java.util.function.DoubleSupplier; + +import edu.wpi.first.networktables.GenericEntry; +import edu.wpi.first.wpilibj2.command.ParallelCommandGroup; +import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; +import edu.wpi.first.wpilibj2.command.WaitUntilCommand; +import frc.robot.subsystems.Accumulateur; +import frc.robot.subsystems.Lanceur; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html +public class Lancer extends ParallelCommandGroup { + private Lanceur lanceur; + private Accumulateur accumulateur; + + /** Creates a new Force1. */ + public Lancer(Lanceur lanceur,Accumulateur accumulateur,GenericEntry vitesse) { + this.lanceur = lanceur; + this.accumulateur = accumulateur; + + // Add your commands in the addCommands() call, e.g. + // addCommands(new FooCommand(), new BarCommand()); + addCommands(new Lancez(lanceur), + new SequentialCommandGroup(new WaitUntilCommand(()->lanceur.vitesse()>vitesse.getDouble(0))) + ,new AccAvancer(accumulateur),new AccReculer(accumulateur)); + } +} diff --git a/src/main/java/frc/robot/commands/Force1.java b/src/main/java/frc/robot/commands/Lancez.java similarity index 55% rename from src/main/java/frc/robot/commands/Force1.java rename to src/main/java/frc/robot/commands/Lancez.java index 7b3cb09..18b4433 100644 --- a/src/main/java/frc/robot/commands/Force1.java +++ b/src/main/java/frc/robot/commands/Lancez.java @@ -4,55 +4,35 @@ package frc.robot.commands; - -import edu.wpi.first.networktables.GenericEntry; import edu.wpi.first.wpilibj2.command.CommandBase; import frc.robot.subsystems.Accumulateur; import frc.robot.subsystems.Lanceur; -public class Force1 extends CommandBase { +public class Lancez extends CommandBase { private Lanceur lanceur; - private Accumulateur accumulateur; - GenericEntry force1; - - /** Creates a new Force1. */ - public Force1(Lanceur lanceur,Accumulateur accumulateur, GenericEntry force1) { + /** Creates a new Lancez. */ + public Lancez(Lanceur lanceur) { this.lanceur = lanceur; - this.accumulateur = accumulateur; - addRequirements(lanceur, accumulateur); - this.force1 = force1; + 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, 0, 0); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - lanceur.lancer(force1.getDouble(100)); - double vitesse = (100); - if (lanceur.vitesse() > vitesse ){ - accumulateur.tourneavant(); - if(accumulateur.tourneavant()>1024) { - accumulateur.tournearriere(); - } - if(accumulateur.tournearriere()>-256){ - accumulateur.stop(); - } - }} - - - + lanceur.lancer(0); + } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { lanceur.lancer(0); - accumulateur.stop(); } // Returns true when the command should end.