Cleanup extender commands

This commit is contained in:
nathanrsxtn
2022-04-20 16:38:30 -06:00
parent 78965a3381
commit 91ab5650a3
15 changed files with 111 additions and 194 deletions
@@ -159,6 +159,7 @@ public final class Constants {
public static final class ExtenderConstants {
public static final double EXTENDER_FORWARD_LIMIT = 200.3;//250.0;
public static final double EXTENDER_REVERSE_LIMIT = 0.0;
public static final double EXTENDER_TOLERANCE = 5.0;
}
public static final class StorageConstants {
-2
View File
@@ -11,7 +11,6 @@ import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc4388.robot.commands.ExtenderIntakeCommands.ExtenderIntakeGroup;
/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
@@ -50,7 +49,6 @@ public class Robot extends TimedRobot {
// desmosServer.start();
m_robotContainer.m_robotVisionOdometry.setLEDs(false);
ExtenderIntakeGroup.setDirectionToOut();
}
/**
@@ -6,7 +6,6 @@ package frc4388.robot;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
@@ -25,6 +24,7 @@ import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.ConditionalCommand;
import edu.wpi.first.wpilibj2.command.PrintCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
@@ -33,10 +33,11 @@ import frc4388.robot.Constants.OIConstants;
import frc4388.robot.Constants.StorageConstants;
import frc4388.robot.Constants.SwerveDriveConstants;
import frc4388.robot.commands.AutonomousBuilder;
import frc4388.robot.commands.PathRecorder;
import frc4388.robot.commands.ExtenderIntakeCommands.ExtenderIntakeGroup;
import frc4388.robot.commands.extender.DeployExtender;
import frc4388.robot.commands.extender.RetractExtender;
import frc4388.robot.commands.shooter.TrackTarget;
import frc4388.robot.commands.shuffleboard.CommandSchedule;
import frc4388.robot.commands.shuffleboard.PathRecorder;
import frc4388.robot.commands.shuffleboard.ShooterTuner;
import frc4388.robot.subsystems.BoomBoom;
import frc4388.robot.subsystems.Camera;
@@ -264,7 +265,7 @@ public class RobotContainer {
button.whenPressed(m_robotClaws::toggleClaws, m_robotClaws);
} else if (binding == XboxController.Button.kX) {
/* X > Toggle Extender Deployment */
button.whenPressed(new ExtenderIntakeGroup(m_robotIntake, m_robotExtender));
button.whenPressed(new ConditionalCommand(new DeployExtender(m_robotExtender, m_robotIntake), new RetractExtender(m_robotExtender), m_robotExtender::isRetracted));
} else if (binding == XboxController.Button.kY) {
/* Y > Track Target */
button.whileHeld(new TrackTarget(m_robotVisionOdometry, m_robotTurret, m_robotHood, m_robotBoomBoom));
@@ -328,7 +329,6 @@ public class RobotContainer {
button.whenReleased(() -> m_robotTurret.m_boomBoomRotateEncoder.setPosition(0), m_robotTurret);
button.whenReleased(() -> m_robotHood.m_angleEncoder.setPosition(0), m_robotHood);
button.whenReleased(() -> m_robotExtender.setEncoder(0), m_robotExtender);
button.whenReleased(ExtenderIntakeGroup::setDirectionToOut, m_robotIntake, m_robotExtender);
button.whenReleased(() -> m_robotClimber.setEncoders(0), m_robotClimber);
} else if (binding == ButtonBox.Button.kRightButton) {
/* Right Button > Extender Out */
@@ -8,6 +8,7 @@ import edu.wpi.first.wpilibj2.command.WaitCommand;
import frc4388.robot.RobotContainer;
import frc4388.robot.Constants.AutoConstants;
import frc4388.robot.Constants.StorageConstants;
import frc4388.robot.commands.extender.DeployExtender;
import frc4388.robot.commands.shooter.TimedWaitUntilCommand;
import frc4388.robot.commands.shooter.TrackTarget;
import frc4388.robot.subsystems.BoomBoom;
@@ -85,8 +86,8 @@ public class AutonomousBuilder {
private Command buildStartupCommandPart() {
return CommandGroupBase.sequence(
new InstantCommand(() -> m_boomBoom.runDrumShooterVelocityPID(8000), m_boomBoom).withName("StartIdlingShooter"),
new InstantCommand(() -> m_intake.runAtOutput(-1), m_intake).withName("StartRunningIntake")
// new RunExtender(m_extender).withName("DeployExtender")
new InstantCommand(() -> m_intake.runAtOutput(-1), m_intake).withName("StartRunningIntake"),
new DeployExtender(m_extender, m_intake).withName("DeployExtender")
);
}
@@ -1,34 +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 frc4388.robot.commands.ExtenderIntakeCommands;
import edu.wpi.first.wpilibj2.command.ParallelRaceGroup;
import frc4388.robot.subsystems.Extender;
import frc4388.robot.subsystems.Intake;
// 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 ExtenderIntakeGroup extends ParallelRaceGroup {
public static int direction;
/** Creates a new RunExtenderAndIntake. */
public ExtenderIntakeGroup(Intake intake, Extender extender) {
// Add your commands in the addCommands() call, e.g.
// addCommands(new FooCommand(), new BarCommand());
// ExtenderIntakeGroup.direction = 1; // assume extender starts retracted completely
addCommands(new RunIntakeConditionally(intake), new RunExtender(extender));
}
public static void setDirectionToOut() {
ExtenderIntakeGroup.direction = 1;
}
public static void changeDirection() {
ExtenderIntakeGroup.direction *= -1;
}
}
@@ -1,66 +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 frc4388.robot.commands.ExtenderIntakeCommands;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.Constants.ExtenderConstants;
import frc4388.robot.subsystems.Extender;
import frc4388.robot.subsystems.Intake;
public class RunExtender extends CommandBase {
private Extender extender;
private double error;
private double tolerance;
/** Creates a new RunExtender. */
public RunExtender(Extender extender) {
// Use addRequirements() here to declare subsystem dependencies.
this.extender = extender;
updateError();
tolerance = 5.0;
addRequirements(this.extender);
}
public void updateError() {
if (ExtenderIntakeGroup.direction > 0) {
this.error = Math.abs(this.extender.getPosition() - ExtenderConstants.EXTENDER_FORWARD_LIMIT);
} else {
this.error = Math.abs(this.extender.getPosition() - ExtenderConstants.EXTENDER_REVERSE_LIMIT);
}
}
// 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() {
//System.out.println("RunExtender is working");
this.extender.runExtender(ExtenderIntakeGroup.direction * 1.0);
updateError();
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
ExtenderIntakeGroup.changeDirection();
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
if (error < tolerance) {
System.out.println("RunExtender finished");
this.extender.runExtender(0.0);
return true;
}
return false;
}
}
@@ -1,47 +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 frc4388.robot.commands.ExtenderIntakeCommands;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.Constants.IntakeConstants;
import frc4388.robot.subsystems.Intake;
public class RunIntakeConditionally extends CommandBase {
private Intake intake;
/** Creates a new RunIntakeConditionally. */
public RunIntakeConditionally(Intake intake) {
// Use addRequirements() here to declare subsystem dependencies.
this.intake = intake;
addRequirements(this.intake);
}
// 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 (ExtenderIntakeGroup.direction > 0) {
this.intake.runAtOutput(-1);
} else {
this.intake.runAtOutput(0);
}
}
// 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;
}
}
@@ -0,0 +1,33 @@
package frc4388.robot.commands.extender;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.subsystems.Extender;
import frc4388.robot.subsystems.Intake;
public class DeployExtender extends CommandBase {
private final Extender m_extender;
private final Intake m_intake;
public DeployExtender(Extender extender, Intake intake) {
m_extender = extender;
m_intake = intake;
addRequirements(extender, intake);
}
@Override
public void initialize() {
m_intake.runAtOutput(-1.0);
m_extender.runExtender(1.0);
}
@Override
public void end(boolean interrupted) {
m_intake.runAtOutput(0.0);
m_extender.runExtender(0.0);
}
@Override
public boolean isFinished() {
return m_extender.isDeployed();
}
}
@@ -0,0 +1,28 @@
package frc4388.robot.commands.extender;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.subsystems.Extender;
public class RetractExtender extends CommandBase {
private final Extender m_extender;
public RetractExtender(Extender extender) {
m_extender = extender;
addRequirements(extender);
}
@Override
public void initialize() {
m_extender.runExtender(-1.0);
}
@Override
public void end(boolean interrupted) {
m_extender.runExtender(0.0);
}
@Override
public boolean isFinished() {
return m_extender.isRetracted();
}
}
@@ -1,4 +1,4 @@
package frc4388.robot.commands;
package frc4388.robot.commands.shuffleboard;
import java.io.File;
import java.io.IOException;
@@ -36,6 +36,7 @@ import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.NotifierCommand;
import frc4388.robot.Constants.SwerveDriveConstants;
import frc4388.robot.commands.PathPlannerCommand;
import frc4388.robot.subsystems.SwerveDrive;
import frc4388.utility.PathPlannerUtil;
import frc4388.utility.PathPlannerUtil.Path.Waypoint;
@@ -17,7 +17,6 @@ import frc4388.robot.Constants.ExtenderConstants;
public class Extender extends SubsystemBase {
private CANSparkMax m_extenderMotor;
private double m_invert = 1;
// private SparkMaxLimitSwitch m_inLimit;
// private SparkMaxLimitSwitch m_outLimit;
@@ -47,10 +46,6 @@ public class Extender extends SubsystemBase {
m_extenderMotor.enableSoftLimit(SoftLimitDirection.kReverse, set);
}
public void invertExtender(double invert){
m_invert = invert;
}
@Override
public void periodic() {
// This method will be called once per scheduler run
@@ -58,8 +53,15 @@ public class Extender extends SubsystemBase {
}
public void runExtender(double input) {
// if (!m_serializer.getBeam() && input < 0.) return;
m_extenderMotor.set(input * m_invert);
m_extenderMotor.set(input);
}
public boolean isDeployed() {
return Math.abs(getPosition() - ExtenderConstants.EXTENDER_FORWARD_LIMIT) < ExtenderConstants.EXTENDER_TOLERANCE;
}
public boolean isRetracted() {
return Math.abs(getPosition() - ExtenderConstants.EXTENDER_REVERSE_LIMIT) < ExtenderConstants.EXTENDER_TOLERANCE;
}
public double getPosition() {
@@ -9,7 +9,6 @@ import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.robot.Constants.IntakeConstants;
import frc4388.robot.commands.ExtenderIntakeCommands.ExtenderIntakeGroup;
public class Intake extends SubsystemBase {
@@ -24,7 +23,6 @@ public class Intake extends SubsystemBase {
public void periodic() {
// This method will be called once per scheduler run
SmartDashboard.putNumber("Intake Percent Output", m_intakeMotor.get());
SmartDashboard.putNumber("Extender Direction", ExtenderIntakeGroup.direction);
}
/**
* Runs The Intake With Triggers as input
+5 -3
View File
@@ -1,7 +1,7 @@
{
"fileName": "PathplannerLib.json",
"name": "PathplannerLib",
"version": "2022.1.0",
"version": "2022.2.1",
"uuid": "1b42324f-17c6-4875-8e77-1c312bc8c786",
"mavenUrls": [
"https://3015rangerrobotics.github.io/pathplannerlib/repo"
@@ -11,7 +11,7 @@
{
"groupId": "com.pathplanner.lib",
"artifactId": "PathplannerLib-java",
"version": "2022.1.0"
"version": "2022.2.1"
}
],
"jniDependencies": [],
@@ -19,12 +19,14 @@
{
"groupId": "com.pathplanner.lib",
"artifactId": "PathplannerLib-cpp",
"version": "2022.1.0",
"version": "2022.2.1",
"libName": "PathplannerLib",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxx86-64",
"osxx86-64",
"linuxathena"
]
+21 -21
View File
@@ -1,7 +1,7 @@
{
"fileName": "Phoenix.json",
"name": "CTRE-Phoenix",
"version": "5.20.2",
"version": "5.21.2",
"frcYear": 2022,
"uuid": "ab676553-b602-441f-a38d-f1296eff6537",
"mavenUrls": [
@@ -12,19 +12,19 @@
{
"groupId": "com.ctre.phoenix",
"artifactId": "api-java",
"version": "5.20.2"
"version": "5.21.2"
},
{
"groupId": "com.ctre.phoenix",
"artifactId": "wpiapi-java",
"version": "5.20.2"
"version": "5.21.2"
}
],
"jniDependencies": [
{
"groupId": "com.ctre.phoenix",
"artifactId": "cci",
"version": "5.20.2",
"version": "5.21.2",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
@@ -34,7 +34,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "cci-sim",
"version": "5.20.2",
"version": "5.21.2",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
@@ -46,7 +46,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simTalonSRX",
"version": "5.20.2",
"version": "5.21.2",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
@@ -58,7 +58,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simTalonFX",
"version": "5.20.2",
"version": "5.21.2",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
@@ -70,7 +70,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simVictorSPX",
"version": "5.20.2",
"version": "5.21.2",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
@@ -82,7 +82,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simPigeonIMU",
"version": "5.20.2",
"version": "5.21.2",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
@@ -94,7 +94,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simCANCoder",
"version": "5.20.2",
"version": "5.21.2",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
@@ -108,7 +108,7 @@
{
"groupId": "com.ctre.phoenix",
"artifactId": "wpiapi-cpp",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_Phoenix_WPI",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -120,7 +120,7 @@
{
"groupId": "com.ctre.phoenix",
"artifactId": "api-cpp",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_Phoenix",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -132,7 +132,7 @@
{
"groupId": "com.ctre.phoenix",
"artifactId": "cci",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_PhoenixCCI",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -144,7 +144,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "wpiapi-cpp-sim",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_Phoenix_WPISim",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -158,7 +158,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "api-cpp-sim",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_PhoenixSim",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -172,7 +172,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "cci-sim",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_PhoenixCCISim",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -186,7 +186,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simTalonSRX",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_SimTalonSRX",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -200,7 +200,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simTalonFX",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_SimTalonFX",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -214,7 +214,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simVictorSPX",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_SimVictorSPX",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -228,7 +228,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simPigeonIMU",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_SimPigeonIMU",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -242,7 +242,7 @@
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "simCANCoder",
"version": "5.20.2",
"version": "5.21.2",
"libName": "CTRE_SimCANCoder",
"headerClassifier": "headers",
"sharedLibrary": true,
+4 -4
View File
@@ -1,7 +1,7 @@
{
"fileName": "photonlib.json",
"name": "photonlib",
"version": "v2022.1.5",
"version": "v2022.2.0",
"uuid": "515fe07e-bfc6-11fa-b3de-0242ac130004 ",
"mavenUrls": [
"https://maven.photonvision.org/repository/internal",
@@ -13,7 +13,7 @@
{
"groupId": "org.photonvision",
"artifactId": "PhotonLib-cpp",
"version": "v2022.1.5",
"version": "v2022.2.0",
"libName": "Photon",
"headerClassifier": "headers",
"sharedLibrary": true,
@@ -30,12 +30,12 @@
{
"groupId": "org.photonvision",
"artifactId": "PhotonLib-java",
"version": "v2022.1.5"
"version": "v2022.2.0"
},
{
"groupId": "org.photonvision",
"artifactId": "PhotonTargeting-java",
"version": "v2022.1.5"
"version": "v2022.2.0"
}
]
}