diff --git a/bin/main/frc/robot/commands/BrakeFerme.class b/bin/main/frc/robot/commands/BrakeFerme.class new file mode 100644 index 0000000..9911767 Binary files /dev/null and b/bin/main/frc/robot/commands/BrakeFerme.class differ diff --git a/bin/main/frc/robot/commands/BrakeOuvre.class b/bin/main/frc/robot/commands/BrakeOuvre.class new file mode 100644 index 0000000..17058de Binary files /dev/null and b/bin/main/frc/robot/commands/BrakeOuvre.class differ diff --git a/bin/main/frc/robot/subsystems/BasePilotable.class b/bin/main/frc/robot/subsystems/BasePilotable.class new file mode 100644 index 0000000..a2332e1 Binary files /dev/null and b/bin/main/frc/robot/subsystems/BasePilotable.class differ diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 196a748..450a43b 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -5,28 +5,24 @@ public class Constants { public static int avantgauche = 1; public static int arrieredroit = 2; public static int arrieregauche = 3; + public static int BrasTelescopique = 4; + + //moteur gris public static int leverGratte = 0; public static int baisserGratte = 1; - public static int BrasTelescopique = 5; + // pneumatique public static int pistonpinceouvre = 0; public static int pistonpinceferme = 1; public static int actuateur = 2; public static int brakedroit = 3; public static int brakegauche = 4; - // DIO + // DIO Brando public static int limitbd = 0; public static int limitbg = 2; public static int limithd = 3; public static int limithg = 1; - - - - - - - - } + \ No newline at end of file diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index de2c9d0..cccb81d 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -6,6 +6,25 @@ package frc.robot; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; +//subsystems +import frc.robot.subsystems.BasePilotable; +import frc.robot.subsystems.Gratte; +import frc.robot.subsystems.bras.BrasTelescopique; +import frc.robot.subsystems.bras.Pince; +import frc.robot.subsystems.bras.Pivot; +import frc.robot.subsystems.Limelight; +// command +import frc.robot.commands.BrakeFerme; +import frc.robot.commands.BrakeOuvre; +import frc.robot.commands.GratteBaisser; +import frc.robot.commands.GratteMonte; +import frc.robot.commands.Gyro; +import frc.robot.commands.bras.FermePince; +import frc.robot.commands.bras.OuvrePince; +import frc.robot.commands.bras.PivotBrasRentre; +import frc.robot.commands.bras.PivoteBrasBas; +import frc.robot.commands.bras.PivoteBrasHaut; +import frc.robot.commands.bras.PivoteBrasMilieux; public class RobotContainer { public RobotContainer() { diff --git a/src/main/java/frc/robot/commands/StablePlateform.java b/src/main/java/frc/robot/commands/BrakeFerme.java similarity index 65% rename from src/main/java/frc/robot/commands/StablePlateform.java rename to src/main/java/frc/robot/commands/BrakeFerme.java index f223510..cd2be53 100644 --- a/src/main/java/frc/robot/commands/StablePlateform.java +++ b/src/main/java/frc/robot/commands/BrakeFerme.java @@ -5,20 +5,30 @@ package frc.robot.commands; import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.BasePilotable; -public class StablePlateform extends CommandBase { - /** Creates a new StablePlateform. */ - public StablePlateform() { +public class BrakeFerme extends CommandBase { + + private BasePilotable basePilotable; + + /** Creates a new BrakeFerme. */ + public BrakeFerme(BasePilotable basePilotable) { + this.basePilotable = basePilotable; // Use addRequirements() here to declare subsystem dependencies. + addRequirements(basePilotable); } // Called when the command is initially scheduled. @Override - public void initialize() {} + public void initialize() { + basePilotable.BrakeFerme(); + } // Called every time the scheduler runs while the command is scheduled. @Override - public void execute() {} + public void execute() { + + } // Called once the command ends or is interrupted. @Override diff --git a/src/main/java/frc/robot/commands/BrakeOuvre.java b/src/main/java/frc/robot/commands/BrakeOuvre.java new file mode 100644 index 0000000..96b0997 --- /dev/null +++ b/src/main/java/frc/robot/commands/BrakeOuvre.java @@ -0,0 +1,42 @@ +// 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.BasePilotable; + +public class BrakeOuvre extends CommandBase { + + private BasePilotable basePilotable; + + /** Creates a new BrakeFerme. */ + public BrakeOuvre(BasePilotable basePilotable) { + this.basePilotable = basePilotable; + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(basePilotable); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + basePilotable.BrakeOuvre(); + } + + // 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/commands/Gyro.java b/src/main/java/frc/robot/commands/Gyro.java new file mode 100644 index 0000000..8492e0d --- /dev/null +++ b/src/main/java/frc/robot/commands/Gyro.java @@ -0,0 +1,49 @@ +// 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.BasePilotable; + +public class Gyro extends CommandBase { + private BasePilotable basePilotable; + /** Creates a new Gyro. */ + public Gyro(BasePilotable basePilotable) { + this.basePilotable = basePilotable; + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(basePilotable); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() {} + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + if(basePilotable.getpitch()<10) + { + basePilotable.drive(0.4, 0, 0); + } + else if(basePilotable.getpitch()>-10) + { + basePilotable.drive(-0.4, 0, 0); + } + else + { + basePilotable.drive(0, 0, 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 false; + } +} diff --git a/src/main/java/frc/robot/commands/bras/PivotBrasRentre.java b/src/main/java/frc/robot/commands/bras/PivotBrasRentre.java new file mode 100644 index 0000000..9624497 --- /dev/null +++ b/src/main/java/frc/robot/commands/bras/PivotBrasRentre.java @@ -0,0 +1,47 @@ +// 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.bras; + +import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.bras.BrasTelescopique; +import frc.robot.subsystems.bras.Pivot; + +public class PivotBrasRentre extends CommandBase { + private BrasTelescopique brasTelescopique; + private Pivot pivot; + /** Creates a new PivotBrasRentre. */ + public PivotBrasRentre(BrasTelescopique brasTelescopique, Pivot pivot) { + this.brasTelescopique = brasTelescopique; + this.pivot = pivot; + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(brasTelescopique); + addRequirements(pivot); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() {} + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + if(brasTelescopique.distance()>1){ + brasTelescopique.AvanceRecule(0.5); + } + if (pivot.distance()>1){ + pivot.monteDescendre(0.5); + } + } + + // 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/commands/bras/PivoteBrasBas.java b/src/main/java/frc/robot/commands/bras/PivoteBrasBas.java index 03a1793..038ec51 100644 --- a/src/main/java/frc/robot/commands/bras/PivoteBrasBas.java +++ b/src/main/java/frc/robot/commands/bras/PivoteBrasBas.java @@ -4,12 +4,22 @@ package frc.robot.commands.bras; + + import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.bras.BrasTelescopique; +import frc.robot.subsystems.bras.Pivot; public class PivoteBrasBas extends CommandBase { + private BrasTelescopique brasTelescopique; + private Pivot pivot; /** Creates a new PivoteBrasBas. */ - public PivoteBrasBas() { + public PivoteBrasBas(BrasTelescopique brasTelescopique, Pivot pivot) { + this.brasTelescopique = brasTelescopique; + this.pivot = pivot; // Use addRequirements() here to declare subsystem dependencies. + addRequirements(brasTelescopique); + addRequirements(pivot); } // Called when the command is initially scheduled. @@ -18,12 +28,32 @@ public class PivoteBrasBas extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override - public void execute() {} + public void execute() { + if(brasTelescopique.distance()<10){ + brasTelescopique.AvanceRecule(0.5); + } + else if(brasTelescopique.distance()>11) { + brasTelescopique.AvanceRecule(-0.5); + } + else { + brasTelescopique.AvanceRecule(0); + } + if (pivot.distance()<10){ + pivot.monteDescendre(0.5); + } + else if(pivot.distance()>11) { + pivot.monteDescendre(-0.5); + } + else{ + pivot.monteDescendre(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() { diff --git a/src/main/java/frc/robot/commands/bras/PivoteBrasHaut.java b/src/main/java/frc/robot/commands/bras/PivoteBrasHaut.java index 4932ad2..2ba3c74 100644 --- a/src/main/java/frc/robot/commands/bras/PivoteBrasHaut.java +++ b/src/main/java/frc/robot/commands/bras/PivoteBrasHaut.java @@ -5,11 +5,19 @@ package frc.robot.commands.bras; import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.bras.BrasTelescopique; +import frc.robot.subsystems.bras.Pivot; public class PivoteBrasHaut extends CommandBase { + private BrasTelescopique brasTelescopique; + private Pivot pivot; /** Creates a new PivoteBrasHaut. */ - public PivoteBrasHaut() { + public PivoteBrasHaut(BrasTelescopique brasTelescopique, Pivot pivot) { + this.brasTelescopique = brasTelescopique; + this.pivot = pivot; // Use addRequirements() here to declare subsystem dependencies. + addRequirements(brasTelescopique); + addRequirements(pivot); } // Called when the command is initially scheduled. @@ -18,7 +26,26 @@ public class PivoteBrasHaut extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override - public void execute() {} + public void execute() { + if(brasTelescopique.distance()<10){ + brasTelescopique.AvanceRecule(0.5); + } + else if(brasTelescopique.distance()>11) { + brasTelescopique.AvanceRecule(-0.5); + } + else { + brasTelescopique.AvanceRecule(0); + } + if (pivot.distance()<10){ + pivot.monteDescendre(0.5); + } + else if(pivot.distance()>11) { + pivot.monteDescendre(-0.5); + } + else{ + pivot.monteDescendre(0); + } + } // Called once the command ends or is interrupted. @Override diff --git a/src/main/java/frc/robot/commands/bras/PivoteBrasMilieux.java b/src/main/java/frc/robot/commands/bras/PivoteBrasMilieux.java index be7e44e..da8939b 100644 --- a/src/main/java/frc/robot/commands/bras/PivoteBrasMilieux.java +++ b/src/main/java/frc/robot/commands/bras/PivoteBrasMilieux.java @@ -5,11 +5,19 @@ package frc.robot.commands.bras; import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.bras.BrasTelescopique; +import frc.robot.subsystems.bras.Pivot; public class PivoteBrasMilieux extends CommandBase { + private BrasTelescopique brasTelescopique; + private Pivot pivot; /** Creates a new PivoteBrasMilieux. */ - public PivoteBrasMilieux() { + public PivoteBrasMilieux(BrasTelescopique brasTelescopique, Pivot pivot) { + this.brasTelescopique = brasTelescopique; + this.pivot = pivot; // Use addRequirements() here to declare subsystem dependencies. + addRequirements(brasTelescopique); + addRequirements(pivot); } // Called when the command is initially scheduled. @@ -18,7 +26,27 @@ public class PivoteBrasMilieux extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override - public void execute() {} + public void execute() { + if(brasTelescopique.distance()<10){ + brasTelescopique.AvanceRecule(0.5); + } + else if(brasTelescopique.distance()>11) { + brasTelescopique.AvanceRecule(-0.5); + } + else { + brasTelescopique.AvanceRecule(0); + } + if (pivot.distance()<10){ + pivot.monteDescendre(0.5); + } + else if(pivot.distance()>11) { + pivot.monteDescendre(-0.5); + } + else{ + pivot.monteDescendre(0); + } + } + // Called once the command ends or is interrupted. @Override diff --git a/src/main/java/frc/robot/subsystems/BasePilotable.java b/src/main/java/frc/robot/subsystems/BasePilotable.java index e7e12fc..9b1eb24 100644 --- a/src/main/java/frc/robot/subsystems/BasePilotable.java +++ b/src/main/java/frc/robot/subsystems/BasePilotable.java @@ -4,11 +4,12 @@ package frc.robot.subsystems; +import com.kauailabs.navx.frc.AHRS; import com.revrobotics.CANSparkMax; import com.revrobotics.CANSparkMaxLowLevel.MotorType; - import edu.wpi.first.wpilibj.DoubleSolenoid; import edu.wpi.first.wpilibj.PneumaticsModuleType; +import edu.wpi.first.wpilibj.DoubleSolenoid.Value; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; import edu.wpi.first.wpilibj2.command.SubsystemBase; @@ -22,10 +23,16 @@ public class BasePilotable extends SubsystemBase { final MotorControllerGroup droit = new MotorControllerGroup(avantdroit, arrieredroit); final MotorControllerGroup gauche = new MotorControllerGroup(avantgauche, arrieregauche); final DifferentialDrive drive = new DifferentialDrive(gauche, droit); - final DoubleSolenoid brakedroit = new DoubleSolenoid(PneumaticsModuleType.CTREPCM,Constants.pistonpinceouvre, Constants.pistonpinceferme); - final DoubleSolenoid brakegauche = new DoubleSolenoid(PneumaticsModuleType.CTREPCM,Constants.pistonpinceouvre, Constants.pistonpinceferme); - - public void drive(double xSpeed, double zRotation){ + //piston + private DoubleSolenoid brakedroit = new DoubleSolenoid(PneumaticsModuleType.CTREPCM,Constants.brakedroit, Constants.brakedroit); + private DoubleSolenoid brakegauche = new DoubleSolenoid(PneumaticsModuleType.CTREPCM,Constants.brakegauche, Constants.brakegauche); + //gyro + private AHRS gyroscope = new AHRS();public double getangle() {return gyroscope.getAngle();} + public double getpitch() { + return gyroscope.getPitch(); + } + + public void drive(double xSpeed, double zRotation, int i){ drive.arcadeDrive(xSpeed, zRotation); } public double distance(){ @@ -40,7 +47,14 @@ public class BasePilotable extends SubsystemBase { arrieredroit.getEncoder().setPosition(0); arrieregauche.getEncoder().setPosition(0); } - +public void BrakeOuvre(){ + brakedroit.set(Value.kForward); + brakegauche.set(Value.kForward); +} +public void BrakeFerme(){ + brakedroit.set(Value.kReverse); + brakegauche.set(Value.kReverse); +} /** Creates a new BasePilotable. */ public BasePilotable() { droit.setInverted(true); diff --git a/src/main/java/frc/robot/subsystems/Gratte.java b/src/main/java/frc/robot/subsystems/Gratte.java index 58c7d11..9bc4bb1 100644 --- a/src/main/java/frc/robot/subsystems/Gratte.java +++ b/src/main/java/frc/robot/subsystems/Gratte.java @@ -9,8 +9,6 @@ import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; import edu.wpi.first.wpilibj.DigitalInput; import frc.robot.Constants; - - public class Gratte extends SubsystemBase { private WPI_TalonSRX Gratted = new WPI_TalonSRX(Constants.leverGratte); private WPI_TalonSRX Gratteg = new WPI_TalonSRX(Constants.baisserGratte);