limelight

This commit is contained in:
Olivier Dubois 2024-01-17 19:40:57 -05:00
parent 1030a95456
commit 05182be6b4
4 changed files with 40 additions and 18 deletions

View File

@ -5,6 +5,7 @@
package frc.robot; package frc.robot;
import java.util.Map; import java.util.Map;
import edu.wpi.first.cameraserver.CameraServer; import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.math.MathUtil; import edu.wpi.first.math.MathUtil;
import edu.wpi.first.networktables.GenericEntry; import edu.wpi.first.networktables.GenericEntry;
@ -36,13 +37,16 @@ import frc.robot.commands.accumulateurtest;
import frc.robot.subsystems.Accumulateur; import frc.robot.subsystems.Accumulateur;
import frc.robot.subsystems.Drive; import frc.robot.subsystems.Drive;
import frc.robot.subsystems.Lanceur; import frc.robot.subsystems.Lanceur;
import frc.robot.subsystems.limelight;
import frc.robot.commands.AprilTag;
public class RobotContainer { public class RobotContainer {
String avancergaucheString = "droite"; String avancergaucheString = "droite";
String avancerautoString = "gauche"; String avancerautoString = "gauche";
ShuffleboardLayout layoutauto = Shuffleboard.getTab("Dashboard").getLayout("auto", BuiltInLayouts.kList); ShuffleboardLayout layoutauto = Shuffleboard.getTab("Dashboard").getLayout("auto", BuiltInLayouts.kList);
SendableChooser<String> chooser = new SendableChooser<>(); SendableChooser<String> chooser = new SendableChooser<>();
limelight limelight = new limelight();
Lanceur lanceur = new Lanceur(); Lanceur lanceur = new Lanceur();
Accumulateur accumulateur = new Accumulateur(); Accumulateur accumulateur = new Accumulateur();
Drive drive = new Drive(); Drive drive = new Drive();
@ -78,6 +82,7 @@ String avancerautoString = "gauche";
chooser.addOption(avancergaucheString, avancergaucheString); chooser.addOption(avancergaucheString, avancergaucheString);
layoutauto.add("choix hauteur", chooser); layoutauto.add("choix hauteur", chooser);
accumulateurtest accumulateurtest = new accumulateurtest(accumulateur); accumulateurtest accumulateurtest = new accumulateurtest(accumulateur);
AprilTag aprilTag = new AprilTag(limelight, lanceur);
Force1 Force1 = new Force1(lanceur, force1); Force1 Force1 = new Force1(lanceur, force1);
Force2 Force2 = new Force2(lanceur, force2); Force2 Force2 = new Force2(lanceur, force2);
Force3 Force3 = new Force3(lanceur, force3); Force3 Force3 = new Force3(lanceur, force3);
@ -87,7 +92,7 @@ String avancerautoString = "gauche";
Force7 Force7 = new Force7(lanceur, force7); Force7 Force7 = new Force7(lanceur, force7);
//touche //touche
joystick1.button(2).whileTrue(aprilTag);
joystick1.button(3).whileTrue(accumulateurtest); joystick1.button(3).whileTrue(accumulateurtest);
joystick1.button(1).whileTrue(Force1); joystick1.button(1).whileTrue(Force1);
joystick1.button(7).whileTrue(Force2); joystick1.button(7).whileTrue(Force2);

View File

@ -4,13 +4,17 @@
package frc.robot.commands; package frc.robot.commands;
import java.util.function.DoubleSupplier;
import edu.wpi.first.wpilibj2.command.CommandBase; import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.Drive;
import frc.robot.subsystems.Lanceur; import frc.robot.subsystems.Lanceur;
import frc.robot.subsystems.limelight; import frc.robot.subsystems.limelight;
public class AprilTag extends CommandBase { public class AprilTag extends CommandBase {
private limelight limelight;
private Lanceur lanceur; private Lanceur lanceur;
private limelight limelight;
/** Creates a new Limelight. */ /** Creates a new Limelight. */
public AprilTag(limelight limelight,Lanceur lanceur) { public AprilTag(limelight limelight,Lanceur lanceur) {
this.lanceur = lanceur; this.lanceur = lanceur;
@ -22,15 +26,19 @@ public class AprilTag extends CommandBase {
// Called when the command is initially scheduled. // Called when the command is initially scheduled.
@Override @Override
public void initialize() { public void initialize() {
limelight.lumiere();
} }
// 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() {
//drive.drive(0, limelight.getYaw(), 0);
if(limelight.tv.getDouble(0) == 1){
lanceur.lancer(0.5); lanceur.lancer(0.5);
} }
}
// Called once the command ends or is interrupted. // Called once the command ends or is interrupted.
@Override @Override
public void end(boolean interrupted) { public void end(boolean interrupted) {

View File

@ -7,6 +7,8 @@ package frc.robot.subsystems;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import com.kauailabs.navx.frc.AHRS;
import edu.wpi.first.math.geometry.Translation2d; import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.SwerveModulePosition; import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.wpilibj.Filesystem; import edu.wpi.first.wpilibj.Filesystem;
@ -39,8 +41,7 @@ public class Drive extends SubsystemBase {
final CanAndCoderSwerve arrieregaucheangle = new CanAndCoderSwerve(Constants.arrieregaucheAngle); final CanAndCoderSwerve arrieregaucheangle = new CanAndCoderSwerve(Constants.arrieregaucheAngle);
final CanAndCoderSwerve arrieredroitangle = new CanAndCoderSwerve(Constants.arrieredroitAngle); */ final CanAndCoderSwerve arrieredroitangle = new CanAndCoderSwerve(Constants.arrieredroitAngle); */
public void drive(double x, double y, double zRotation){ public void drive(double x, double y, double zRotation){
swerveDrive.drive(new Translation2d(x*2, y*2), zRotation, true, false); swerveDrive.drive(new Translation2d(x*2, y*2), zRotation, true, false);}
}

View File

@ -5,22 +5,30 @@
package frc.robot.subsystems; package frc.robot.subsystems;
import org.photonvision.PhotonCamera;
import org.photonvision.common.hardware.VisionLEDMode; import org.photonvision.common.hardware.VisionLEDMode;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class limelight extends SubsystemBase { public class limelight extends SubsystemBase {
public NetworkTableEntry tv = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv");
PhotonCamera limelight = new PhotonCamera("limelight"); limelight limelight = new limelight();
/** Creates a new limelight. */ /** Creates a new limelight. */
public limelight() {} public limelight() {}
public void lumiere(){
/*public void lumiere(){
limelight.setLED(VisionLEDMode.kOff); limelight.setLED(VisionLEDMode.kOff);
limelight.setPipelineIndex(0); limelight.setPipelineIndex(0);
}*/
/*public double getYaw() {
var result = limelight.getLatestResult();
if(result.hasTargets()){
return -result.getBestTarget().getYaw()/45;
} }
return 0;}*/
@Override @Override
public void periodic() { public void periodic() {