Merge branch 'main' of https:re

This commit is contained in:
Olivier Dubois 2023-03-13 18:35:55 -04:00
commit ee17a7cfad
12 changed files with 146 additions and 58 deletions

View File

@ -1,7 +1,8 @@
{ {
"NTProvider": { "NTProvider": {
"types": { "types": {
"/FMSInfo": "FMSInfo" "/FMSInfo": "FMSInfo",
"/Shuffleboard/teb/auto/choix hauteur": "String Chooser"
} }
}, },
"NetworkTables": { "NetworkTables": {

View File

@ -6,24 +6,24 @@ public class Constants {
public static int arrieredroit = 3; public static int arrieredroit = 3;
public static int arrieregauche = 5; public static int arrieregauche = 5;
public static int BrasTelescopique = 2; public static int BrasTelescopique = 2;
public static int pivot = 0; public static int pivot = 6;
//moteur //moteur
public static int baiserGratte = 8;
public static int leverGratte = 0; public static int leverGratte = 0;
public static int baiserGratte = 1;
<<<<<<< HEAD
public static int baisserGratte = 2; public static int baisserGratte = 2;
=======
>>>>>>> 23806ebfa2db43d63673f9b4cfc37aa3b9b23491
// pneumatique // pneumatique
public static int pistonpinceouvre = 0; public static int pistonpinceouvre = 0;
public static int pistonpinceferme = 1; public static int pistonpinceferme = 1;
public static int actuateur = 8; public static int actuateur = 2;
public static int brakedroit = 3; public static int brakedroit = 3;
public static int brakegauche = 4; public static int brakegauche = 4;
public static int brakewinchf = 5; public static int brakewinchf = 5;
public static int brakewinchb = 5; public static int brakewinchb = 6;
// DIO // DIO
public static int limitbd = 0; public static int limitbd = 0;
public static int limitbg = 2; public static int limitbg = 2;

View File

@ -3,20 +3,22 @@
// the WPILib BSD license file in the root directory of this project. // the WPILib BSD license file in the root directory of this project.
package frc.robot; package frc.robot;
import org.photonvision.estimation.CameraTargetRelation; import java.util.Map;
import edu.wpi.first.cameraserver.CameraServer; import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
import java.util.Map;
import edu.wpi.first.networktables.GenericEntry; 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.shuffleboard.ShuffleboardLayout;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
<<<<<<< HEAD
//subsystems //subsystems
import frc.robot.subsystems.BasePilotable; import frc.robot.subsystems.BasePilotable;
@ -26,6 +28,10 @@ import frc.robot.subsystems.bras.Pince;
import frc.robot.subsystems.bras.Pivot; import frc.robot.subsystems.bras.Pivot;
import frc.robot.subsystems.Limelight; import frc.robot.subsystems.Limelight;
import frc.robot.commands.Apriltag; import frc.robot.commands.Apriltag;
=======
import frc.robot.commands.Apriltag;
import frc.robot.commands.Avancer;
>>>>>>> de5b5213cba2b66ec7b8cc5e73c1bf9123dd259b
// command // command
import frc.robot.commands.BrakeFerme; import frc.robot.commands.BrakeFerme;
import frc.robot.commands.BrakeOuvre; import frc.robot.commands.BrakeOuvre;
@ -44,12 +50,32 @@ import frc.robot.commands.bras.PivotChercheHaut;
import frc.robot.commands.bras.PivoteBrasBas; import frc.robot.commands.bras.PivoteBrasBas;
import frc.robot.commands.bras.PivoteBrasHaut; import frc.robot.commands.bras.PivoteBrasHaut;
import frc.robot.commands.bras.PivoteBrasMilieux; import frc.robot.commands.bras.PivoteBrasMilieux;
//subsystems
import frc.robot.subsystems.BasePilotable;
import frc.robot.subsystems.Gratte;
import frc.robot.subsystems.Limelight;
import frc.robot.subsystems.bras.BrasTelescopique;
import frc.robot.subsystems.bras.Pince;
import frc.robot.subsystems.bras.Pivot;
public class RobotContainer { public class RobotContainer {
CommandXboxController manette1 = new CommandXboxController(0); CommandXboxController manette1 = new CommandXboxController(0);
CommandXboxController manette2 = new CommandXboxController(1); CommandXboxController manette2 = new CommandXboxController(1);
SendableChooser<String> 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 // subsystems
BasePilotable basePilotable = new BasePilotable(); BasePilotable basePilotable = new BasePilotable();
Gratte gratte = new Gratte(); Gratte gratte = new Gratte();
@ -70,22 +96,17 @@ PivoteBrasBas pivoteBrasBas = new PivoteBrasBas(brasTelescopique, pivot);
PivoteBrasMilieux pivoteBrasMilieux = new PivoteBrasMilieux(brasTelescopique, pivot); PivoteBrasMilieux pivoteBrasMilieux = new PivoteBrasMilieux(brasTelescopique, pivot);
PivoteBrasHaut pivoteBrasHaut = new PivoteBrasHaut(brasTelescopique, pivot); PivoteBrasHaut pivoteBrasHaut = new PivoteBrasHaut(brasTelescopique, pivot);
Cone cone = new Cone(limelight, basePilotable, ()->-manette1.getLeftY()); 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));
PivotChercheBas pivotChercheBas = new PivotChercheBas(brasTelescopique, pivot); PivotChercheBas pivotChercheBas = new PivotChercheBas(brasTelescopique, pivot);
PivotChercheHaut pivotChercheHaut = new PivotChercheHaut(brasTelescopique, pivot); PivotChercheHaut pivotChercheHaut = new PivotChercheHaut(brasTelescopique, pivot);
Cube cube = new Cube(limelight, basePilotable, null); Cube cube = new Cube(limelight, basePilotable, null);
Apriltag aprilTag = new Apriltag(limelight, basePilotable, null); Apriltag aprilTag = new Apriltag(limelight, basePilotable, null);
Tape tape = new Tape(limelight, basePilotable, null); Tape tape = new Tape(limelight, basePilotable, null);
ShuffleboardTab teb = Shuffleboard.getTab("teb");
Reculer reculer = new Reculer(basePilotable);
SendableChooser<String> 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() { public RobotContainer() {
chooser.setDefaultOption(enhaut, enhaut); chooser.setDefaultOption(enhaut, enhaut);
chooser.addOption(enbas, enbas); chooser.addOption(enbas, enbas);
@ -94,38 +115,53 @@ public RobotContainer() {
layoutauto.add("choix hauteur",chooser); layoutauto.add("choix hauteur",chooser);
configureBindings(); configureBindings();
CameraServer.startAutomaticCapture(); CameraServer.startAutomaticCapture();
<<<<<<< HEAD
teb.add (CameraServer.startAutomaticCapture(null, 0)); teb.add (CameraServer.startAutomaticCapture(null, 0));
basePilotable.setDefaultCommand(new RunCommand()-> basePilotable.setDefaultCommand(new RunCommand()->
basePilotable.drive(-manette1.getLeftY(), manette1.getLeftX(), 0)); basePilotable.drive(-manette1.getLeftY(), manette1.getLeftX(), 0));
} }
=======
basePilotable.setDefaultCommand(new RunCommand(() -> {
basePilotable.drive(-manette1.getLeftY(), manette1.getLeftX());
}));
}
>>>>>>> de5b5213cba2b66ec7b8cc5e73c1bf9123dd259b
private void configureBindings() { private void configureBindings() {
// manette 1 // manette 1
manette1.povDown().onTrue(pivoteBrasHaut);
manette1.povUp().onTrue(pivoteBrasBas);
manette1.povLeft().onTrue(pivoteBrasMilieux);
manette1.povRight().onTrue(pivotBrasRentre);
manette1.a().toggleOnTrue(Commands.startEnd(pince::ouvrir, pince::fermer,pince)); manette1.a().toggleOnTrue(Commands.startEnd(pince::ouvrir, pince::fermer,pince));
manette1.x().toggleOnTrue(Commands.startEnd(basePilotable::BrakeFerme,basePilotable::BrakeOuvre,basePilotable)); manette1.x().toggleOnTrue(Commands.startEnd(basePilotable::BrakeFerme,basePilotable::BrakeOuvre,basePilotable));
manette1.y().whileTrue(gyro); manette1.leftBumper().toggleOnTrue(aprilTag);
manette1.start().toggleOnTrue(Commands.startEnd(basePilotable::resetGyro, basePilotable::resetGyro, basePilotable)); manette1.rightBumper().toggleOnTrue(tape);
manette1.povUp().onTrue(pivoteBrasHaut);
manette1.povDown().onTrue(pivoteBrasBas);
manette1.povRight().onTrue(pivoteBrasMilieux);
manette1.povLeft().onTrue(pivotBrasRentre);
//manette 2
manette2.povRight().onTrue(pivotChercheBas);
manette2.povLeft().onTrue(pivotChercheHaut);
manette2.rightBumper().toggleOnTrue(cube);
manette2.leftBumper().toggleOnTrue(cone);
manette2.y().whileTrue(gyro);
manette2.start().onTrue(new InstantCommand(basePilotable::resetGyro));
manette2.b().onTrue(Commands.either(gratteBaisser, gratteMonte, gratte::getenHaut));
} }
public Command getAutonomousCommand() { public Command getAutonomousCommand() {
chooser.getSelected(); chooser.getSelected();
autobalance.getBoolean(true); autobalance.getBoolean(true);
return new SequentialCommandGroup( return new SequentialCommandGroup(
Commands.either(gyro, Commands.none(),()-> autobalance.getBoolean(true)),
Commands.either(reculer, Commands.none(),()-> autosortir.getBoolean(true)),
Commands.select(Map.ofEntries( Commands.select(Map.ofEntries(
Map.entry(enhaut,pivoteBrasHaut), Map.entry(enhaut,pivoteBrasHaut),
Map.entry(aumilieux,null), Map.entry(aumilieux,pivoteBrasMilieux),
Map.entry(enbas,null), Map.entry(enbas,pivoteBrasBas),
Map.entry(nulpart,null) Map.entry(nulpart,pivotBrasRentre)
), chooser::getSelected) ), 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))
).deadlineWith(Commands.waitSeconds(14)).andThen(brakeOuvre);
} }

View File

@ -32,7 +32,7 @@ public class Apriltag extends CommandBase {
// Called every time the scheduler runs while the command is scheduled. // Called every time the scheduler runs while the command is scheduled.
@Override @Override
public void execute() { public void execute() {
basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw(), 0); basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw());
} }
// Called once the command ends or is interrupted. // Called once the command ends or is interrupted.

View File

@ -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();
}
}

View File

@ -32,7 +32,7 @@ public class Cone extends CommandBase {
// Called every time the scheduler runs while the command is scheduled. // Called every time the scheduler runs while the command is scheduled.
@Override @Override
public void execute() { public void execute() {
basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw(), 0); basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw());
} }
// Called once the command ends or is interrupted. // Called once the command ends or is interrupted.

View File

@ -32,7 +32,7 @@ public class Cube extends CommandBase {
// Called every time the scheduler runs while the command is scheduled. // Called every time the scheduler runs while the command is scheduled.
@Override @Override
public void execute() { public void execute() {
basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw(), 0); basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw());
} }
// Called once the command ends or is interrupted. // Called once the command ends or is interrupted.

View File

@ -30,20 +30,20 @@ public class Gyro extends CommandBase {
public void execute() { public void execute() {
if(basePilotable.getpitch()>10) 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) else if(basePilotable.getpitch()<-10)
{ {
basePilotable.drive(0.3*basePilotable.getpitch()/12, 0, 0); basePilotable.drive(0.3*basePilotable.getpitch()/12, 0);
basePilotable.drive(0.3*basePilotable.getpitch()/15, 0, 0); basePilotable.drive(0.3*basePilotable.getpitch()/15, 0);
} }
else if(basePilotable.getpitch()<-4) else if(basePilotable.getpitch()<-4)
{ {
basePilotable.drive(0.3*basePilotable.getpitch()/15, 0, 0); basePilotable.drive(0.3*basePilotable.getpitch()/15, 0);
} }
else else
{ {
basePilotable.drive(0, 0, 0); basePilotable.drive(0, 0);
} }
} }

View File

@ -5,15 +5,21 @@
package frc.robot.commands; 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.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase; import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.BasePilotable; import frc.robot.subsystems.BasePilotable;
public class Reculer extends CommandBase { public class Reculer extends CommandBase {
BasePilotable basePilotable; BasePilotable basePilotable;
DoubleSupplier distance;
/** Creates a new Reculer. */ /** Creates a new Reculer. */
public Reculer(BasePilotable basePilotable) { public Reculer(BasePilotable basePilotable, DoubleSupplier distance) {
this.basePilotable = basePilotable; this.basePilotable = basePilotable;
this.distance = distance;
// Use addRequirements() here to declare subsystem dependencies. // Use addRequirements() here to declare subsystem dependencies.
addRequirements(basePilotable); addRequirements(basePilotable);
} }
@ -27,7 +33,7 @@ public class Reculer extends CommandBase {
// Called every time the scheduler runs while the command is scheduled. // Called every time the scheduler runs while the command is scheduled.
@Override @Override
public void execute() { 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. // Called once the command ends or is interrupted.
@ -37,6 +43,6 @@ public class Reculer extends CommandBase {
// Returns true when the command should end. // Returns true when the command should end.
@Override @Override
public boolean isFinished() { public boolean isFinished() {
return false; return basePilotable.distance()<distance.getAsDouble();
} }
} }

View File

@ -32,7 +32,7 @@ public class Tape extends CommandBase {
// Called every time the scheduler runs while the command is scheduled. // Called every time the scheduler runs while the command is scheduled.
@Override @Override
public void execute() { public void execute() {
basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw(), 0); basePilotable.drive(doubleSupplier.getAsDouble(), limelight.getYaw());
} }
// Called once the command ends or is interrupted. // Called once the command ends or is interrupted.

View File

@ -42,7 +42,7 @@ public class BasePilotable extends SubsystemBase {
return gyroscope.getPitch(); return gyroscope.getPitch();
} }
public void drive(double xSpeed, double zRotation, int i){ public void drive(double xSpeed, double zRotation){
drive.arcadeDrive(xSpeed, zRotation); drive.arcadeDrive(xSpeed, zRotation);
} }
public double distance(){ public double distance(){
@ -80,6 +80,4 @@ public void BrakeFerme(){
public void periodic() { public void periodic() {
} }
public void drive(double d, double leftX) {
}
} }

View File

@ -26,8 +26,8 @@ public class Pivot extends SubsystemBase {
pivot.set (vitesse); pivot.set (vitesse);
} }
public Pivot(){ public Pivot(){
teb .add ("encodeurpivot",0.1); teb.addDouble("encodeurpivot",this::distance);
teb .add ("limitpivot",0.1); teb .addBoolean ("limitpivot",this::limitpivot);
} }
// encodeur // encodeur
public double distance(){ public double distance(){
@ -47,9 +47,8 @@ public class Pivot extends SubsystemBase {
{
teb.add ("encodeur pivot",0.1);
}
} }