diff --git a/simgui.json b/simgui.json index 1d8ea9a..7b653c9 100644 --- a/simgui.json +++ b/simgui.json @@ -1,7 +1,8 @@ { "NTProvider": { "types": { - "/FMSInfo": "FMSInfo" + "/FMSInfo": "FMSInfo", + "/Shuffleboard/teb/auto/choix hauteur": "String Chooser" } }, "NetworkTables": { diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index b2ce20d..7b935de 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -6,20 +6,20 @@ public class Constants { public static int arrieredroit = 3; public static int arrieregauche = 5; public static int BrasTelescopique = 2; - public static int pivot = 0; + public static int pivot = 6; //moteur - public static int leverGratte = 0; - public static int baiserGratte = 1; + public static int leverGratte = 7; + public static int baiserGratte = 8; // pneumatique public static int pistonpinceouvre = 0; public static int pistonpinceferme = 1; - public static int actuateur = 8; + public static int actuateur = 2; public static int brakedroit = 3; public static int brakegauche = 4; public static int brakewinchf = 5; - public static int brakewinchb = 5; + public static int brakewinchb = 6; // DIO public static int limitbd = 0; public static int limitbg = 2; diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 96cd9b4..d802160 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -7,6 +7,8 @@ import java.util.Map; import edu.wpi.first.cameraserver.CameraServer; import edu.wpi.first.networktables.GenericEntry; +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.smartdashboard.SendableChooser; @@ -23,6 +25,7 @@ import frc.robot.subsystems.bras.BrasTelescopique; import frc.robot.subsystems.bras.Pince; import frc.robot.subsystems.bras.Pivot; import frc.robot.subsystems.Limelight; +import frc.robot.commands.Avancer; // command import frc.robot.commands.BrakeFerme; import frc.robot.commands.BrakeOuvre; @@ -43,6 +46,19 @@ public class RobotContainer { CommandXboxController manette1 = new CommandXboxController(0); CommandXboxController manette2 = new CommandXboxController(1); + +SendableChooser chooser = new SendableChooser<>(); +String enhaut = "en haut"; +String aumilieux = "au milieux"; +String enbas = "en bas"; +String nulpart = "nul part"; +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",0).getEntry(); +GenericEntry reculerdistanceb = layoutauto.addPersistent("reculerdistancebalance", 0).getEntry(); +GenericEntry avancerdistance = layoutauto.addPersistent("avancer",0).getEntry(); // subsystems BasePilotable basePilotable = new BasePilotable(); Gratte gratte = new Gratte(); @@ -63,16 +79,10 @@ PivoteBrasBas pivoteBrasBas = new PivoteBrasBas(brasTelescopique, pivot); PivoteBrasMilieux pivoteBrasMilieux = new PivoteBrasMilieux(brasTelescopique, pivot); PivoteBrasHaut pivoteBrasHaut = new PivoteBrasHaut(brasTelescopique, pivot); Cone cone = new Cone(limelight, basePilotable, ()->-manette1.getLeftY()); -Reculer reculer = new Reculer(basePilotable); +Reculer reculers = new Reculer(basePilotable, ()->reculerdistances.getDouble(0)); +Reculer reculerb = new Reculer(basePilotable, ()->reculerdistanceb.getDouble(0)); +Avancer avancer = new Avancer(basePilotable, ()->avancerdistance.getDouble(0)); -SendableChooser chooser = new SendableChooser<>(); -String enhaut = "en bas"; -String aumilieux = "au milieux"; -String enbas = "en bas"; -String nulpart = "nul part"; -ShuffleboardLayout layoutauto = Shuffleboard.getTab("teb").getLayout("auto"); -GenericEntry autobalance = layoutauto.add("choix balance",true).getEntry(); -GenericEntry autosortir = layoutauto.add("choix sorit",false).getEntry(); public RobotContainer() { chooser.setDefaultOption(enhaut, enhaut); chooser.addOption(enbas, enbas); @@ -102,14 +112,16 @@ public RobotContainer() { chooser.getSelected(); autobalance.getBoolean(true); return new SequentialCommandGroup( - Commands.either(gyro, Commands.none(),()-> autobalance.getBoolean(true)), - Commands.either(reculer, Commands.none(),()-> autosortir.getBoolean(true)), Commands.select(Map.ofEntries( Map.entry(enhaut,pivoteBrasHaut), - Map.entry(aumilieux,null), - Map.entry(enbas,null), - Map.entry(nulpart,null) - ), chooser::getSelected) + Map.entry(aumilieux,pivoteBrasMilieux), + Map.entry(enbas,pivoteBrasBas), + Map.entry(nulpart,pivotBrasRentre) + ), chooser::getSelected), + ouvrePince.unless(()->chooser.getSelected().equals(nulpart)), + Commands.either(reculers, reculerb,()-> autosortir.getBoolean(true)), + avancer.unless(()->!autosortir.getBoolean(true)|| !autobalance.getBoolean(false)), + Commands.either(gyro, Commands.none(),()-> autobalance.getBoolean(true)) ); diff --git a/src/main/java/frc/robot/commands/Apriltag.java b/src/main/java/frc/robot/commands/Apriltag.java index 3ef6b06..9ef54b3 100644 --- a/src/main/java/frc/robot/commands/Apriltag.java +++ b/src/main/java/frc/robot/commands/Apriltag.java @@ -32,7 +32,7 @@ public class Apriltag extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw(), 0); + basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw()); } // Called once the command ends or is interrupted. diff --git a/src/main/java/frc/robot/commands/Avancer.java b/src/main/java/frc/robot/commands/Avancer.java new file mode 100644 index 0000000..0b94017 --- /dev/null +++ b/src/main/java/frc/robot/commands/Avancer.java @@ -0,0 +1,48 @@ +// 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.wpilibj.shuffleboard.Shuffleboard; +import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.BasePilotable; + +public class Avancer extends CommandBase { + BasePilotable basePilotable; + DoubleSupplier distance; + /** Creates a new Reculer. */ + public Avancer(BasePilotable basePilotable, DoubleSupplier distance) { + this.basePilotable = basePilotable; + this.distance = distance; + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(basePilotable); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + basePilotable.Reset(); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + basePilotable.drive(0.3,0); + } + + // 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 basePilotable.distance()>distance.getAsDouble(); + } +} diff --git a/src/main/java/frc/robot/commands/Cone.java b/src/main/java/frc/robot/commands/Cone.java index 8121b19..d780293 100644 --- a/src/main/java/frc/robot/commands/Cone.java +++ b/src/main/java/frc/robot/commands/Cone.java @@ -32,7 +32,7 @@ public class Cone extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw(), 0); + basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw()); } // Called once the command ends or is interrupted. diff --git a/src/main/java/frc/robot/commands/Cube.java b/src/main/java/frc/robot/commands/Cube.java index 2bd023f..d54839e 100644 --- a/src/main/java/frc/robot/commands/Cube.java +++ b/src/main/java/frc/robot/commands/Cube.java @@ -32,7 +32,7 @@ public class Cube extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw(), 0); + basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw()); } // 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 6a758d0..d65a693 100644 --- a/src/main/java/frc/robot/commands/Gyro.java +++ b/src/main/java/frc/robot/commands/Gyro.java @@ -30,20 +30,20 @@ public class Gyro extends CommandBase { public void execute() { if(basePilotable.getpitch()>10) { - basePilotable.drive(0.3*basePilotable.getpitch()/12, 0, 0); + basePilotable.drive(0.3*basePilotable.getpitch()/12, 0); } else if(basePilotable.getpitch()<-10) { - basePilotable.drive(0.3*basePilotable.getpitch()/12, 0, 0); - basePilotable.drive(0.3*basePilotable.getpitch()/15, 0, 0); + basePilotable.drive(0.3*basePilotable.getpitch()/12, 0); + basePilotable.drive(0.3*basePilotable.getpitch()/15, 0); } else if(basePilotable.getpitch()<-4) { - basePilotable.drive(0.3*basePilotable.getpitch()/15, 0, 0); + basePilotable.drive(0.3*basePilotable.getpitch()/15, 0); } else { - basePilotable.drive(0, 0, 0); + basePilotable.drive(0, 0); } } diff --git a/src/main/java/frc/robot/commands/Reculer.java b/src/main/java/frc/robot/commands/Reculer.java index 674ef40..46aab87 100644 --- a/src/main/java/frc/robot/commands/Reculer.java +++ b/src/main/java/frc/robot/commands/Reculer.java @@ -5,15 +5,21 @@ package frc.robot.commands; +import java.util.function.DoubleSupplier; + +import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; +import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.CommandBase; import frc.robot.subsystems.BasePilotable; public class Reculer extends CommandBase { BasePilotable basePilotable; + DoubleSupplier distance; /** Creates a new Reculer. */ - public Reculer(BasePilotable basePilotable) { + public Reculer(BasePilotable basePilotable, DoubleSupplier distance) { this.basePilotable = basePilotable; + this.distance = distance; // Use addRequirements() here to declare subsystem dependencies. addRequirements(basePilotable); } @@ -27,7 +33,7 @@ public class Reculer extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - basePilotable.drive(SmartDashboard.getNumber("vitesse auto", -0.3), 0, 0); + basePilotable.drive(-0.3,0); } // Called once the command ends or is interrupted. @@ -37,6 +43,6 @@ public class Reculer extends CommandBase { // Returns true when the command should end. @Override public boolean isFinished() { - return false; + return basePilotable.distance()