From c257411505738931ee48505e1151083466f39aa0 Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Mon, 5 Feb 2024 20:24:04 -0500 Subject: [PATCH 01/12] led --- src/main/java/frc/robot/RobotContainer.java | 7 ++- .../java/frc/robot/command/AllumeLED.java | 48 +++++++++++++++++++ src/main/java/frc/robot/subsystem/LED.java | 27 +++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/main/java/frc/robot/command/AllumeLED.java create mode 100644 src/main/java/frc/robot/subsystem/LED.java diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 3fb4b54..ddffae3 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -62,8 +62,9 @@ public class RobotContainer { autoChooser = AutoBuilder.buildAutoChooser(); CameraServer.startAutomaticCapture(); - manette.a().onTrue(guiderBas); - manette.b().onTrue(guiderHaut); + manette.a().whileTrue(guiderBas); + manette.b().whileTrue(guiderHaut); + joystick.button(3).toggleOnTrue(balayer); configureBindings(); drive.setDefaultCommand(new RunCommand(()->{ drive.drive(-MathUtil.applyDeadband(joystick.getY(),0.2), MathUtil.applyDeadband(-joystick.getX(),0.2), MathUtil.applyDeadband(-joystick.getZ(), 0.2)); @@ -73,8 +74,6 @@ public class RobotContainer { private void configureBindings() { - joystick.button(3).toggleOnTrue(balayer); - } public Command getAutonomousCommand(){ diff --git a/src/main/java/frc/robot/command/AllumeLED.java b/src/main/java/frc/robot/command/AllumeLED.java new file mode 100644 index 0000000..9ba8c16 --- /dev/null +++ b/src/main/java/frc/robot/command/AllumeLED.java @@ -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.command; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystem.Accumulateur; +import frc.robot.subsystem.LED; + +public class AllumeLED extends Command { + private LED led; + private Accumulateur accumulateur; + /** Creates a new AllumeLED. */ + public AllumeLED(LED led,Accumulateur accumulateur) { + this.accumulateur = accumulateur; + this.led = led; + addRequirements(led,accumulateur); + // 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(accumulateur.limitswitch()){ + led.couleur(0, 255, 0); + } + else{ + led.couleur(255, 0, 0); + } + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + led.couleur(255, 0, 0); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/subsystem/LED.java b/src/main/java/frc/robot/subsystem/LED.java new file mode 100644 index 0000000..8bc91cc --- /dev/null +++ b/src/main/java/frc/robot/subsystem/LED.java @@ -0,0 +1,27 @@ +// 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.subsystem; + +import edu.wpi.first.wpilibj.AddressableLED; +import edu.wpi.first.wpilibj.AddressableLEDBuffer; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class LED extends SubsystemBase { + /** Creates a new LED. */ + public LED() {} + AddressableLED led = new AddressableLED(9); + AddressableLEDBuffer ledBuffer = new AddressableLEDBuffer(60); + public void led(){ + led.setData(ledBuffer); + led.start(); + } + public void couleur(int R, int G, int B){ + ledBuffer.setRGB(0, R, G, B); + } + @Override + public void periodic() { + // This method will be called once per scheduler run + } +} From a708aac7003f31da65b076fd3abc90a91f820e0f Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 6 Feb 2024 18:17:08 -0500 Subject: [PATCH 02/12] --- src/main/java/frc/robot/RobotContainer.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index ddffae3..44a48ea 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -19,7 +19,7 @@ import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; // Manettes import edu.wpi.first.wpilibj2.command.button.CommandJoystick; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; - +import frc.robot.command.AllumeLED; // Commands import frc.robot.command.Balayer; import frc.robot.command.GrimpeurDroit; @@ -35,6 +35,7 @@ import frc.robot.subsystem.Balayeuse; import frc.robot.subsystem.Drive; import frc.robot.subsystem.Grimpeur; import frc.robot.subsystem.Guideur; +import frc.robot.subsystem.LED; import frc.robot.subsystem.Lanceur; @@ -56,6 +57,8 @@ public class RobotContainer { CommandXboxController manette = new CommandXboxController(1); GrimpeurDroit grimpeurDroit = new GrimpeurDroit(grimpeur, manette::getLeftX); GrimpeurGauche grimpeurGauche = new GrimpeurGauche(grimpeur, manette::getLeftY); + LED LED = new LED(); + AllumeLED allumeLED = new AllumeLED(LED, accumulateur); public RobotContainer() { NamedCommands.registerCommand("balayer",new Balayer(balayeuse, accumulateur)); NamedCommands.registerCommand("lancer", new LancerNote(lanceur, accumulateur)); @@ -69,7 +72,10 @@ public class RobotContainer { drive.setDefaultCommand(new RunCommand(()->{ drive.drive(-MathUtil.applyDeadband(joystick.getY(),0.2), MathUtil.applyDeadband(-joystick.getX(),0.2), MathUtil.applyDeadband(-joystick.getZ(), 0.2)); },drive)); - + grimpeur.setDefaultCommand(new RunCommand(()->{ + grimpeur.droit(manette.getLeftX());} + ,grimpeur)); + LED.setDefaultCommand(allumeLED); } private void configureBindings() { From f293f07bbdb8aaef8066aad0a1f78d61092e7db1 Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 6 Feb 2024 18:31:05 -0500 Subject: [PATCH 03/12] LED --- src/main/java/frc/robot/RobotContainer.java | 2 +- src/main/java/frc/robot/command/AllumeLED.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 44a48ea..6df4895 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -58,7 +58,7 @@ public class RobotContainer { GrimpeurDroit grimpeurDroit = new GrimpeurDroit(grimpeur, manette::getLeftX); GrimpeurGauche grimpeurGauche = new GrimpeurGauche(grimpeur, manette::getLeftY); LED LED = new LED(); - AllumeLED allumeLED = new AllumeLED(LED, accumulateur); + AllumeLED allumeLED = new AllumeLED(LED); public RobotContainer() { NamedCommands.registerCommand("balayer",new Balayer(balayeuse, accumulateur)); NamedCommands.registerCommand("lancer", new LancerNote(lanceur, accumulateur)); diff --git a/src/main/java/frc/robot/command/AllumeLED.java b/src/main/java/frc/robot/command/AllumeLED.java index 9ba8c16..484ecb3 100644 --- a/src/main/java/frc/robot/command/AllumeLED.java +++ b/src/main/java/frc/robot/command/AllumeLED.java @@ -15,7 +15,7 @@ public class AllumeLED extends Command { public AllumeLED(LED led,Accumulateur accumulateur) { this.accumulateur = accumulateur; this.led = led; - addRequirements(led,accumulateur); + addRequirements(led); // Use addRequirements() here to declare subsystem dependencies. } From b4ee2d228af6ef566bc4cc1a85e490c3e8e3ed1f Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 6 Feb 2024 18:32:56 -0500 Subject: [PATCH 04/12] LED --- src/main/java/frc/robot/command/AllumeLED.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/command/AllumeLED.java b/src/main/java/frc/robot/command/AllumeLED.java index 484ecb3..dd1d09e 100644 --- a/src/main/java/frc/robot/command/AllumeLED.java +++ b/src/main/java/frc/robot/command/AllumeLED.java @@ -12,7 +12,7 @@ public class AllumeLED extends Command { private LED led; private Accumulateur accumulateur; /** Creates a new AllumeLED. */ - public AllumeLED(LED led,Accumulateur accumulateur) { + public AllumeLED(LED led) { this.accumulateur = accumulateur; this.led = led; addRequirements(led); From e72a23fdde21208eb352ed7095fb7b2889b47b11 Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 6 Feb 2024 18:48:33 -0500 Subject: [PATCH 05/12] Pixy --- src/main/java/frc/robot/PixyException.java | 8 ++++++++ src/main/java/frc/robot/PixyPacket.java | 9 +++++++++ src/main/java/frc/robot/subsystem/Pixy.java | 1 - 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/main/java/frc/robot/PixyException.java create mode 100644 src/main/java/frc/robot/PixyPacket.java diff --git a/src/main/java/frc/robot/PixyException.java b/src/main/java/frc/robot/PixyException.java new file mode 100644 index 0000000..c4fd3c0 --- /dev/null +++ b/src/main/java/frc/robot/PixyException.java @@ -0,0 +1,8 @@ +package frc.robot; + +public class PixyException extends Exception { + public PixyException(String message){ + super(message); + } + +} diff --git a/src/main/java/frc/robot/PixyPacket.java b/src/main/java/frc/robot/PixyPacket.java new file mode 100644 index 0000000..d52adfe --- /dev/null +++ b/src/main/java/frc/robot/PixyPacket.java @@ -0,0 +1,9 @@ +package frc.robot; + +public class PixyPacket { + public int X; + public int Y; + public int Width; + public int Height; + +} diff --git a/src/main/java/frc/robot/subsystem/Pixy.java b/src/main/java/frc/robot/subsystem/Pixy.java index f56c0d2..468a421 100644 --- a/src/main/java/frc/robot/subsystem/Pixy.java +++ b/src/main/java/frc/robot/subsystem/Pixy.java @@ -7,7 +7,6 @@ package frc.robot.subsystem; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Pixy extends SubsystemBase { - /** Creates a new Pixy. */ public Pixy() {} From add3237dc5d8f04cd07c29332fff29a5efbfc5a0 Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 6 Feb 2024 18:55:13 -0500 Subject: [PATCH 06/12] --- src/main/java/frc/robot/Pixy.java | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/main/java/frc/robot/Pixy.java diff --git a/src/main/java/frc/robot/Pixy.java b/src/main/java/frc/robot/Pixy.java new file mode 100644 index 0000000..94c01b5 --- /dev/null +++ b/src/main/java/frc/robot/Pixy.java @@ -0,0 +1,73 @@ +package frc.robot; + + +import edu.wpi.first.wpilibj.SerialPort; +import edu.wpi.first.wpilibj.SerialPort.Port; +//Warning: if the pixy is plugged in through mini usb, this code WILL NOT WORK b/c the pixy is smart and detects where it should send data +public class Pixy { + SerialPort pixy; + Port port = Port.kMXP; + PixyPacket[] packets; + PixyException pExc; + String print; + + public Pixy() { + pixy = new SerialPort(19200, port); + pixy.setReadBufferSize(14); + packets = new PixyPacket[7]; + pExc = new PixyException(print); + } + //This method parses raw data from the pixy into readable integers + public int cvt(byte upper, byte lower) { + return (((int)upper & 0xff) << 8) | ((int)lower & 0xff); + } + public void pixyReset(){ + pixy.reset(); + } + //This method gathers data, then parses that data, and assigns the ints to global variables + public PixyPacket readPacket(int Signature) throws PixyException { + int Checksum; + int Sig; + byte[] rawData = new byte[32]; + try{ + rawData = pixy.read(32); + } catch (RuntimeException e){ + + } + if(rawData.length < 32){ + return null; + } + for (int i = 0; i <= 16; i++) { + int syncWord = cvt(rawData[i+1], rawData[i+0]); //Parse first 2 bytes + if (syncWord == 0xaa55) { //Check is first 2 bytes equal a "sync word", which indicates the start of a packet of valid data + syncWord = cvt(rawData[i+3], rawData[i+2]); //Parse the next 2 bytes + + if (syncWord != 0xaa55){ //Shifts everything in the case that one syncword is sent + i -= 2; + } + //This next block parses the rest of the data + Checksum = cvt(rawData[i+5], rawData[i+4]); + Sig = cvt(rawData[i+7], rawData[i+6]); + if(Sig <= 0 || Sig > packets.length){ + break; + } + packets[Sig - 1] = new PixyPacket(); + packets[Sig - 1].X = cvt(rawData[i+9], rawData[i+8]); + packets[Sig - 1].Y = cvt(rawData[i+11], rawData[i+10]); + packets[Sig - 1].Width = cvt(rawData[i+13], rawData[i+12]); + packets[Sig - 1].Height = cvt(rawData[i+15], rawData[i+14]); + //Checks whether the data is valid using the checksum *This if block should never be entered* + if (Checksum != Sig + packets[Sig - 1].X + packets[Sig - 1].Y + packets[Sig - 1].Width + packets[Sig - 1].Height) { + packets[Sig - 1] = null; + throw pExc; + } + break; + } + } + //Assigns our packet to a temp packet, then deletes data so that we dont return old data + + PixyPacket pkt = packets[Signature - 1]; + packets[Signature - 1] = null; + return pkt; + } +} \ No newline at end of file From b6e9c303f35f013843697b931b92cda099c620c4 Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 6 Feb 2024 19:01:04 -0500 Subject: [PATCH 07/12] Pixy --- src/main/java/frc/robot/Pixy.java | 73 ------------------ src/main/java/frc/robot/RobotContainer.java | 2 + src/main/java/frc/robot/subsystem/Pixy.java | 82 ++++++++++++++++++--- 3 files changed, 72 insertions(+), 85 deletions(-) delete mode 100644 src/main/java/frc/robot/Pixy.java diff --git a/src/main/java/frc/robot/Pixy.java b/src/main/java/frc/robot/Pixy.java deleted file mode 100644 index 94c01b5..0000000 --- a/src/main/java/frc/robot/Pixy.java +++ /dev/null @@ -1,73 +0,0 @@ -package frc.robot; - - -import edu.wpi.first.wpilibj.SerialPort; -import edu.wpi.first.wpilibj.SerialPort.Port; -//Warning: if the pixy is plugged in through mini usb, this code WILL NOT WORK b/c the pixy is smart and detects where it should send data -public class Pixy { - SerialPort pixy; - Port port = Port.kMXP; - PixyPacket[] packets; - PixyException pExc; - String print; - - public Pixy() { - pixy = new SerialPort(19200, port); - pixy.setReadBufferSize(14); - packets = new PixyPacket[7]; - pExc = new PixyException(print); - } - //This method parses raw data from the pixy into readable integers - public int cvt(byte upper, byte lower) { - return (((int)upper & 0xff) << 8) | ((int)lower & 0xff); - } - public void pixyReset(){ - pixy.reset(); - } - //This method gathers data, then parses that data, and assigns the ints to global variables - public PixyPacket readPacket(int Signature) throws PixyException { - int Checksum; - int Sig; - byte[] rawData = new byte[32]; - try{ - rawData = pixy.read(32); - } catch (RuntimeException e){ - - } - if(rawData.length < 32){ - return null; - } - for (int i = 0; i <= 16; i++) { - int syncWord = cvt(rawData[i+1], rawData[i+0]); //Parse first 2 bytes - if (syncWord == 0xaa55) { //Check is first 2 bytes equal a "sync word", which indicates the start of a packet of valid data - syncWord = cvt(rawData[i+3], rawData[i+2]); //Parse the next 2 bytes - - if (syncWord != 0xaa55){ //Shifts everything in the case that one syncword is sent - i -= 2; - } - //This next block parses the rest of the data - Checksum = cvt(rawData[i+5], rawData[i+4]); - Sig = cvt(rawData[i+7], rawData[i+6]); - if(Sig <= 0 || Sig > packets.length){ - break; - } - packets[Sig - 1] = new PixyPacket(); - packets[Sig - 1].X = cvt(rawData[i+9], rawData[i+8]); - packets[Sig - 1].Y = cvt(rawData[i+11], rawData[i+10]); - packets[Sig - 1].Width = cvt(rawData[i+13], rawData[i+12]); - packets[Sig - 1].Height = cvt(rawData[i+15], rawData[i+14]); - //Checks whether the data is valid using the checksum *This if block should never be entered* - if (Checksum != Sig + packets[Sig - 1].X + packets[Sig - 1].Y + packets[Sig - 1].Width + packets[Sig - 1].Height) { - packets[Sig - 1] = null; - throw pExc; - } - break; - } - } - //Assigns our packet to a temp packet, then deletes data so that we dont return old data - - PixyPacket pkt = packets[Signature - 1]; - packets[Signature - 1] = null; - return pkt; - } -} \ 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 6df4895..9368be5 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -37,6 +37,7 @@ import frc.robot.subsystem.Grimpeur; import frc.robot.subsystem.Guideur; import frc.robot.subsystem.LED; import frc.robot.subsystem.Lanceur; +import frc.robot.subsystem.Pixy; public class RobotContainer { @@ -59,6 +60,7 @@ public class RobotContainer { GrimpeurGauche grimpeurGauche = new GrimpeurGauche(grimpeur, manette::getLeftY); LED LED = new LED(); AllumeLED allumeLED = new AllumeLED(LED); + Pixy pixy = new Pixy(); public RobotContainer() { NamedCommands.registerCommand("balayer",new Balayer(balayeuse, accumulateur)); NamedCommands.registerCommand("lancer", new LancerNote(lanceur, accumulateur)); diff --git a/src/main/java/frc/robot/subsystem/Pixy.java b/src/main/java/frc/robot/subsystem/Pixy.java index 468a421..8cd59b9 100644 --- a/src/main/java/frc/robot/subsystem/Pixy.java +++ b/src/main/java/frc/robot/subsystem/Pixy.java @@ -1,17 +1,75 @@ -// 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.subsystem; import edu.wpi.first.wpilibj2.command.SubsystemBase; - +import frc.robot.PixyException; +import frc.robot.PixyPacket; +import edu.wpi.first.wpilibj.SerialPort; +import edu.wpi.first.wpilibj.SerialPort.Port; +//Warning: if the pixy is plugged in through mini usb, this code WILL NOT WORK b/c the pixy is smart and detects where it should send data public class Pixy extends SubsystemBase { - /** Creates a new Pixy. */ - public Pixy() {} + SerialPort pixy; + Port port = Port.kMXP; + PixyPacket[] packets; + PixyException pExc; + String print; - @Override - public void periodic() { - // This method will be called once per scheduler run - } -} + public Pixy() { + pixy = new SerialPort(19200, port); + pixy.setReadBufferSize(14); + packets = new PixyPacket[7]; + pExc = new PixyException(print); + } + //This method parses raw data from the pixy into readable integers + public int cvt(byte upper, byte lower) { + return (((int)upper & 0xff) << 8) | ((int)lower & 0xff); + } + public void pixyReset(){ + pixy.reset(); + } + //This method gathers data, then parses that data, and assigns the ints to global variables + public PixyPacket readPacket(int Signature) throws PixyException { + int Checksum; + int Sig; + byte[] rawData = new byte[32]; + try{ + rawData = pixy.read(32); + } catch (RuntimeException e){ + + } + if(rawData.length < 32){ + return null; + } + for (int i = 0; i <= 16; i++) { + int syncWord = cvt(rawData[i+1], rawData[i+0]); //Parse first 2 bytes + if (syncWord == 0xaa55) { //Check is first 2 bytes equal a "sync word", which indicates the start of a packet of valid data + syncWord = cvt(rawData[i+3], rawData[i+2]); //Parse the next 2 bytes + + if (syncWord != 0xaa55){ //Shifts everything in the case that one syncword is sent + i -= 2; + } + //This next block parses the rest of the data + Checksum = cvt(rawData[i+5], rawData[i+4]); + Sig = cvt(rawData[i+7], rawData[i+6]); + if(Sig <= 0 || Sig > packets.length){ + break; + } + packets[Sig - 1] = new PixyPacket(); + packets[Sig - 1].X = cvt(rawData[i+9], rawData[i+8]); + packets[Sig - 1].Y = cvt(rawData[i+11], rawData[i+10]); + packets[Sig - 1].Width = cvt(rawData[i+13], rawData[i+12]); + packets[Sig - 1].Height = cvt(rawData[i+15], rawData[i+14]); + //Checks whether the data is valid using the checksum *This if block should never be entered* + if (Checksum != Sig + packets[Sig - 1].X + packets[Sig - 1].Y + packets[Sig - 1].Width + packets[Sig - 1].Height) { + packets[Sig - 1] = null; + throw pExc; + } + break; + } + } + //Assigns our packet to a temp packet, then deletes data so that we dont return old data + + PixyPacket pkt = packets[Signature - 1]; + packets[Signature - 1] = null; + return pkt; + } +} \ No newline at end of file From 3b44dbb6a66e45e0f5aeb8781c8fb10c122ec792 Mon Sep 17 00:00:00 2001 From: samuel desharnais Date: Tue, 6 Feb 2024 19:08:49 -0500 Subject: [PATCH 08/12] --- src/main/java/frc/robot/RobotContainer.java | 1 + .../java/frc/robot/command/RobotPixy.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/frc/robot/command/RobotPixy.java diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 9368be5..4ba1d18 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -70,6 +70,7 @@ public class RobotContainer { manette.a().whileTrue(guiderBas); manette.b().whileTrue(guiderHaut); joystick.button(3).toggleOnTrue(balayer); + configureBindings(); drive.setDefaultCommand(new RunCommand(()->{ drive.drive(-MathUtil.applyDeadband(joystick.getY(),0.2), MathUtil.applyDeadband(-joystick.getX(),0.2), MathUtil.applyDeadband(-joystick.getZ(), 0.2)); diff --git a/src/main/java/frc/robot/command/RobotPixy.java b/src/main/java/frc/robot/command/RobotPixy.java new file mode 100644 index 0000000..652c4c3 --- /dev/null +++ b/src/main/java/frc/robot/command/RobotPixy.java @@ -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.command; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystem.Drive; +import frc.robot.subsystem.Pixy; + +public class RobotPixy extends Command { + private Pixy pixy; + private Drive drive; + /** Creates a new RobotPixy. */ + public RobotPixy(Pixy pixy,Drive drive) { + this.drive = drive; + this.pixy = pixy; + addRequirements(drive,pixy); + // 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() { + } + + // 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; + } +} From 1b6663c9771e55d16b3c50134c6dfb15f33c5b48 Mon Sep 17 00:00:00 2001 From: Antoine PerreaultE Date: Tue, 6 Feb 2024 19:57:49 -0500 Subject: [PATCH 09/12] Limelight --- src/main/java/frc/robot/subsystem/Limelight.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/subsystem/Limelight.java b/src/main/java/frc/robot/subsystem/Limelight.java index 9fb068b..176616d 100644 --- a/src/main/java/frc/robot/subsystem/Limelight.java +++ b/src/main/java/frc/robot/subsystem/Limelight.java @@ -9,6 +9,7 @@ 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; @@ -16,14 +17,26 @@ public class Limelight extends SubsystemBase { /** Creates a new Limelight. */ public Limelight() { - NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight"); + NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight"); + NetworkTableInstance.getDefault().getTable("limelight").getEntry("Tv").getDouble(0); + NetworkTableInstance.getDefault().getTable("limelight").getEntry("getpipe").getDouble(1); + NetworkTableInstance.getDefault().getTable("limelight").getEntry("").getDoubleArray(new double[6]); + + NetworkTableEntry tx = table.getEntry("tx"); NetworkTableEntry ty = table.getEntry("ty"); NetworkTableEntry ta = table.getEntry("ta"); + NetworkTableEntry botpose = table.getEntry("pose"); + NetworkTableEntry getpipe = table.getEntry(getName()); double x = tx.getDouble(0.0); double y = ty.getDouble(0.0); double area = ta.getDouble(0.0); + double pose = botpose.getDouble(area); + + + + SmartDashboard.putNumber("LimelightX", x); SmartDashboard.putNumber("LimelightY", y); From da4342e4565537ce773302a1918078fcce14aaa2 Mon Sep 17 00:00:00 2001 From: Antoine PerreaultE Date: Wed, 7 Feb 2024 18:05:24 -0500 Subject: [PATCH 10/12] j --- .../java/frc/robot/subsystem/Limelight.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/frc/robot/subsystem/Limelight.java b/src/main/java/frc/robot/subsystem/Limelight.java index 176616d..49291b3 100644 --- a/src/main/java/frc/robot/subsystem/Limelight.java +++ b/src/main/java/frc/robot/subsystem/Limelight.java @@ -14,37 +14,39 @@ import frc.robot.LimelightHelpers; public class Limelight extends SubsystemBase { - /** Creates a new Limelight. */ - public Limelight() { - NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight"); - NetworkTableInstance.getDefault().getTable("limelight").getEntry("Tv").getDouble(0); - NetworkTableInstance.getDefault().getTable("limelight").getEntry("getpipe").getDouble(1); - NetworkTableInstance.getDefault().getTable("limelight").getEntry("").getDoubleArray(new double[6]); - NetworkTableEntry tx = table.getEntry("tx"); NetworkTableEntry ty = table.getEntry("ty"); NetworkTableEntry ta = table.getEntry("ta"); - NetworkTableEntry botpose = table.getEntry("pose"); - NetworkTableEntry getpipe = table.getEntry(getName()); + NetworkTableEntry pipeline = table.getEntry("pipeline"); + NetworkTableEntry tv = table.getEntry("tv"); + NetworkTableEntry camMode = table.getEntry("camMode"); - double x = tx.getDouble(0.0); - double y = ty.getDouble(0.0); - double area = ta.getDouble(0.0); - double pose = botpose.getDouble(area); - - - + + /** Creates a new Limelight. */ + public Limelight() { + } + public double getx(){ + return tx.getDouble(0); + } + public double gety(){ + return ty.getDouble(0); + } + public double geta() { + return ta.getDouble(0); + } + public boolean getv(){ + return tv.getBoolean(false); + } + public double getpipeline(){ + return pipeline.getDouble(0); + } + public double getcamMode(){ + return camMode.getDouble(0); + } - SmartDashboard.putNumber("LimelightX", x); - SmartDashboard.putNumber("LimelightY", y); - SmartDashboard.putNumber("LimelightArea", area); - -} - - @Override public void periodic() { // This method will be called once per scheduler run From fcac077def5428d03df7ebe38df76a15dfdd40a2 Mon Sep 17 00:00:00 2001 From: Antoine PerreaultE Date: Wed, 7 Feb 2024 18:35:35 -0500 Subject: [PATCH 11/12] subsystem limelight --- src/main/java/frc/robot/subsystem/Limelight.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/frc/robot/subsystem/Limelight.java b/src/main/java/frc/robot/subsystem/Limelight.java index 49291b3..97831af 100644 --- a/src/main/java/frc/robot/subsystem/Limelight.java +++ b/src/main/java/frc/robot/subsystem/Limelight.java @@ -9,8 +9,6 @@ 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 { @@ -22,10 +20,11 @@ public class Limelight extends SubsystemBase { NetworkTableEntry pipeline = table.getEntry("pipeline"); NetworkTableEntry tv = table.getEntry("tv"); NetworkTableEntry camMode = table.getEntry("camMode"); + NetworkTableEntry tid = table.getEntry("tid"); - /** Creates a new Limelight. */ public Limelight() { + } public double getx(){ @@ -40,11 +39,14 @@ public class Limelight extends SubsystemBase { public boolean getv(){ return tv.getBoolean(false); } - public double getpipeline(){ - return pipeline.getDouble(0); + public void setpipeline(){ + pipeline.setNumber(0); } - public double getcamMode(){ - return camMode.getDouble(0); + public void setcamMode(){ + camMode.setNumber(0); + } + public double getTid(){ + return tid.getDouble(0); } @Override From 9f4ae69d9acc5939da8a05e2494bac20af2aef09 Mon Sep 17 00:00:00 2001 From: Antoine PerreaultE Date: Wed, 7 Feb 2024 19:37:35 -0500 Subject: [PATCH 12/12] Commande tracker april tag --- .../java/frc/robot/command/GuiderHaut.java | 2 +- .../java/frc/robot/command/LancerNote.java | 1 + .../frc/robot/command/Limelight_tracker.java | 49 +++++++++++++++++++ .../java/frc/robot/subsystem/Limelight.java | 6 +-- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 src/main/java/frc/robot/command/Limelight_tracker.java diff --git a/src/main/java/frc/robot/command/GuiderHaut.java b/src/main/java/frc/robot/command/GuiderHaut.java index 1eb052e..74719ca 100644 --- a/src/main/java/frc/robot/command/GuiderHaut.java +++ b/src/main/java/frc/robot/command/GuiderHaut.java @@ -40,6 +40,6 @@ public class GuiderHaut extends Command { // Returns true when the command should end. @Override public boolean isFinished() { - return guideur.haut()==true; +return guideur.haut()==true; } } diff --git a/src/main/java/frc/robot/command/LancerNote.java b/src/main/java/frc/robot/command/LancerNote.java index d653184..133492b 100644 --- a/src/main/java/frc/robot/command/LancerNote.java +++ b/src/main/java/frc/robot/command/LancerNote.java @@ -15,6 +15,7 @@ public class LancerNote extends Command { public LancerNote(Lanceur lancer, Accumulateur accumulateur) { this.lancer = lancer; this.accumulateur = accumulateur; + addRequirements(lancer); // Use addRequirements() here to declare subsystem dependencies. } diff --git a/src/main/java/frc/robot/command/Limelight_tracker.java b/src/main/java/frc/robot/command/Limelight_tracker.java new file mode 100644 index 0000000..78d0f91 --- /dev/null +++ b/src/main/java/frc/robot/command/Limelight_tracker.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.command; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystem.Drive; +import frc.robot.subsystem.Limelight; + +public class Limelight_tracker extends Command { + /** Creates a new Limelight_tracker. */ + private Limelight tracker; + private Drive drive; + + public Limelight_tracker(Limelight tracker, Drive drive) { + this.drive = drive; + this.tracker = tracker; + addRequirements(tracker,drive); + } + + // 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 (tracker.getv()){ + drive.drive(0,0, tracker.getx()); + } + else{ + drive.drive(0, 0, 0); + } + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + drive.drive(0, 0, 0); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/subsystem/Limelight.java b/src/main/java/frc/robot/subsystem/Limelight.java index 97831af..ab2358f 100644 --- a/src/main/java/frc/robot/subsystem/Limelight.java +++ b/src/main/java/frc/robot/subsystem/Limelight.java @@ -27,15 +27,15 @@ public class Limelight extends SubsystemBase { } - public double getx(){ + public double getx(){ return tx.getDouble(0); } public double gety(){ return ty.getDouble(0); } - public double geta() { + /* public double geta() { return ta.getDouble(0); - } + }*/ public boolean getv(){ return tv.getBoolean(false); }