diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 4ebb994..6c2448d 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -129,6 +129,7 @@ public void teleopInit() { if (m_autonomousCommand != null) { m_autonomousCommand.cancel(); } + m_robotContainer.configureTeleopBindings(); } /** This function is called periodically during operator control. */ @@ -141,8 +142,7 @@ public void testInit() { CommandScheduler.getInstance().cancelAll(); SignalLogger.stop(); - // m_robotContainer.removeSubsystemDefaultCommands(); - // m_robotContainer.configureTestBindings(); + m_robotContainer.configureTestBindings(); } /** This function is called periodically during test mode. */ diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index deccbe3..853e2f8 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -63,7 +63,6 @@ public class RobotContainer { private final DriveState driveState = DriveState.getInstance(); private final LaunchState launchState = LaunchState.getInstance(); - /* private final Command driveAndLaunchCommand = drivetrain .applyRequest(() -> getDriveAndLaunchRequest()) @@ -83,14 +82,13 @@ public class RobotContainer { .stopFullIndexingNoPID() .andThen(shooter.stopFlywheelCommand()) .andThen(shooter.stowHood()); - */ private final SendableChooser autoChooser; public RobotContainer() { NamedCommands.registerCommand("Seed", drivetrain.runOnce(drivetrain::seedFieldCentric)); - // NamedCommands.registerCommand("AutonShoot", autonShootCommand); - // NamedCommands.registerCommand("StopShot", stopShotCommand); + NamedCommands.registerCommand("AutonShoot", autonShootCommand); + NamedCommands.registerCommand("StopShot", stopShotCommand); NamedCommands.registerCommand("StopRoller", intake.stopRollerNoPID()); NamedCommands.registerCommand( "Collect Intake", @@ -126,7 +124,6 @@ public RobotContainer() { .withName("Rumble & Set Pose")); configureSubsystemDefaultCommands(); - configureTeleopBindings(); } public void configureSubsystemDefaultCommands() { @@ -163,11 +160,6 @@ public void configureSubsystemDefaultCommands() { .withName("Teleop Drive")); } - public void removeSubsystemDefaultCommands() { - drivetrain.removeDefaultCommand(); - } - - /* public void configureTestBindings() { // Idle while the robot is disabled. This ensures the configured // neutral mode is applied to the drive motors while disabled. @@ -194,14 +186,13 @@ public void configureTestBindings() { driverJoystick .a() - .whileTrue(driveAndLaunchCommand) + .whileTrue(driveAndLaunchCommand.alongWith(indexer.startFullIndexingNoPID())) .onFalse(shooter.stopFlywheelCommand().andThen(shooter.stowHood())); driverJoystick.b().onTrue(intake.testRollerNoPID()).onFalse(intake.stopRollerNoPID()); driverJoystick.x().onTrue(intake.spinRollerCommand()).onFalse(intake.stopRollerCommand()); } - */ public void configureTeleopBindings() { driverJoystick @@ -213,14 +204,13 @@ public void configureTeleopBindings() { .leftBumper() .onTrue( intake - .stopRollerNoPID() + .stopRollerCommand() .andThen(intake.setIntakeExtensionCommand(IntakeConstants.INTAKE_REVERSE_LIMIT)) .withName("Stow Intake")); // stop the roller without retracting. driverJoystick.x().onTrue(intake.stopRollerNoPID()); - /* // outtake fuel. don't retract when done. driverJoystick .b() @@ -233,14 +223,15 @@ public void configureTeleopBindings() { .onFalse( intake.stopRollerNoPID().andThen(indexer.stopIndexerNoPID()).withName("Stop Roller")); + driverJoystick.rightTrigger().onTrue(shooter.spinFlywheelCommand()); + operatorJoystick .rightTrigger() .whileTrue( drivetrain .setXCommand() - .alongWith(indexer.pulsingIndexCommand()) - .withName("Lock Wheels and Index")) - .onFalse(indexer.stopFullIndexingNoPID()); + .alongWith(indexer.startFullIndexingNoPID()) + .withName("Lock Wheels and Index")); operatorJoystick .leftTrigger() @@ -256,7 +247,6 @@ public void configureTeleopBindings() { .rightBumper() .whileTrue(shooter.spinFlywheelPostCommand()) .onFalse(shooter.stopFlywheelCommand().andThen(shooter.stowHood())); - */ // Reset the field-centric heading on start button press. driverJoystick @@ -302,11 +292,6 @@ public void configureTeleopBindings() { .manualRumbleCommand(driverJoystick.getHID()) .withName("Rumble Driver Controller")); - operatorJoystick.rightTrigger().whileTrue(indexer.startFullIndexingNoPID()); - operatorJoystick.a().onTrue(shooter.setHoodTargetCommand()); - operatorJoystick.leftBumper().onTrue(shooter.setFlywheelOutputCommand()); - operatorJoystick.rightBumper().onTrue(shooter.stopFlywheelOutputCommand()); - drivetrain.registerTelemetry(logger::telemeterize); SmartDashboard.putData( diff --git a/src/main/java/frc/robot/subsystems/indexer/IndexerPreferences.java b/src/main/java/frc/robot/subsystems/indexer/IndexerPreferences.java index 67920cd..2a9c1e8 100644 --- a/src/main/java/frc/robot/subsystems/indexer/IndexerPreferences.java +++ b/src/main/java/frc/robot/subsystems/indexer/IndexerPreferences.java @@ -9,25 +9,15 @@ private IndexerPreferences() {} protected static DoublePreference indexerPercent = new DoublePreference("Indexer/Index Percent (for without PID)", 0.1); // in percent - protected static DoublePreference acceleratorPercent = - new DoublePreference("Indexer/Accelerator Percent (for without PID)", 0.1); // in percent - - /* - protected static DoublePreference indexSpeed = - new DoublePreference("Indexer/Index Speed (RotationsPS)", 0.1); // in rotations per second - protected static DoublePreference indexerReversePercent = new DoublePreference("Indexer/Reverse Index Percent (for without PID)", -0.1); // in percent - protected static DoublePreference accelerateSpeed = - new DoublePreference( - "Indexer/Accelerate Speed (RotationsPS)", 0.1); // in rotations per second - + protected static DoublePreference acceleratorPercent = + new DoublePreference("Indexer/Accelerator Percent (for without PID)", 0.1); // in percent protected static DoublePreference indexerRunTime = new DoublePreference("Indexer/Pulsing Run Time", 2.0); // in seconds protected static DoublePreference indexerPauseTime = new DoublePreference("Indexer/Pulsing Pause Time", 0.1); // in seconds - */ } diff --git a/src/main/java/frc/robot/subsystems/indexer/IndexerSubsystem.java b/src/main/java/frc/robot/subsystems/indexer/IndexerSubsystem.java index b03b18f..0ef0b0e 100644 --- a/src/main/java/frc/robot/subsystems/indexer/IndexerSubsystem.java +++ b/src/main/java/frc/robot/subsystems/indexer/IndexerSubsystem.java @@ -3,11 +3,9 @@ import static edu.wpi.first.units.Units.Volts; import com.ctre.phoenix6.SignalLogger; -import com.ctre.phoenix6.controls.VelocityVoltage; import com.ctre.phoenix6.hardware.TalonFX; import edu.wpi.first.epilogue.Logged; -import edu.wpi.first.epilogue.Logged.Importance; -import edu.wpi.first.units.measure.AngularVelocity; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; @@ -17,15 +15,6 @@ public class IndexerSubsystem extends SubsystemBase { private final TalonFX indexerMotor; private final TalonFX acceleratorMotor; - @Logged(name = "Indexer Velocity Target", importance = Importance.CRITICAL) - private AngularVelocity indexerVelocityTarget; // RotationsPerSecond - - @Logged(name = "Accelerator Velocity Target", importance = Importance.CRITICAL) - private AngularVelocity acceleratorVelocityTarget; - - private VelocityVoltage indexerControl; - private VelocityVoltage acceleratorControl; - final SysIdRoutine m_sysIdRoutineIndexer = new SysIdRoutine( new SysIdRoutine.Config( @@ -86,22 +75,6 @@ private void setAcceleratorVoltage(double magnitude) { acceleratorMotor.setVoltage(magnitude); } - // Indexer Commands - public Command startIndexerNoPID() { - return runEnd( - () -> indexerMotor.set(IndexerPreferences.indexerPercent.getValue()), - () -> indexerMotor.set(0)) - .withName("Set Indexer Percent"); - } - - // Accelerator Commands - public Command startAcceleratorNoPID() { - return runEnd( - () -> acceleratorMotor.set(IndexerPreferences.acceleratorPercent.getValue()), - () -> acceleratorMotor.set(0)) - .withName("Set Acceleration Percent"); - } - public Command startFullIndexingNoPID() { return runEnd( () -> { @@ -123,9 +96,8 @@ public Command stopFullIndexingNoPID() { .withName("Stop Full Indexing No PID"); } - /* public Command startIndexerReverseNoPID() { - return run(() -> indexerMotor.set(IndexerPreferences.indexerReversePercent.getValue())) + return runOnce(() -> indexerMotor.set(IndexerPreferences.indexerReversePercent.getValue())) .withName("Set Indexer Reverse Percent"); } @@ -133,6 +105,8 @@ public Command stopIndexerNoPID() { return runOnce(() -> indexerMotor.set(0)).withName("Stop Indexer Percent"); } + /* + public Command stopAcceleratorNoPID() { return runOnce(() -> acceleratorMotor.set(0)).withName("Stop Accelerator Percent"); } @@ -172,6 +146,8 @@ public Command stopCommand() { .withName("Stop Indexing Lemons"); } + */ + public Command pulsingIndexCommand() { Timer timer = new Timer(); return runEnd( @@ -192,5 +168,4 @@ public Command pulsingIndexCommand() { .beforeStarting(() -> timer.restart()) .withName("Pulsing Index"); } - */ } diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeSubsystem.java b/src/main/java/frc/robot/subsystems/intake/IntakeSubsystem.java index 677d837..baf3906 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeSubsystem.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeSubsystem.java @@ -16,12 +16,10 @@ import edu.wpi.first.units.measure.Angle; import edu.wpi.first.units.measure.AngularVelocity; import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.CommandScheduler; import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wpilibj2.command.WaitCommand; import edu.wpi.first.wpilibj2.command.WaitUntilCommand; -import edu.wpi.first.wpilibj2.command.button.RobotModeTriggers; import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; @Logged @@ -99,12 +97,14 @@ public IntakeSubsystem() { public void periodic() { // rollerMotor.setControl(rollerControl.withVelocity(rollerVelocityTarget.in(RotationsPerSecond))); + /* if (extensionMotor.getStatorCurrent().getValueAsDouble() > IntakePreferences.resistanceCurrentLimit.getValue() && isCompliantMode && RobotModeTriggers.teleop().getAsBoolean()) CommandScheduler.getInstance() .schedule(stopRollerNoPID().andThen(setIntakeExtensionCommand(0))); + */ extensionMotor.setControl( extensionControl @@ -161,10 +161,14 @@ public boolean atExtensionSetpoint() { } public Command setIntakeExtensionCommand(double rotations) { + /* return runOnce(() -> isCompliantMode = false) .andThen(runOnce(() -> extensionTarget = Rotations.of(rotations))) .andThen(Commands.waitUntil(() -> atExtensionSetpoint())) .finallyDo(() -> isCompliantMode = true); + */ + return runOnce(() -> extensionTarget = Rotations.of(rotations)) + .andThen(Commands.waitUntil(() -> atExtensionSetpoint())); } public Command setExtendNoPID() { diff --git a/src/main/java/frc/robot/subsystems/shooter/MappedLaunchRequestBuilder.java b/src/main/java/frc/robot/subsystems/shooter/MappedLaunchRequestBuilder.java index b68db1b..91cf73f 100644 --- a/src/main/java/frc/robot/subsystems/shooter/MappedLaunchRequestBuilder.java +++ b/src/main/java/frc/robot/subsystems/shooter/MappedLaunchRequestBuilder.java @@ -16,9 +16,6 @@ /** Add your docs here. */ public class MappedLaunchRequestBuilder implements LaunchRequestBuilder { - private static final double minDistance; - private static final double maxDistance; - // Launching Maps // private static final InterpolatingTreeMap hoodAngleMap = // new InterpolatingTreeMap<>(InverseInterpolator.forDouble(), Rotation2d::interpolate); @@ -26,25 +23,41 @@ public class MappedLaunchRequestBuilder implements LaunchRequestBuilder { private static final InterpolatingDoubleTreeMap flywheelSpeedMap = new InterpolatingDoubleTreeMap(); - // TODO: All of this is made up. Need real numbers. static { - minDistance = 0.9; - maxDistance = 4.0; + hoodAngleMap.put(1.3, 0.0); + hoodAngleMap.put(2.0, 0.6); + hoodAngleMap.put(2.6, 1.4); + hoodAngleMap.put(3.1, 1.8); + hoodAngleMap.put(3.21, 2.2); + hoodAngleMap.put(3.7, 2.6); + hoodAngleMap.put(4.2, 2.6); + hoodAngleMap.put(5.4, 3.0); + + flywheelSpeedMap.put(1.3, 51.9); + flywheelSpeedMap.put(2.0, 54.5); + flywheelSpeedMap.put(2.6, 57.1); + flywheelSpeedMap.put(3.1, 62.4); + flywheelSpeedMap.put(3.21, 62.2); + flywheelSpeedMap.put(3.7, 65.0); + flywheelSpeedMap.put(4.2, 67.6); + flywheelSpeedMap.put(5.4, 78.1); + /* Old shooter settings hoodAngleMap.put(0.99, 0.0); hoodAngleMap.put(1.62, 1.0); hoodAngleMap.put(1.94, 2.1); hoodAngleMap.put(2.53, 3.3); hoodAngleMap.put(3.00, 4.0); hoodAngleMap.put(3.51, 4.0); - hoodAngleMap.put(6.00, 6.1); // put in a value to max out the hood + hoodAngleMap.put(6.00, 6.1); flywheelSpeedMap.put(0.99, 57.7); flywheelSpeedMap.put(1.62, 64.3); flywheelSpeedMap.put(1.94, 64.7); flywheelSpeedMap.put(3.00, 74.5); flywheelSpeedMap.put(3.51, 80.0); - flywheelSpeedMap.put(6.00, 108.0); // put in a value to max out the hood + flywheelSpeedMap.put(6.00, 108.0); + */ } public LaunchRequest createLaunchRequest( diff --git a/src/main/java/frc/robot/subsystems/shooter/ShooterConstants.java b/src/main/java/frc/robot/subsystems/shooter/ShooterConstants.java index 5881ae3..1ae593b 100644 --- a/src/main/java/frc/robot/subsystems/shooter/ShooterConstants.java +++ b/src/main/java/frc/robot/subsystems/shooter/ShooterConstants.java @@ -3,12 +3,15 @@ import static edu.wpi.first.units.Units.*; import com.ctre.phoenix6.configs.CurrentLimitsConfigs; +import com.ctre.phoenix6.configs.MotionMagicConfigs; import com.ctre.phoenix6.configs.MotorOutputConfigs; import com.ctre.phoenix6.configs.Slot0Configs; import com.ctre.phoenix6.configs.SoftwareLimitSwitchConfigs; +import com.ctre.phoenix6.controls.DutyCycleOut; import com.ctre.phoenix6.signals.InvertedValue; import com.ctre.phoenix6.signals.NeutralModeValue; import edu.wpi.first.units.measure.Angle; +import edu.wpi.first.units.measure.Current; import edu.wpi.first.units.measure.Distance; public class ShooterConstants { @@ -60,6 +63,19 @@ public static SoftwareLimitSwitchConfigs createHoodSoftwareLimitSwitchConfigs() return configs; } + public static final double HOOD_MAX_VELOCITY_RPS = 5; + public static final double HOOD_MAX_ACCELERATION_RPS2 = 10; + public static final double HOOD_MAX_JERK_RPS2 = 10; + + public static MotionMagicConfigs createHoodMotionMagicConfigs() { + MotionMagicConfigs configs = new MotionMagicConfigs(); + configs.MotionMagicCruiseVelocity = HOOD_MAX_VELOCITY_RPS; + configs.MotionMagicAcceleration = HOOD_MAX_ACCELERATION_RPS2; + configs.MotionMagicJerk = HOOD_MAX_JERK_RPS2; + + return configs; + } + public static final double FLYWHEEL_CURRENT_LIMIT = 40; public static CurrentLimitsConfigs createFlywheelCurrentLimitsConfigs() { @@ -80,17 +96,18 @@ public static CurrentLimitsConfigs createHoodCurrentLimitsConfigs() { public static final double HOOD_KS = 4.8; public static final double HOOD_KP = 9; - public static final double HOOD_KD = 0; + public static final double HOOD_KD = 0.1; + public static final double HOOD_KI = 1; public static Slot0Configs createHoodMotorSlot0Configs() { Slot0Configs slot = new Slot0Configs(); slot.kS = HOOD_KS; slot.kP = HOOD_KP; + slot.kI = HOOD_KI; slot.kD = HOOD_KD; return slot; } - // TODO: Tune Flywheel and Hood Motor // Flywheel motor @@ -106,33 +123,11 @@ public static Slot0Configs createFlywheelMotorSlot0Configs() { return slot; } - - /* public static final double ALLOWABLE_HOOD_ERROR = 0.1; - public static final double HOOD_FORWARD_LIMIT = 6.2; - public static final double HOOD_REVERSE_LIMIT = 0; - - public static SoftwareLimitSwitchConfigs createHoodSoftwareLimitSwitchConfigs() { - SoftwareLimitSwitchConfigs configs = new SoftwareLimitSwitchConfigs(); - configs.ForwardSoftLimitEnable = true; - configs.ReverseSoftLimitEnable = true; - configs.ForwardSoftLimitThreshold = HOOD_FORWARD_LIMIT; - configs.ReverseSoftLimitThreshold = HOOD_REVERSE_LIMIT; - return configs; - } - - public static MotorOutputConfigs createHoodMotorOutputConfigs() { - MotorOutputConfigs newConfigs = new MotorOutputConfigs(); - newConfigs.Inverted = InvertedValue.CounterClockwise_Positive; - newConfigs.NeutralMode = NeutralModeValue.Brake; - return newConfigs; - } - public static final DutyCycleOut SAFE_HOMING_EFFORT = new DutyCycleOut(-0.2); public static final Current SAFE_STATOR_LIMIT = Amp.of(0.8); - */ // Conversion Constants public static final Angle ROTATIONS_PER_LAUNCH_DEGREE = Rotations.of(0.2); public static final Distance FLYWHEEL_RADIUS = Inch.of(2); diff --git a/src/main/java/frc/robot/subsystems/shooter/ShooterPreferences.java b/src/main/java/frc/robot/subsystems/shooter/ShooterPreferences.java index 9708e39..c4ec371 100644 --- a/src/main/java/frc/robot/subsystems/shooter/ShooterPreferences.java +++ b/src/main/java/frc/robot/subsystems/shooter/ShooterPreferences.java @@ -5,32 +5,25 @@ public class ShooterPreferences { private ShooterPreferences() {} - public static DoublePreference hoodTargetPreference = - new DoublePreference("Shooter/Hood/Target Rotations", 0); + public static DoublePreference flywheelLaunchSpeed = + new DoublePreference("Shooter/Launch Speed", 0.1); // in rotations per second - public static DoublePreference flywheelLaunchPercent = - new DoublePreference("Shooter/Launch Percent (for without PID)", 0.1); // in percent + public static DoublePreference hoodLaunchAngle = + new DoublePreference("Shooter/Hood Launch Position", 3); // in rotations - /* - public static DoublePreference flywheelLaunchSpeed = - new DoublePreference("Shooter/Launch Speed", 0.1); // in rotations per second - public static DoublePreference hoodLaunchAngle = - new DoublePreference("Shooter/Hood Launch Position", 3); // in rotations + public static DoublePreference hoodkP = new DoublePreference("Shooter/Hood/kP", 1); + public static DoublePreference hoodkD = new DoublePreference("Shooter/Hood/kD", 0); - public static DoublePreference hoodkP = new DoublePreference("Shooter/Hood/kP", 1); - public static DoublePreference hoodkD = new DoublePreference("Shooter/Hood/kD", 0); + // unit is *radians per second** for velocity. + public static DoublePreference tuningDefaultFlywheelRPS = + new DoublePreference("Shooter/Tuning/FlywheelRPS", 1000.0 / 60.0 / 2 * Math.PI); + public static DoublePreference tuningDefaultFlywheelStepRPS = + new DoublePreference("Shooter/Tuning/FlywheelStepRPS", 100.0 / 60.0 / 2 * Math.PI); + public static DoublePreference tuningDefaultHoodRotations = + new DoublePreference("Shooter/Tuning/HoodRotations", 0.0); + public static DoublePreference tuningDefaultHoodStepRotations = + new DoublePreference("Shooter/Tuning/HoodStepRotations", 0.2); - // unit is *radians per second** for velocity. - public static DoublePreference tuningDefaultFlywheelRPS = - new DoublePreference("Shooter/Tuning/FlywheelRPS", 1000.0 / 60.0 / 2 * Math.PI); - public static DoublePreference tuningDefaultFlywheelStepRPS = - new DoublePreference("Shooter/Tuning/FlywheelStepRPS", 100.0 / 60.0 / 2 * Math.PI); - public static DoublePreference tuningDefaultHoodRotations = - new DoublePreference("Shooter/Tuning/HoodRotations", 0.0); - public static DoublePreference tuningDefaultHoodStepRotations = - new DoublePreference("Shooter/Tuning/HoodStepRotations", 0.2); - - */ public static DoublePreference passingFlywheelSpeed = new DoublePreference("Shooter/Tuning/Flywheel Pass Speed", 62); } diff --git a/src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java b/src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java index fd0a0bb..144ed5e 100644 --- a/src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java +++ b/src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java @@ -3,14 +3,19 @@ import static edu.wpi.first.units.Units.*; import com.ctre.phoenix6.SignalLogger; +import com.ctre.phoenix6.controls.Follower; import com.ctre.phoenix6.controls.PositionVoltage; +import com.ctre.phoenix6.controls.VelocityVoltage; import com.ctre.phoenix6.hardware.TalonFX; +import com.ctre.phoenix6.signals.MotorAlignmentValue; import edu.wpi.first.epilogue.Logged; import edu.wpi.first.epilogue.Logged.Importance; import edu.wpi.first.units.measure.Angle; +import edu.wpi.first.units.measure.AngularVelocity; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; +import frc.robot.statemachines.LaunchState; @Logged public class ShooterSubsystem extends SubsystemBase { @@ -19,14 +24,12 @@ public class ShooterSubsystem extends SubsystemBase { private final TalonFX flywheelMotorLeftFollower; private final TalonFX hoodMotor; - /* @Logged(name = "Velocity Target rads/s", importance = Importance.CRITICAL) private AngularVelocity velocityTarget; // *rads* Per Second is the base unit. private VelocityVoltage velocityControl; private final LaunchState launchState = LaunchState.getInstance(); - */ @Logged(name = "Hood Target (radians)", importance = Importance.CRITICAL) private Angle hoodTarget; // radians is the base unit. @@ -36,7 +39,7 @@ public class ShooterSubsystem extends SubsystemBase { final SysIdRoutine m_sysIdRoutineFlywheel = new SysIdRoutine( new SysIdRoutine.Config( - null, // Use default ramp rate (1 V/s) + Volts.per(Second).of(0.2), // Use default ramp rate (1 V/s) Volts.of(4), // Reduce dynamic step voltage to 4 V to prevent brownout null, // Use default timeout (10 s) // Log state with SignalLogger class @@ -74,10 +77,20 @@ public ShooterSubsystem() { hoodMotor.getConfigurator().apply(ShooterConstants.createHoodSoftwareLimitSwitchConfigs()); + hoodMotor.getConfigurator().apply(ShooterConstants.createHoodMotionMagicConfigs()); + hoodMotor.getConfigurator().apply(ShooterConstants.createHoodMotorSlot0Configs()); + flywheelMotorLeftFollower.setControl(new Follower(5, MotorAlignmentValue.Aligned)); + flywheelMotorRight.setControl(new Follower(5, MotorAlignmentValue.Opposed)); + hoodTarget = Rotations.of(0); hoodControl = new PositionVoltage(hoodTarget); + + velocityTarget = RotationsPerSecond.of(0); + velocityControl = new VelocityVoltage(velocityTarget); + + hoodMotor.setPosition(0); } private void setFlywheelVoltage(double magnitude) { @@ -88,33 +101,10 @@ private void setFlywheelVoltage(double magnitude) { @Override public void periodic() { - /* launchState.refreshRequest(); - flywheelMotorLeader.setControl( - velocityControl.withVelocity(velocityTarget.in(RotationsPerSecond))); - flywheelRightFollower.setControl( + flywheelMotorLeftLeader.setControl( velocityControl.withVelocity(velocityTarget.in(RotationsPerSecond))); hoodMotor.setControl(hoodControl.withPosition(hoodTarget)); - flywheelLeftFollower.setControl( - velocityControl.withVelocity(velocityTarget.in(RotationsPerSecond))); - */ - // hoodMotor.setControl(hoodControl.withPosition(hoodTarget)); - } - - public Command setHoodTargetCommand() { - return runOnce( - () -> hoodTarget = Rotations.of(ShooterPreferences.hoodTargetPreference.getValue())) - .withName("Set Hood Target"); - } - - public Command setFlywheelOutputCommand() { - return runOnce( - () -> setFlywheelMotorOutput(ShooterPreferences.flywheelLaunchPercent.getValue())) - .withName("Set Flywheel Output"); - } - - public Command stopFlywheelOutputCommand() { - return runOnce(() -> setFlywheelMotorOutput(0)).withName("Stop Flywheel Output"); } public void setFlywheelMotorOutput(double output) { @@ -123,17 +113,22 @@ public void setFlywheelMotorOutput(double output) { flywheelMotorRight.set(output); } - /* - @Logged(name = "Velocity Target RPM", importance = Importance.CRITICAL) - public double getFlywheelTargetRPM() { - return velocityTarget.in(RotationsPerSecond) * 60; - } - @Logged(name = "Hood Angle Rotations", importance = Importance.CRITICAL) public double getHoodTargetRotations() { return hoodTarget.in(Rotations); } + @Logged(name = "At Hood Setpoint", importance = Importance.CRITICAL) + public boolean atHoodSetpoint() { + return Math.abs(hoodMotor.getPosition().getValueAsDouble() - hoodTarget.in(Rotations)) + < ShooterConstants.ALLOWABLE_HOOD_ERROR; + } + + @Logged(name = "Velocity Target RPM", importance = Importance.CRITICAL) + public double getFlywheelTargetRPM() { + return velocityTarget.in(RotationsPerSecond) * 60; + } + public Command spinFlywheelCommand() { return runOnce( () -> { @@ -144,23 +139,6 @@ public Command spinFlywheelCommand() { .withName("Start Spinning Flywheel"); } - public Command spinFlywheelPostCommand() { - return runOnce( - () -> { - velocityTarget = RotationsPerSecond.of(74.5); - hoodTarget = Rotations.of(4); - }) - .withName("Start Spinning Flywheel"); - } - - public Command spinFlywheelCommand(AngularVelocity v) { - return runOnce(() -> velocityTarget = v).withName("Spinning To AV"); - } - - public Command spinFlyWheelCommand(DoublePreference d) { - return runOnce(() -> velocityTarget = RotationsPerSecond.of(d.getValue())); - } - public Command stopFlywheelCommand() { return runOnce(() -> velocityTarget = RotationsPerSecond.of(0)) .withName("Stop Spinning Flywheel"); @@ -170,76 +148,6 @@ public Command stowHood() { return runOnce(() -> hoodTarget = Rotations.of(0)); } - public Command setHoodToPreference() { - return runOnce( - () -> hoodTarget = Rotations.of(ShooterPreferences.hoodTargetPreference.getValue())); - } - - @Logged(name = "At Hood Setpoint", importance = Importance.CRITICAL) - public boolean atHoodSetpoint() { - return Math.abs(hoodMotor.getPosition().getValueAsDouble() - hoodTarget.in(Rotations)) - < ShooterConstants.ALLOWABLE_HOOD_ERROR; - } - - public Command setHoodCommand(Angle position) { - return runOnce(() -> hoodTarget = position) - .andThen(Commands.waitUntil(() -> atHoodSetpoint())) - .withName("Set Hood Angle"); - } - - public Command spinFlywheelRanged() { - return run( - () -> { - velocityTarget = launchState.getLaunchRequest().getFlywheelVelocity(); - hoodTarget = launchState.getLaunchRequest().getHoodTarget(); - }); - } - - public Command spinFlywheelHardCoded() { - return run( - () -> { - velocityTarget = RotationsPerSecond.of(66.5); - hoodTarget = Rotations.of(2.38); - }); - } - - public Command launchLemonsCommandNoPID() { - return setHoodCommand(Rotations.of(ShooterPreferences.hoodLaunchAngle.getValue())) - .andThen( - runOnce( - () -> { - flywheelMotorLeader.set(ShooterPreferences.flywheelLaunchPercent.getValue()); - flywheelMotorFollower.set(ShooterPreferences.flywheelLaunchPercent.getValue()); - })) - .withName("Start Launching Lemons (No PID)"); - } - - public Command stopLaunchLemonsNoPIDCommand() { - return setHoodCommand(Rotations.of(0)) - .andThen( - runOnce( - () -> { - flywheelMotorLeader.set(0); - flywheelMotorFollower.set(0); - })) - .withName("Stop Launching Lemons (No PID)"); - } - - public Command stowCommand() { - return stopFlywheelCommand().andThen(setHoodCommand(Rotations.of(0))).withName("Stow Shooter"); - } - - public Command homeShooterCommand() { - return runEnd( - () -> hoodMotor.set(ShooterConstants.SAFE_HOMING_EFFORT.Output), - () -> hoodMotor.setPosition(0)) - .until( - () -> { - return hoodMotor.getStatorCurrent().getValueAsDouble() - > ShooterConstants.SAFE_STATOR_LIMIT.in(Amp); - }); - } - public Command increaseFlywheelCommand() { return runOnce( () -> @@ -281,19 +189,46 @@ public Command decreaseHoodCommand() { } public Command startShooterTuningCommand() { - return spinFlyWheelCommand(ShooterPreferences.tuningDefaultFlywheelRPS) - .andThen( - setHoodCommand(Rotations.of(ShooterPreferences.tuningDefaultHoodRotations.getValue()))) + return runOnce( + () -> { + velocityTarget = + RotationsPerSecond.of(ShooterPreferences.tuningDefaultFlywheelRPS.getValue()); + hoodTarget = Rotations.of(ShooterPreferences.tuningDefaultHoodRotations.getValue()); + }) .withName("Start Shooter Tuning"); } public Command stopShooterTuningCommand() { - return stopFlywheelCommand() - .andThen( - setHoodCommand(Rotations.of(ShooterPreferences.tuningDefaultHoodRotations.getValue()))) - .withName("Stop Shooter Tuning"); + return stopFlywheelCommand().andThen(stowHood()).withName("Stop Shooter Tuning"); + } + + public Command spinFlywheelPostCommand() { + return runOnce( + () -> { + velocityTarget = RotationsPerSecond.of(74.5); + hoodTarget = Rotations.of(4); + }) + .withName("Start Spinning Flywheel"); + } + + public Command spinFlywheelRanged() { + return run( + () -> { + velocityTarget = launchState.getLaunchRequest().getFlywheelVelocity(); + hoodTarget = launchState.getLaunchRequest().getHoodTarget(); + }); + } + + public Command homeShooterCommand() { + return runEnd( + () -> hoodMotor.set(ShooterConstants.SAFE_HOMING_EFFORT.Output), + () -> hoodMotor.setPosition(0)) + .until( + () -> { + return hoodMotor.getStatorCurrent().getValueAsDouble() + > ShooterConstants.SAFE_STATOR_LIMIT.in(Amp); + }); } - */ public Command sysIdQuasistatic(SysIdRoutine.Direction direction) { return m_sysIdRoutineFlywheel.quasistatic(direction); diff --git a/src/main/java/frc/robot/subsystems/vision/VisionConstants.java b/src/main/java/frc/robot/subsystems/vision/VisionConstants.java index 6eb0399..992c0d4 100644 --- a/src/main/java/frc/robot/subsystems/vision/VisionConstants.java +++ b/src/main/java/frc/robot/subsystems/vision/VisionConstants.java @@ -36,18 +36,17 @@ public class VisionConstants { put( photonCameraName_Front, new Transform3d( - new Translation3d(-0.1638, 0, 0.7192), - new Rotation3d(0, Math.toRadians(-20), 0))); + new Translation3d(0.13, 0, 0.696), new Rotation3d(0, Math.toRadians(-22), 0))); put( photonCameraName_Left, new Transform3d( - new Translation3d(-0.2680, 0.3164, 0.451), - new Rotation3d(0, Math.toRadians(-20), Math.toRadians(120)))); + new Translation3d(-0.252, 0.328, 0.715), + new Rotation3d(0, 0, Math.toRadians(160)))); put( photonCameraName_Right, new Transform3d( - new Translation3d(-0.2680, -0.3164, 0.451), - new Rotation3d(0, Math.toRadians(-20), Math.toRadians(-120)))); + new Translation3d(-0.252, -0.328, 0.715), + new Rotation3d(0, 0, Math.toRadians(-160)))); } };