From 5fa7666976fa2326c6a492bc01fa97ebc55f840a Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 5 Dec 2023 18:18:45 -0500 Subject: [PATCH 1/3] cvbn --- src/main/java/frc/robot/RobotContainer.java | 10 +++-- .../java/frc/robot/commands/LancerTest.java | 6 +++ .../java/frc/robot/commands/LanceurAuto.java | 37 +++++++++++++++++++ src/main/java/frc/robot/subsystems/Drive.java | 21 ++++++++++- 4 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/main/java/frc/robot/commands/LanceurAuto.java diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 9f25d03..9ec8880 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -3,6 +3,7 @@ // the WPILib BSD license file in the root directory of this project. package frc.robot; +import edu.wpi.first.cameraserver.CameraServer; import edu.wpi.first.math.MathUtil; import edu.wpi.first.networktables.GenericEntry; import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts; @@ -10,6 +11,7 @@ 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.ParallelCommandGroup; import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; import edu.wpi.first.wpilibj2.command.button.CommandJoystick; @@ -39,6 +41,7 @@ public class RobotContainer { ShuffleboardLayout forces = Shuffleboard.getTab("Dashboard") .getLayout("forces", BuiltInLayouts.kList) .withSize(3, 7); + GenericEntry force1 = forces.add("Force1", 2).getEntry(); GenericEntry force2 = forces.add("Force2", 4).getEntry(); GenericEntry force3 = forces.add("Force3", 6).getEntry(); @@ -76,9 +79,8 @@ public class RobotContainer { public Command getAutonomousCommand() { - return null; - /* new SequentialCommandGroup(new Avancer(drive), new Force7(lanceur, force7, accumulateur) - , new Lancer(lanceur, accumulateur, force1), new Reculer(drive)); - */ } + return new SequentialCommandGroup(new ParallelCommandGroup(new LancerTest(lanceur).withTimeout(5),new accumulateurtest(accumulateur).withTimeout(5)) + ,new Avancer(drive)); + } } diff --git a/src/main/java/frc/robot/commands/LancerTest.java b/src/main/java/frc/robot/commands/LancerTest.java index 95eaeb0..03ed1ab 100644 --- a/src/main/java/frc/robot/commands/LancerTest.java +++ b/src/main/java/frc/robot/commands/LancerTest.java @@ -4,13 +4,19 @@ package frc.robot.commands; +import edu.wpi.first.networktables.GenericEntry; +import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; +import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; import edu.wpi.first.wpilibj2.command.CommandBase; import frc.robot.subsystems.Lanceur; public class LancerTest extends CommandBase { + ShuffleboardTab dashboard = Shuffleboard.getTab("Dashboard"); + private Lanceur lanceur; /** Creates a new LancerTest. */ public LancerTest(Lanceur lanceur) { + dashboard.add("vitesse lanceur", 0.5); this.lanceur = lanceur; addRequirements(lanceur); // Use addRequirements() here to declare subsystem dependencies. diff --git a/src/main/java/frc/robot/commands/LanceurAuto.java b/src/main/java/frc/robot/commands/LanceurAuto.java new file mode 100644 index 0000000..72b12f9 --- /dev/null +++ b/src/main/java/frc/robot/commands/LanceurAuto.java @@ -0,0 +1,37 @@ +// 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.Lanceur; + +public class LanceurAuto extends CommandBase { + private Lanceur lanceur; + /** Creates a new LanceurAuto. */ + public LanceurAuto(Lanceur lanceur) { + this.lanceur = lanceur; + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + lanceur.setPID(0, 0, 0); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // 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 false; + } +} diff --git a/src/main/java/frc/robot/subsystems/Drive.java b/src/main/java/frc/robot/subsystems/Drive.java index c0aa314..1032e73 100644 --- a/src/main/java/frc/robot/subsystems/Drive.java +++ b/src/main/java/frc/robot/subsystems/Drive.java @@ -7,17 +7,32 @@ package frc.robot.subsystems; import java.io.File; import java.io.IOException; +import com.revrobotics.CANSparkMax; +import com.revrobotics.CANSparkMaxLowLevel.MotorType; + import edu.wpi.first.math.geometry.Translation2d; import edu.wpi.first.math.kinematics.SwerveModulePosition; import edu.wpi.first.wpilibj.Filesystem; +import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; +import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.Constants; import swervelib.SwerveDrive; +import swervelib.encoders.CanAndCoderSwerve; import swervelib.parser.SwerveParser; public class Drive extends SubsystemBase { + ShuffleboardTab dashboard = Shuffleboard.getTab("Dashboard"); SwerveDrive swerveDrive; File swerveJsonDirectory = new File(Filesystem.getDeployDirectory(),"swerve"); - + /* final CanAndCoderSwerve avantdroitdrive = new CanAndCoderSwerve(Constants.avantdroitDrive); + final CanAndCoderSwerve avantgauchedrive = new CanAndCoderSwerve(Constants.avantgaucheDrive); + final CanAndCoderSwerve arrieregauchedrive = new CanAndCoderSwerve(Constants.arrieregaucheDrive); + final CanAndCoderSwerve arrieredroitdrive = new CanAndCoderSwerve(Constants.arrieredroitDrive); + final CanAndCoderSwerve avantdroitangle = new CanAndCoderSwerve(Constants.avantdroitAngle); + final CanAndCoderSwerve avantgaucheangle = new CanAndCoderSwerve(Constants.avantgaucheAngle); + final CanAndCoderSwerve arrieregaucheangle = new CanAndCoderSwerve(Constants.arrieregaucheAngle); + final CanAndCoderSwerve arrieredroitangle = new CanAndCoderSwerve(Constants.arrieredroitAngle); */ public void drive(double x, double y, double zRotation){ swerveDrive.drive(new Translation2d(x, y), zRotation, false, false); } @@ -25,6 +40,7 @@ public class Drive extends SubsystemBase { /** Creates a new Drive. */ public Drive() { + try { this.swerveDrive = new SwerveParser(swerveJsonDirectory).createSwerveDrive(); } catch (IOException e) { @@ -34,6 +50,9 @@ public class Drive extends SubsystemBase { public SwerveModulePosition[] distance(){ return swerveDrive.getModulePositions(); } +public void reset(){ + +} @Override public void periodic() { // This method will be called once per scheduler run From c214822ac6d56b372d9f24af9da534a6bcf1526a Mon Sep 17 00:00:00 2001 From: OlivierDubois Date: Tue, 5 Dec 2023 19:09:54 -0500 Subject: [PATCH 2/3] mettre des choses dans le dashboard(ca marche) --- src/main/java/frc/robot/RobotContainer.java | 3 ++- src/main/java/frc/robot/commands/Avancer.java | 3 ++- src/main/java/frc/robot/commands/Reculer.java | 3 ++- src/main/java/frc/robot/subsystems/Drive.java | 22 +++++++++++++++++++ .../java/frc/robot/subsystems/Lanceur.java | 17 ++++++++------ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 9df979c..abb1545 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -38,7 +38,8 @@ public class RobotContainer { ShuffleboardTab dashboard = Shuffleboard.getTab("Dashboard"); ShuffleboardLayout forces = Shuffleboard.getTab("Dashboard") .getLayout("forces", BuiltInLayouts.kList) - .withSize(3, 7); + .withSize(1, 7) + .withPosition(1, 0); GenericEntry force1 = forces.add("Force1", 2).getEntry(); GenericEntry force2 = forces.add("Force2", 4).getEntry(); GenericEntry force3 = forces.add("Force3", 6).getEntry(); diff --git a/src/main/java/frc/robot/commands/Avancer.java b/src/main/java/frc/robot/commands/Avancer.java index c0ee5c7..0e7c1f1 100644 --- a/src/main/java/frc/robot/commands/Avancer.java +++ b/src/main/java/frc/robot/commands/Avancer.java @@ -16,7 +16,8 @@ public class Avancer extends CommandBase { ShuffleboardTab dashboard = Shuffleboard.getTab("Dashboard"); ShuffleboardLayout avancer = Shuffleboard.getTab("Dashboard") .getLayout("Avancer", BuiltInLayouts.kList) - .withSize(3, 3); + .withSize(1, 4) + .withPosition(4, 0); /** Creates a new Avancer. */ public Avancer(Drive drive) { avancer.add("vitesse x", 1); diff --git a/src/main/java/frc/robot/commands/Reculer.java b/src/main/java/frc/robot/commands/Reculer.java index b0303ab..9571c64 100644 --- a/src/main/java/frc/robot/commands/Reculer.java +++ b/src/main/java/frc/robot/commands/Reculer.java @@ -16,7 +16,8 @@ public class Reculer extends CommandBase { ShuffleboardTab dashboard = Shuffleboard.getTab("Dashboard"); ShuffleboardLayout reculer = Shuffleboard.getTab("Dashboard") .getLayout("Reculer", BuiltInLayouts.kList) - .withSize(3, 3); + .withSize(1, 4) + .withPosition(6,0); /** Creates a new Reculer. */ public Reculer(Drive drive) { reculer.add("vitesse x", 1); diff --git a/src/main/java/frc/robot/subsystems/Drive.java b/src/main/java/frc/robot/subsystems/Drive.java index c0aa314..c49c6c0 100644 --- a/src/main/java/frc/robot/subsystems/Drive.java +++ b/src/main/java/frc/robot/subsystems/Drive.java @@ -7,14 +7,28 @@ package frc.robot.subsystems; import java.io.File; import java.io.IOException; +import edu.wpi.first.cameraserver.CameraServer; import edu.wpi.first.math.geometry.Translation2d; import edu.wpi.first.math.kinematics.SwerveModulePosition; import edu.wpi.first.wpilibj.Filesystem; +import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts; +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.SubsystemBase; import swervelib.SwerveDrive; import swervelib.parser.SwerveParser; public class Drive extends SubsystemBase { + ShuffleboardTab dashboard = Shuffleboard.getTab("Dashboard"); + ShuffleboardLayout avancer = Shuffleboard.getTab("Dashboard") + .getLayout("Avancer", BuiltInLayouts.kList) + .withSize(1, 4) + .withPosition(4, 0); + ShuffleboardLayout reculer = Shuffleboard.getTab("Dashboard") + .getLayout("Reculer", BuiltInLayouts.kList) + .withSize(1, 4) + .withPosition(3,0); SwerveDrive swerveDrive; File swerveJsonDirectory = new File(Filesystem.getDeployDirectory(),"swerve"); @@ -25,6 +39,14 @@ public class Drive extends SubsystemBase { /** Creates a new Drive. */ public Drive() { + reculer.add("vitesse x", 1); + reculer.add("vitesse y", 2); + reculer.add("vitesse z", 3); + reculer.add("distance", 4); + avancer.add("vitesse x", 1); + avancer.add("vitesse y", 2); + avancer.add("vitesse z", 3); + avancer.add("distance", 4); try { this.swerveDrive = new SwerveParser(swerveJsonDirectory).createSwerveDrive(); } catch (IOException e) { diff --git a/src/main/java/frc/robot/subsystems/Lanceur.java b/src/main/java/frc/robot/subsystems/Lanceur.java index dddd1b3..7dd7e59 100644 --- a/src/main/java/frc/robot/subsystems/Lanceur.java +++ b/src/main/java/frc/robot/subsystems/Lanceur.java @@ -7,6 +7,7 @@ package frc.robot.subsystems; import com.revrobotics.CANSparkMax; import com.revrobotics.CANSparkMaxLowLevel.MotorType; +import edu.wpi.first.networktables.GenericEntry; import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts; import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; @@ -18,14 +19,16 @@ public class Lanceur extends SubsystemBase { ShuffleboardTab dash2 = Shuffleboard.getTab("Dashboard2.0"); ShuffleboardTab dashboard = Shuffleboard.getTab("Dashboard"); - //ShuffleboardLayout pid = Shuffleboard.getTab("Dashboard") - //.getLayout("Pid", BuiltInLayouts.kList) - //.withSize(3, 7); + ShuffleboardLayout pid = Shuffleboard.getTab("Dashboard") + .getLayout("Pid", BuiltInLayouts.kList) + .withSize(1, 3) + .withPosition(0, 0); + private GenericEntry p = pid.add("p", 1).getEntry(); + public Lanceur(){ - dash2.add("test", 1); - dashboard.add("p", 1); - dashboard.add("i", 2); - dashboard.add("d", 3); + double P = p.getDouble(1.0); + pid.add("i", 2).getEntry(); + pid.add("d", 3).getEntry(); } final CANSparkMax lanceur = new CANSparkMax(Constants.lanceur, MotorType.kBrushless); From 05891f1a01ea7f8441ed2bbb0c23abaaf03cbea6 Mon Sep 17 00:00:00 2001 From: OlivierDubois Date: Tue, 5 Dec 2023 19:17:00 -0500 Subject: [PATCH 3/3] enlerver ,g --- src/main/java/frc/robot/commands/Force1.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/commands/Force1.java b/src/main/java/frc/robot/commands/Force1.java index 31d2ae0..6496c62 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) { dashboard.add("vitesse lanceur", 0.5); this.lanceur = lanceur; addRequirements(lanceur);