Module fini
This commit is contained in:
@@ -6,13 +6,34 @@ package frc.robot;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.Command;
|
||||
import edu.wpi.first.wpilibj2.command.Commands;
|
||||
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
|
||||
import frc.robot.commands.Aspirer;
|
||||
import frc.robot.commands.DescendreBalyeuse;
|
||||
import frc.robot.commands.DescendreGrimpeur;
|
||||
import frc.robot.commands.Lancer;
|
||||
import frc.robot.commands.MonterBalyeuse;
|
||||
import frc.robot.commands.MonterGrimpeur;
|
||||
import frc.robot.subsystems.Balayeuse;
|
||||
import frc.robot.subsystems.Grimpeur;
|
||||
import frc.robot.subsystems.Lanceur;
|
||||
|
||||
public class RobotContainer {
|
||||
Balayeuse balayeuse = new Balayeuse();
|
||||
Grimpeur grimpeur = new Grimpeur();
|
||||
Lanceur lanceur = new Lanceur();
|
||||
CommandXboxController manette = new CommandXboxController(0);
|
||||
public RobotContainer() {
|
||||
configureBindings();
|
||||
}
|
||||
|
||||
private void configureBindings() {}
|
||||
private void configureBindings() {
|
||||
manette.a().whileTrue(new Lancer(lanceur));
|
||||
manette.rightTrigger().whileTrue(new MonterGrimpeur(grimpeur));
|
||||
manette.leftTrigger().whileTrue(new DescendreGrimpeur(grimpeur));
|
||||
manette.rightBumper().whileTrue(new MonterBalyeuse(balayeuse));
|
||||
manette.leftBumper().whileTrue(new DescendreBalyeuse(balayeuse));
|
||||
manette.b().whileTrue(new Aspirer(balayeuse));
|
||||
}
|
||||
|
||||
public Command getAutonomousCommand() {
|
||||
return Commands.print("No autonomous command configured");
|
||||
|
||||
41
src/main/java/frc/robot/commands/Aspirer.java
Normal file
41
src/main/java/frc/robot/commands/Aspirer.java
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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.Command;
|
||||
import frc.robot.subsystems.Balayeuse;
|
||||
|
||||
/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
|
||||
public class Aspirer extends Command {
|
||||
Balayeuse balayeuse;
|
||||
/** Creates a new Aspirer. */
|
||||
public Aspirer(Balayeuse balayeuse) {
|
||||
this.balayeuse = balayeuse;
|
||||
addRequirements(balayeuse);
|
||||
// Use addRequirements() here to declare subsystem dependencies.
|
||||
}
|
||||
|
||||
// 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() {
|
||||
balayeuse.Balayer(0.5);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
balayeuse.Balayer(0);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
43
src/main/java/frc/robot/commands/DescendreBalyeuse.java
Normal file
43
src/main/java/frc/robot/commands/DescendreBalyeuse.java
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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.Command;
|
||||
import frc.robot.subsystems.Balayeuse;
|
||||
|
||||
/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
|
||||
public class DescendreBalyeuse extends Command {
|
||||
Balayeuse balayeuse;
|
||||
/** Creates a new Descendre. */
|
||||
public DescendreBalyeuse(Balayeuse balayeuse) {
|
||||
this.balayeuse = balayeuse;
|
||||
addRequirements(balayeuse);
|
||||
// Use addRequirements() here to declare subsystem dependencies.
|
||||
}
|
||||
|
||||
// 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(balayeuse.Distance() < 10){
|
||||
balayeuse.Pivoter(-0.2);
|
||||
}
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
balayeuse.Pivoter(0);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
45
src/main/java/frc/robot/commands/DescendreGrimpeur.java
Normal file
45
src/main/java/frc/robot/commands/DescendreGrimpeur.java
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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.Command;
|
||||
import frc.robot.subsystems.Grimpeur;
|
||||
|
||||
/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
|
||||
public class DescendreGrimpeur extends Command {
|
||||
Grimpeur grimpeur;
|
||||
/** Creates a new DescendreGrimpeur. */
|
||||
public DescendreGrimpeur(Grimpeur grimpeur) {
|
||||
this.grimpeur = grimpeur;
|
||||
// Use addRequirements() here to declare subsystem dependencies.
|
||||
}
|
||||
|
||||
// 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(!grimpeur.Limit()){
|
||||
grimpeur.Grimper(-0.5);
|
||||
}
|
||||
else{
|
||||
grimpeur.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
grimpeur.Grimper(0);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
46
src/main/java/frc/robot/commands/Lancer.java
Normal file
46
src/main/java/frc/robot/commands/Lancer.java
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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.Command;
|
||||
import frc.robot.subsystems.Lanceur;
|
||||
|
||||
/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
|
||||
public class Lancer extends Command {
|
||||
Lanceur lanceur;
|
||||
/** Creates a new Lancer. */
|
||||
public Lancer(Lanceur lanceur) {
|
||||
this.lanceur = lanceur;
|
||||
addRequirements(lanceur);
|
||||
// Use addRequirements() here to declare subsystem dependencies.
|
||||
}
|
||||
|
||||
// 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() {
|
||||
double vitesse = 0.8;
|
||||
lanceur.Lancer(vitesse);
|
||||
if(lanceur.Vitesse() >= vitesse){
|
||||
lanceur.Demeler(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
lanceur.Demeler(0);
|
||||
lanceur.Lancer(0);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
46
src/main/java/frc/robot/commands/MonterBalyeuse.java
Normal file
46
src/main/java/frc/robot/commands/MonterBalyeuse.java
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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.Command;
|
||||
import frc.robot.subsystems.Balayeuse;
|
||||
|
||||
/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
|
||||
public class MonterBalyeuse extends Command {
|
||||
Balayeuse balayeuse;
|
||||
/** Creates a new MonterBalyeuse. */
|
||||
public MonterBalyeuse(Balayeuse balayeuse) {
|
||||
this.balayeuse = balayeuse;
|
||||
addRequirements(balayeuse);
|
||||
// Use addRequirements() here to declare subsystem dependencies.
|
||||
}
|
||||
|
||||
// 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(!balayeuse.GetLimiSwtich()){
|
||||
balayeuse.Pivoter(0.2);
|
||||
}
|
||||
else{
|
||||
balayeuse.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
balayeuse.Pivoter(0);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
42
src/main/java/frc/robot/commands/MonterGrimpeur.java
Normal file
42
src/main/java/frc/robot/commands/MonterGrimpeur.java
Normal file
@@ -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.Command;
|
||||
import frc.robot.subsystems.Grimpeur;
|
||||
|
||||
/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
|
||||
public class MonterGrimpeur extends Command {
|
||||
Grimpeur grimpeur;
|
||||
/** Creates a new MonterGrimpeur. */
|
||||
public MonterGrimpeur(Grimpeur grimpeur) {
|
||||
this.grimpeur = grimpeur;
|
||||
// Use addRequirements() here to declare subsystem dependencies.
|
||||
}
|
||||
|
||||
// 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(grimpeur.Position() > 10){
|
||||
grimpeur.Grimper(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
grimpeur.Grimper(0);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
40
src/main/java/frc/robot/subsystems/Balayeuse.java
Normal file
40
src/main/java/frc/robot/subsystems/Balayeuse.java
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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.subsystems;
|
||||
|
||||
import com.revrobotics.spark.SparkFlex;
|
||||
import com.revrobotics.spark.SparkMax;
|
||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
|
||||
public class Balayeuse extends SubsystemBase {
|
||||
SparkFlex Balaye = new SparkFlex(5, MotorType.kBrushless);
|
||||
SparkMax Pivot = new SparkMax(6, MotorType.kBrushless);
|
||||
DigitalInput limit = new DigitalInput(0);
|
||||
public void Balayer(double vitesse){
|
||||
Balaye.set(vitesse);
|
||||
}
|
||||
public void Pivoter(double vitesse){
|
||||
Pivot.set(vitesse);
|
||||
}
|
||||
public double Distance(){
|
||||
return Pivot.getEncoder().getPosition();
|
||||
}
|
||||
public void Reset(){
|
||||
Pivot.getEncoder().setPosition(0);
|
||||
}
|
||||
public boolean GetLimiSwtich(){
|
||||
return limit.get();
|
||||
}
|
||||
/** Creates a new Balayeuse. */
|
||||
public Balayeuse() {}
|
||||
|
||||
@Override
|
||||
public void periodic() {
|
||||
// This method will be called once per scheduler run
|
||||
}
|
||||
}
|
||||
41
src/main/java/frc/robot/subsystems/Grimpeur.java
Normal file
41
src/main/java/frc/robot/subsystems/Grimpeur.java
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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.subsystems;
|
||||
|
||||
import com.revrobotics.spark.SparkMax;
|
||||
import com.revrobotics.spark.config.SparkMaxConfig;
|
||||
import com.revrobotics.spark.SparkBase.PersistMode;
|
||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Spark;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
|
||||
public class Grimpeur extends SubsystemBase {
|
||||
SparkMax grimpeur1 = new SparkMax(8,MotorType.kBrushless);
|
||||
SparkMax grimpeur2 = new SparkMax(9,MotorType.kBrushless);
|
||||
SparkMaxConfig slaveConfig = new SparkMaxConfig();
|
||||
DigitalInput limit = new DigitalInput(1);
|
||||
public void Grimper(double vitesse){
|
||||
grimpeur1.set(vitesse);
|
||||
slaveConfig.follow(grimpeur1, false);
|
||||
grimpeur2.configure(slaveConfig,null,null);
|
||||
}
|
||||
public double Position(){
|
||||
return grimpeur1.getEncoder().getPosition();
|
||||
}
|
||||
public void Reset(){
|
||||
grimpeur1.getEncoder().setPosition(0);
|
||||
}
|
||||
public boolean Limit(){
|
||||
return limit.get();
|
||||
}
|
||||
/** Creates a new Grimpeur. */
|
||||
public Grimpeur() {}
|
||||
|
||||
@Override
|
||||
public void periodic() {
|
||||
// This method will be called once per scheduler run
|
||||
}
|
||||
}
|
||||
38
src/main/java/frc/robot/subsystems/Lanceur.java
Normal file
38
src/main/java/frc/robot/subsystems/Lanceur.java
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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.subsystems;
|
||||
|
||||
import com.revrobotics.spark.SparkFlex;
|
||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||
import com.revrobotics.spark.config.SparkMaxConfig;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
|
||||
public class Lanceur extends SubsystemBase {
|
||||
SparkFlex moteur1 = new SparkFlex(2, MotorType.kBrushless);
|
||||
SparkFlex moteur2 = new SparkFlex(3, MotorType.kBrushless);
|
||||
SparkFlex Demeleur = new SparkFlex(4, MotorType.kBrushless);
|
||||
SparkMaxConfig slaveConfig = new SparkMaxConfig();
|
||||
public void Lancer(double vitesse){
|
||||
moteur1.set(vitesse);
|
||||
slaveConfig.follow(moteur1, true);
|
||||
moteur2.configure(slaveConfig,null,null);
|
||||
}
|
||||
public void Demeler(double vitesse){
|
||||
Demeleur.set(vitesse);
|
||||
}
|
||||
public double Vitesse(){
|
||||
return moteur1.getEncoder().getVelocity();
|
||||
}
|
||||
/** Creates a new Lanceur. */
|
||||
public Lanceur() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void periodic() {
|
||||
// This method will be called once per scheduler run
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user