This commit is contained in:
Olivier Dubois 2024-01-30 18:18:26 -05:00
commit ab5f7098e6
5 changed files with 150 additions and 10 deletions

View File

@ -0,0 +1,51 @@
// 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.command;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystem.Grimpeur;
public class GrimpeurBas extends Command {
private Grimpeur grimpeur;
/** Creates a new GrimpeurBas. */
public GrimpeurBas(Grimpeur grimpeur) {
this.grimpeur = grimpeur;
addRequirements(grimpeur);
// Use addRequirements() here to declare subsystem dependencies.
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
grimpeur.resetencodeurd();
grimpeur.resetencodeurg();
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
if(grimpeur.droite()){
grimpeur.resetencodeurd();
grimpeur.gauche(0);
}
if(grimpeur.gauche()){
grimpeur.resetencodeurg();
grimpeur.gauche(0);
}
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
grimpeur.droit(0);
grimpeur.gauche(0);
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}

View File

@ -7,10 +7,10 @@ package frc.robot.command;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystem.Grimpeur;
public class GrimpeurHaut extends Command {
public class GrimpeurHautDroit extends Command {
private Grimpeur grimpeur;
/** Creates a new GrimpeurHaut. */
public GrimpeurHaut(Grimpeur grimpeur) {
public GrimpeurHautDroit(Grimpeur grimpeur) {
this.grimpeur = grimpeur;
addRequirements(grimpeur);
// Use addRequirements() here to declare subsystem dependencies.
@ -18,17 +18,35 @@ public class GrimpeurHaut extends Command {
// Called when the command is initially scheduled.
@Override
public void initialize() {}
public void initialize() {
grimpeur.resetencodeurd();
grimpeur.resetencodeurg();
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
if(grimpeur.encoderd()>261 ){
grimpeur.droit(0);
}
else if(grimpeur.getpitch()<-15){
grimpeur.droit(-0.6);
}
else if(grimpeur.getpitch()>15){
grimpeur.droit(0.6);
}
else{
grimpeur.droit(0);
}
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {}
public void end(boolean interrupted) {
grimpeur.droit(0);
}
// Returns true when the command should end.
@Override

View File

@ -0,0 +1,55 @@
// 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.command;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystem.Grimpeur;
public class GrimpeurHautGauche extends Command {
private Grimpeur grimpeur;
/** Creates a new GrimpeurHautGauche. */
public GrimpeurHautGauche(Grimpeur grimpeur) {
this.grimpeur = grimpeur;
addRequirements(grimpeur);
// Use addRequirements() here to declare subsystem dependencies.
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
grimpeur.resetencodeurd();
grimpeur.resetencodeurg();
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
if(grimpeur.encoderg()>261 ){
grimpeur.gauche(0);
}
else if(grimpeur.getpitch()<-15){
grimpeur.gauche(0.6);
}
else if(grimpeur.getpitch()>15){
grimpeur.gauche(-0.6);
}
else{
grimpeur.gauche(0);
}
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
grimpeur.gauche(0);
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}

View File

@ -45,7 +45,12 @@ public void resetencodeurd(){
public void resetencodeurg(){
grimpeurg.getEncoder().setPosition(0);
}
public double encoderd(){
return grimpeurd.getEncoder().getPosition();
}
public double encoderg(){
return grimpeurg.getEncoder().getPosition();
}
public AHRS gyroscope = new AHRS();
public double getpitch(){
return gyroscope.getPitch();

View File

@ -4,20 +4,31 @@
package frc.robot.subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.LimelightHelpers;
public class Limelight extends SubsystemBase {
/** Creates a new Limelight. */
public Limelight() {
boolean tv = LimelightHelpers.getTV("No_name");
NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight");
NetworkTableEntry tx = table.getEntry("tx");
NetworkTableEntry ty = table.getEntry("ty");
NetworkTableEntry ta = table.getEntry("ta");
double x = tx.getDouble(0.0);
double y = ty.getDouble(0.0);
double area = ta.getDouble(0.0);
SmartDashboard.putNumber("LimelightX", x);
SmartDashboard.putNumber("LimelightY", y);
SmartDashboard.putNumber("LimelightArea", area);
double tx = LimelightHelpers.getTX("No_name");
double ty = LimelightHelpers.getTY("No_name");
double ta = LimelightHelpers.getTA("No_name");
}