This commit is contained in:
EdwardFaucher 2023-03-11 09:56:59 -05:00
parent 23806ebfa2
commit 49689b14f1
12 changed files with 105 additions and 41 deletions

View File

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

View File

@ -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;

View File

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

View File

@ -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.

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.
@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.

View File

@ -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.

View File

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

View File

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

View File

@ -32,7 +32,7 @@ public class Tape 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.

View File

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

View File

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