From 9f72f048254d402bf358f9d938d9c64099b5879e Mon Sep 17 00:00:00 2001 From: Computer 0 <48131223+TheGamer1002@users.noreply.github.com> Date: Mon, 17 Apr 2023 20:49:00 -0400 Subject: [PATCH] why isnt anything working graaah --- src/main/java/frc/robot/Constants.java | 1 + src/main/java/frc/robot/RobotContainer.java | 4 ++ .../java/frc/robot/commands/DriveCommand.java | 10 ++++- .../java/frc/robot/commands/Tracking.java | 21 +++++++++ .../java/frc/robot/commands/XTracking.java | 45 +++++++++++++++++++ .../robot/commands/tests/FullTestCommand.java | 31 ------------- .../robot/commands/tests/TestArmCommand.java | 30 ------------- .../robot/commands/tests/TestClawCommand.java | 27 ----------- .../commands/tests/TestDrivebaseCommand.java | 44 ------------------ .../commands/tests/TestTurretCommand.java | 36 --------------- src/main/java/frc/robot/subsystems/Arm.java | 11 ++++- .../frc/robot/subsystems/Tracking/Arm.java | 21 --------- .../frc/robot/subsystems/Tracking/Target.java | 22 +++++++-- 13 files changed, 107 insertions(+), 196 deletions(-) create mode 100644 src/main/java/frc/robot/commands/Tracking.java create mode 100644 src/main/java/frc/robot/commands/XTracking.java delete mode 100644 src/main/java/frc/robot/commands/tests/FullTestCommand.java delete mode 100644 src/main/java/frc/robot/commands/tests/TestArmCommand.java delete mode 100644 src/main/java/frc/robot/commands/tests/TestClawCommand.java delete mode 100644 src/main/java/frc/robot/commands/tests/TestDrivebaseCommand.java delete mode 100644 src/main/java/frc/robot/commands/tests/TestTurretCommand.java delete mode 100644 src/main/java/frc/robot/subsystems/Tracking/Arm.java diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 66f220b..af014b0 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -57,4 +57,5 @@ public static final class VisionConstants { } public static final String OperatorConstast = null; +public boolean isDriveCommandFinished = false; } diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 3b0a1e7..1a91106 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -11,6 +11,7 @@ import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.CommandScheduler; import edu.wpi.first.wpilibj2.command.button.JoystickButton; import frc.robot.commands.*; import frc.robot.subsystems.*; @@ -282,4 +283,7 @@ public void robotPeriodic() { Logger.updateEntries(); timeWidget.setDouble(DriverStation.getMatchTime()); } + + + } diff --git a/src/main/java/frc/robot/commands/DriveCommand.java b/src/main/java/frc/robot/commands/DriveCommand.java index 62c7397..72206cf 100644 --- a/src/main/java/frc/robot/commands/DriveCommand.java +++ b/src/main/java/frc/robot/commands/DriveCommand.java @@ -4,6 +4,8 @@ package frc.robot.commands; +import java.security.Guard; + import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.CommandBase; import frc.robot.Constants; @@ -14,6 +16,9 @@ public class DriveCommand extends CommandBase { @SuppressWarnings({ "PMD.UnusedPrivateField", "PMD.SingularField" }) private final Tank m_drivebase; + + + public DriveCommand(Tank subsystem) { m_drivebase = subsystem; addRequirements(m_drivebase); @@ -27,6 +32,7 @@ public void initialize() { @Override public void execute() { // double check getMaxSpeed(), might be wrong + Tank.arcadeDrive( /* rotation */RobotContainer.getAdjustedTurningStickInput() * Constants.CanConstants.maxSpeed, /* speed */RobotContainer.getAdjustedForwardStickInput() * 0.7); @@ -41,7 +47,9 @@ public void end(boolean interrupted) { @Override public boolean isFinished() { - return false; + // we need to return the value in Constants.isDriveCommandFinished but in a static way while keeping the value non-static in Constants + private static final boolean x = Constants.isDriveCommandFinished; + return x; } @Override diff --git a/src/main/java/frc/robot/commands/Tracking.java b/src/main/java/frc/robot/commands/Tracking.java new file mode 100644 index 0000000..eb7b3b0 --- /dev/null +++ b/src/main/java/frc/robot/commands/Tracking.java @@ -0,0 +1,21 @@ +// 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.InstantCommand; +import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html +public class Tracking extends ParallelDeadlineGroup { + /** Creates a new Tracking. */ + public Tracking() { + // Add the deadline command in the super() call. Add other commands using + // addCommands(). + super(new InstantCommand()); + // addCommands(new FooCommand(), new BarCommand()); + } +} diff --git a/src/main/java/frc/robot/commands/XTracking.java b/src/main/java/frc/robot/commands/XTracking.java new file mode 100644 index 0000000..871508e --- /dev/null +++ b/src/main/java/frc/robot/commands/XTracking.java @@ -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.CommandBase; +import edu.wpi.first.wpilibj2.command.CommandScheduler; +import frc.robot.subsystems.Tank; +import frc.robot.subsystems.Tracking.Target; +import frc.robot.RobotContainer; +import frc.robot.commands.*; + +public class XTracking extends CommandBase { + + private double tx; + /** Creates a new XTracking. */ + public XTracking(Tank tank, Target target) { + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(tank, target); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + // stop the DriveCommand + + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + tx = Target.getTX(); + } + + // 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/tests/FullTestCommand.java b/src/main/java/frc/robot/commands/tests/FullTestCommand.java deleted file mode 100644 index 6b9b2b8..0000000 --- a/src/main/java/frc/robot/commands/tests/FullTestCommand.java +++ /dev/null @@ -1,31 +0,0 @@ -package frc.robot.commands.tests; - -import edu.wpi.first.wpilibj2.command.InstantCommand; - -public class FullTestCommand extends InstantCommand { - private final TestArmCommand m_arm; - private final TestClawCommand m_claw; - private final TestDrivebaseCommand m_drive; - private final TestTurretCommand m_turret; - - public FullTestCommand( - TestArmCommand arm, - TestClawCommand claw, - TestDrivebaseCommand drive, - TestTurretCommand turret) { - m_arm = arm; - m_claw = claw; - m_drive = drive; - m_turret = turret; - } - - @Override - public void execute() { - m_arm.andThen(m_claw.andThen(m_drive.andThen(m_turret))).schedule(); - } - - @Override - public boolean runsWhenDisabled() { - return false; - } -} diff --git a/src/main/java/frc/robot/commands/tests/TestArmCommand.java b/src/main/java/frc/robot/commands/tests/TestArmCommand.java deleted file mode 100644 index 5fdb275..0000000 --- a/src/main/java/frc/robot/commands/tests/TestArmCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package frc.robot.commands.tests; - -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj2.command.InstantCommand; -import frc.robot.subsystems.Arm; - -public class TestArmCommand extends InstantCommand { - private final Arm m_arm; - - public TestArmCommand(Arm subsystem) { - m_arm = subsystem; - addRequirements(m_arm); - } - - @Override - public void execute() { - m_arm.moveArm(1); - Timer.delay(1); - m_arm.moveArm(0); - Timer.delay(1); - m_arm.moveArm(-1); - Timer.delay(1); - m_arm.moveArmToZeroDeg(); - } - - @Override - public boolean runsWhenDisabled() { - return false; - } -} diff --git a/src/main/java/frc/robot/commands/tests/TestClawCommand.java b/src/main/java/frc/robot/commands/tests/TestClawCommand.java deleted file mode 100644 index 6339fab..0000000 --- a/src/main/java/frc/robot/commands/tests/TestClawCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package frc.robot.commands.tests; - -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj2.command.InstantCommand; -import frc.robot.subsystems.Claw; - -public class TestClawCommand extends InstantCommand { - private final Claw m_claw; - - public TestClawCommand(Claw subsystem) { - m_claw = subsystem; - addRequirements(m_claw); - } - - @Override - public void execute() { - m_claw.openClaw(); - Timer.delay(0.5); - m_claw.closeClaw(); - Timer.delay(0.5); - } - - @Override - public boolean runsWhenDisabled() { - return false; - } -} diff --git a/src/main/java/frc/robot/commands/tests/TestDrivebaseCommand.java b/src/main/java/frc/robot/commands/tests/TestDrivebaseCommand.java deleted file mode 100644 index 2721625..0000000 --- a/src/main/java/frc/robot/commands/tests/TestDrivebaseCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package frc.robot.commands.tests; - -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj2.command.InstantCommand; -import frc.robot.subsystems.Tank; - -public class TestDrivebaseCommand extends InstantCommand { - private final Tank m_drivebase; - - public TestDrivebaseCommand(Tank subsystem) { - m_drivebase = subsystem; - addRequirements(m_drivebase); - } - - @Override - public void execute() { - Tank.arcadeDrive(1, 0); - Timer.delay(1); - Tank.arcadeDrive(0, 0); - Timer.delay(1); - Tank.arcadeDrive(-1, 0); - Timer.delay(1); - Tank.arcadeDrive(0, 0); - Timer.delay(1); - Tank.arcadeDrive(0, 1); - Timer.delay(1); - Tank.arcadeDrive(0, 0); - Timer.delay(1); - Tank.arcadeDrive(0, -1); - Timer.delay(1); - Tank.arcadeDrive(0, 0); - Timer.delay(1); - } - - @Override - public void end(boolean interrupted) { - Tank.arcadeDrive(0, 0); - } - - @Override - public boolean runsWhenDisabled() { - return false; - } -} diff --git a/src/main/java/frc/robot/commands/tests/TestTurretCommand.java b/src/main/java/frc/robot/commands/tests/TestTurretCommand.java deleted file mode 100644 index a0e2af9..0000000 --- a/src/main/java/frc/robot/commands/tests/TestTurretCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package frc.robot.commands.tests; - -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj2.command.InstantCommand; -import frc.robot.subsystems.Turret; - -public class TestTurretCommand extends InstantCommand { - private final Turret m_turret; - - public TestTurretCommand(Turret subsystem) { - m_turret = subsystem; - addRequirements(m_turret); - } - - @Override - public void execute() { - m_turret.rotateTurret(1); - Timer.delay(1); - m_turret.rotateTurret(0); - Timer.delay(1); - m_turret.rotateTurret(-1); - Timer.delay(1); - m_turret.rotateTurret(0); - Timer.delay(1); - } - - @Override - public void end(boolean interrupted) { - m_turret.rotateTurret(0); - } - - @Override - public boolean runsWhenDisabled() { - return false; - } -} diff --git a/src/main/java/frc/robot/subsystems/Arm.java b/src/main/java/frc/robot/subsystems/Arm.java index a232ccb..ccef4db 100644 --- a/src/main/java/frc/robot/subsystems/Arm.java +++ b/src/main/java/frc/robot/subsystems/Arm.java @@ -21,6 +21,9 @@ public class Arm extends SubsystemBase { + public double armToFrontAngle = 3; + public double armToBackAngle = -3; + public CANSparkMax armMotor; public DigitalInput allTheWayDownRear = new DigitalInput(1); public double desiredArmAngle; @@ -96,11 +99,15 @@ public void moveArm(double value) { armMotor.set(motorDrive); } - public void moveArmToZeroDeg() { - } + @Override public void simulationPeriodic() { // This method will be called once per scheduler run during simulation } + + public void setArmAngle(double angle) { + desiredArmAngle = angle; + armPID.setReference(angle, CANSparkMax.ControlType.kPosition); + } } diff --git a/src/main/java/frc/robot/subsystems/Tracking/Arm.java b/src/main/java/frc/robot/subsystems/Tracking/Arm.java deleted file mode 100644 index 51ecd17..0000000 --- a/src/main/java/frc/robot/subsystems/Tracking/Arm.java +++ /dev/null @@ -1,21 +0,0 @@ -// 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.Tracking; - -import edu.wpi.first.wpilibj2.command.SubsystemBase; -import com.revrobotics.CANSparkMax; - -public class Arm extends SubsystemBase { - - /** Creates a new Arm. */ - public Arm() { - - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - } -} diff --git a/src/main/java/frc/robot/subsystems/Tracking/Target.java b/src/main/java/frc/robot/subsystems/Tracking/Target.java index 33a9d44..9f82262 100644 --- a/src/main/java/frc/robot/subsystems/Tracking/Target.java +++ b/src/main/java/frc/robot/subsystems/Tracking/Target.java @@ -20,7 +20,7 @@ import frc.robot.LimelightHelpers; public class Target extends SubsystemBase { - private String name = "limelight"; + private static String name = "limelight"; private double tx; private double ty; private double ta; @@ -36,6 +36,7 @@ public class Target extends SubsystemBase { private GenericEntry taEntry; private GenericEntry tclassEntry; private GenericEntry targetedEntry; + private static LimelightHelpers limelightHelpers = new LimelightHelpers(); /** Creates a new Target. */ public Target() { @@ -65,9 +66,9 @@ public Target() { @Override public void periodic() { // This method will be called once per scheduler run - tx = LimelightHelpers.getTX(name); - ty = LimelightHelpers.getTY(name); - ta = LimelightHelpers.getTA(name); + tx = limelightHelpers.getTX(name); + ty = limelightHelpers.getTY(name); + ta = limelightHelpers.getTA(name); tclass = NetworkTableInstance.getDefault().getTable(name).getEntry("tclass").getDouble(0); txEntry.setDouble(tx); @@ -75,4 +76,17 @@ public void periodic() { taEntry.setDouble(ta); tclassEntry.setDouble(tclass); } + + public static double getTX() { + return NetworkTableInstance.getDefault().getTable(name).getEntry("tx").getDouble(0); + } + public double getTY() { + return NetworkTableInstance.getDefault().getTable(name).getEntry("ty").getDouble(0); + } + public double getTA() { + return NetworkTableInstance.getDefault().getTable(name).getEntry("ta").getDouble(0); + } + public double getTClass() { + return NetworkTableInstance.getDefault().getTable(name).getEntry("tclass").getDouble(0); + } }