From a1062d3ae368259d4fcd8e57caac6f8a146193d3 Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Wed, 12 Apr 2023 19:35:44 -0400 Subject: [PATCH] yfcghjhfhcgvnm --- src/main/java/frc/robot/RobotContainer.java | 29 ++++++++++++------- src/main/java/frc/robot/commands/Avancer.java | 7 +++-- src/main/java/frc/robot/commands/Gyro.java | 10 +++++-- src/main/java/frc/robot/commands/Reculer.java | 6 ++-- .../frc/robot/commands/bras/Bougerbras.java | 13 +++++++-- .../frc/robot/commands/bras/Bougerpivot.java | 13 +++++++-- .../commands/bras/DescendrePivotBras.java | 7 +++-- .../robot/commands/bras/MonterPivotBras.java | 9 +++--- .../frc/robot/subsystems/BasePilotable.java | 1 + 9 files changed, 63 insertions(+), 32 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 227763a..f39e5a9 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -13,6 +13,7 @@ import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts; import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets; 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.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; @@ -60,15 +61,21 @@ public class RobotContainer { String aumilieux = "au milieux"; String enbas = "en bas"; String nulpart = "nul part"; + GenericEntry forcebrasmonter = Shuffleboard.getTab("teb").addPersistent("force bras monter", 0.35).getEntry(); + GenericEntry forcebrasdescendre = Shuffleboard.getTab("teb").addPersistent("force bras descendre", -0.35).getEntry(); + GenericEntry forcepivotmonter = Shuffleboard.getTab("teb").addPersistent("force pivot monter", 0.5).getEntry(); + GenericEntry forcepivotdescendre = Shuffleboard.getTab("teb").addPersistent("force pivot descendre", -0.5).getEntry(); ShuffleboardLayout layoutauto = Shuffleboard.getTab("teb").getLayout("auto", BuiltInLayouts.kList) .withSize(2, 2).withProperties(Map.of("Label position", "LEFT")); GenericEntry autobalance = layoutauto.add("choix balance", true).withWidget(BuiltInWidgets.kToggleSwitch).getEntry(); GenericEntry autosortir = layoutauto.add("choix sortir", false).withWidget(BuiltInWidgets.kToggleSwitch).getEntry(); - GenericEntry reculerdistances = layoutauto.addPersistent("reculerdistancesortir", -66).getEntry(); - GenericEntry reculerdistanceb = layoutauto.addPersistent("reculerdistancebalance", -31).getEntry(); + GenericEntry reculerdistances = layoutauto.addPersistent("reculer distance sortir", -66).getEntry(); + GenericEntry reculerdistanceb = layoutauto.addPersistent("reculer distance balance", -31).getEntry(); GenericEntry avancerdistance = layoutauto.addPersistent("avancer", 35).getEntry(); - GenericEntry avancerforce = layoutauto.addPersistent("avancerforce", 0.4).getEntry(); - GenericEntry reculerforce = layoutauto.addPersistent("reculerforce", 0.4).getEntry(); + GenericEntry avancerforce = layoutauto.addPersistent("avancer force", 0.4).getEntry(); + GenericEntry reculerforce = layoutauto.addPersistent("reculer force", -0.45).getEntry(); + GenericEntry gyroforce = layoutauto.addPersistent("gyro force", 0.3).getEntry(); + // subsystems BasePilotable basePilotable = new BasePilotable(); Gratte gratte = new Gratte(); @@ -82,13 +89,13 @@ public class RobotContainer { BrakeOuvre brakeOuvre = new BrakeOuvre(basePilotable); GratteBaisser gratteBaisser = new GratteBaisser(gratte); GratteMonte gratteMonte = new GratteMonte(gratte); - Gyro gyro = new Gyro(basePilotable); + Gyro gyro = new Gyro(basePilotable,()->gyroforce.getDouble(0)); FermePince fermePince = new FermePince(pince); OuvrePince ouvrePince = new OuvrePince(pince); Cone cone = new Cone(limelight, basePilotable, () -> -manette1.getLeftY()); - Reculer reculers = new Reculer(basePilotable, () -> reculerdistances.getDouble(0)); - Reculer reculerb = new Reculer(basePilotable, () -> reculerdistanceb.getDouble(0)); - Avancer avancer = new Avancer(basePilotable, () -> avancerdistance.getDouble(0)); + Reculer reculers = new Reculer(basePilotable, () -> reculerdistances.getDouble(0),()->reculerforce.getDouble(0)); + Reculer reculerb = new Reculer(basePilotable, () -> reculerdistanceb.getDouble(0),()->reculerforce.getDouble(0)); + Avancer avancer = new Avancer(basePilotable, () -> avancerdistance.getDouble(0),()-> avancerforce.getDouble(0)); Cube cube = new Cube(limelight, basePilotable, () -> manette1.getLeftY()); Apriltag aprilTag = new Apriltag(limelight, basePilotable, () -> manette1.getLeftY()); Tape tape = new Tape(limelight, basePilotable, () -> manette1.getLeftY()); @@ -137,8 +144,8 @@ public class RobotContainer { private Command creerCommandBras(double distancePivot, double distanceBras) { return Commands.either( - new MonterPivotBras(brasTelescopique, pivot, distanceBras, distancePivot), - new DescendrePivotBras(brasTelescopique, pivot, distanceBras, distancePivot), + new MonterPivotBras(brasTelescopique, pivot, distanceBras, distancePivot,forcebrasmonter,forcebrasdescendre,forcepivotmonter,forcepivotdescendre), + new DescendrePivotBras(brasTelescopique, pivot, distanceBras, distancePivot,forcebrasmonter,forcebrasdescendre,forcepivotmonter,forcepivotdescendre), () -> pivot.distance() < distancePivot); } @@ -160,7 +167,7 @@ public class RobotContainer { new FermePince(pince).unless(() -> chooser.getSelected().equals(nulpart)), new ParallelCommandGroup (creerCommandBras(0, 0).unless(() -> chooser.getSelected().equals(nulpart)), Commands.either(reculers, reculerb, () -> autosortir.getBoolean(true))), - new Avancer(basePilotable, () -> avancerdistance.getDouble(0)).unless(() -> !autosortir.getBoolean(true) || !autobalance.getBoolean(false)), + new Avancer(basePilotable, () -> avancerdistance.getDouble(0),()->avancerforce.getDouble(0)).unless(() -> !autosortir.getBoolean(true) || !autobalance.getBoolean(false)), Commands.either(gyro, Commands.none(), () -> autobalance.getBoolean(true)))) .andThen(brakeOuvre); diff --git a/src/main/java/frc/robot/commands/Avancer.java b/src/main/java/frc/robot/commands/Avancer.java index c0cc3cf..f62d7f9 100644 --- a/src/main/java/frc/robot/commands/Avancer.java +++ b/src/main/java/frc/robot/commands/Avancer.java @@ -7,17 +7,18 @@ package frc.robot.commands; import java.util.function.DoubleSupplier; -import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj2.command.CommandBase; import frc.robot.subsystems.BasePilotable; public class Avancer extends CommandBase { BasePilotable basePilotable; DoubleSupplier distance; + DoubleSupplier force; /** Creates a new Reculer. */ - public Avancer(BasePilotable basePilotable, DoubleSupplier distance) { + public Avancer(BasePilotable basePilotable, DoubleSupplier distance, DoubleSupplier force) { this.basePilotable = basePilotable; this.distance = distance; + this.force = force; // Use addRequirements() here to declare subsystem dependencies. addRequirements(basePilotable); } @@ -31,7 +32,7 @@ public class Avancer extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - basePilotable.drive(0.4,0); + basePilotable.drive(force.getAsDouble(),0); } // Called once the command ends or is interrupted. diff --git a/src/main/java/frc/robot/commands/Gyro.java b/src/main/java/frc/robot/commands/Gyro.java index 7874235..ea56e0d 100644 --- a/src/main/java/frc/robot/commands/Gyro.java +++ b/src/main/java/frc/robot/commands/Gyro.java @@ -5,14 +5,18 @@ package frc.robot.commands; +import java.util.function.DoubleSupplier; + import edu.wpi.first.wpilibj2.command.CommandBase; import frc.robot.subsystems.BasePilotable; public class Gyro extends CommandBase { private BasePilotable basePilotable; + DoubleSupplier force; /** Creates a new Gyro. */ - public Gyro(BasePilotable basePilotable) { + public Gyro(BasePilotable basePilotable,DoubleSupplier force) { this.basePilotable = basePilotable; + this.force = force; // Use addRequirements() here to declare subsystem dependencies. addRequirements(basePilotable); } @@ -26,11 +30,11 @@ public class Gyro extends CommandBase { public void execute() { if(basePilotable.getpitch()>6) { - basePilotable.drive(0.3*basePilotable.getpitch()/12, 0); + basePilotable.drive(force.getAsDouble()*basePilotable.getpitch()/12, 0); } else if(basePilotable.getpitch()<-6) { - basePilotable.drive(0.3*basePilotable.getpitch()/12, 0); + basePilotable.drive(force.getAsDouble()*basePilotable.getpitch()/12, 0); } else { diff --git a/src/main/java/frc/robot/commands/Reculer.java b/src/main/java/frc/robot/commands/Reculer.java index 51e81b2..128cdfb 100644 --- a/src/main/java/frc/robot/commands/Reculer.java +++ b/src/main/java/frc/robot/commands/Reculer.java @@ -13,10 +13,12 @@ import frc.robot.subsystems.BasePilotable; public class Reculer extends CommandBase { BasePilotable basePilotable; DoubleSupplier distance; + DoubleSupplier force; /** Creates a new Reculer. */ - public Reculer(BasePilotable basePilotable, DoubleSupplier distance) { + public Reculer(BasePilotable basePilotable, DoubleSupplier distance,DoubleSupplier force) { this.basePilotable = basePilotable; this.distance = distance; + this.force = force; // Use addRequirements() here to declare subsystem dependencies. addRequirements(basePilotable); } @@ -30,7 +32,7 @@ public class Reculer extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - basePilotable.drive(-0.45,0); + basePilotable.drive(force.getAsDouble(),0); } // Called once the command ends or is interrupted. diff --git a/src/main/java/frc/robot/commands/bras/Bougerbras.java b/src/main/java/frc/robot/commands/bras/Bougerbras.java index d807832..8a97404 100644 --- a/src/main/java/frc/robot/commands/bras/Bougerbras.java +++ b/src/main/java/frc/robot/commands/bras/Bougerbras.java @@ -4,6 +4,8 @@ package frc.robot.commands.bras; +import edu.wpi.first.networktables.GenericEntry; +import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj2.command.CommandBase; import frc.robot.subsystems.bras.BrasTelescopique; @@ -11,9 +13,14 @@ public class Bougerbras extends CommandBase { /** Creates a new bougerbras. */ double distance; BrasTelescopique brasTelescopique; - public Bougerbras(BrasTelescopique brasTelescopique,double distance) { + private GenericEntry forcebrasdescendre; + private GenericEntry forcebrasmonter; + + public Bougerbras(BrasTelescopique brasTelescopique,double distance,GenericEntry forcebrasdescendre, GenericEntry forcebrasmonter) { this.brasTelescopique = brasTelescopique; this.distance = distance; + this.forcebrasdescendre = forcebrasdescendre; + this.forcebrasmonter = forcebrasmonter; addRequirements(brasTelescopique); // Use addRequirements() here to declare subsystem dependencies. } @@ -28,11 +35,11 @@ public class Bougerbras extends CommandBase { @Override public void execute() { if(brasTelescopique.distance()>distance+0.5 ) { - brasTelescopique.AvanceRecule(-0.35); + brasTelescopique.AvanceRecule(forcebrasdescendre.getDouble(-0.35)); } else if(brasTelescopique.distance()distance+0.5 ) { - pivot.monteDescendre(-0.5); + pivot.monteDescendre(forcepivotdescendre.getDouble(-0.5)); } else if(pivot.distance()pivot.distance()>10), - new ParallelCommandGroup(new Bougerpivot(pivot, distancePivot)), - new ParallelCommandGroup(new Bougerbras(brasTelescopique, distanceBras)) + new Bougerpivot(pivot, 10, forcepivotdescendre, forcepivotdescendre).unless(()->pivot.distance()>10), + new ParallelCommandGroup(new Bougerpivot(pivot, distancePivot,forcepivotdescendre,forcepivotmonter)), + new ParallelCommandGroup(new Bougerbras(brasTelescopique, distanceBras,forcebrasdescendre,forcebrasmonter)) ); diff --git a/src/main/java/frc/robot/subsystems/BasePilotable.java b/src/main/java/frc/robot/subsystems/BasePilotable.java index a5d5b91..a582c7b 100644 --- a/src/main/java/frc/robot/subsystems/BasePilotable.java +++ b/src/main/java/frc/robot/subsystems/BasePilotable.java @@ -74,6 +74,7 @@ public void BrakeFerme(){ teb.add(drive); teb.addDouble("distancerobot",this::distance); teb.addDouble("angle gyro", this::getpitch); + } @Override