-
Notifications
You must be signed in to change notification settings - Fork 5
Midnight day 3, going to master #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ee0f9be
f714974
47099d1
41597d9
01af3c1
930c6e0
1ae1b61
c43a62f
ac5a1bc
e9ec266
0d1ca30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||
| package frc.robot.subsystems; | ||||
|
|
||||
| import com.revrobotics.spark.SparkLowLevel.MotorType; | ||||
|
||||
| import com.revrobotics.spark.SparkLowLevel.MotorType; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,126 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| package frc.robot.subsystems; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import com.thethriftybot.ThriftyNova; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import edu.wpi.first.math.controller.ArmFeedforward; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import edu.wpi.first.math.system.plant.DCMotor; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import edu.wpi.first.units.measure.Angle; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.Amps; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.Degrees; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.DegreesPerSecond; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.DegreesPerSecondPerSecond; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.Feet; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.Inches; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.Pounds; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.RPM; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import static edu.wpi.first.units.Units.Seconds; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import edu.wpi.first.wpilibj2.command.Command; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import edu.wpi.first.wpilibj2.command.Commands; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import frc.robot.Constants; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.gearing.GearBox; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.gearing.MechanismGearing; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.mechanisms.config.ArmConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.mechanisms.config.FlyWheelConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.mechanisms.positional.Arm; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.mechanisms.velocity.FlyWheel; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.motorcontrollers.SmartMotorController; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.motorcontrollers.SmartMotorControllerConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.motorcontrollers.SmartMotorControllerConfig.ControlMode; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.motorcontrollers.SmartMotorControllerConfig.MotorMode; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.motorcontrollers.SmartMotorControllerConfig.TelemetryVerbosity; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import yams.motorcontrollers.local.NovaWrapper; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| public class IntakeSubsystem extends SubsystemBase { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private static final double INTAKE_SPEED = 0.1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // ThriftyNova controlling the intake roller | ||||||||||||||||||||||||||||||||||||||||||||||||
| private ThriftyNova rollerNova = new ThriftyNova(Constants.IntakeConstants.kRollerMotorId); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private SmartMotorControllerConfig smcConfig = new SmartMotorControllerConfig(this) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withControlMode(ControlMode.OPEN_LOOP) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withTelemetry("IntakeMotor", TelemetryVerbosity.HIGH) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withGearing(new MechanismGearing(GearBox.fromReductionStages(1))) // Direct drive, adjust if geared | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withMotorInverted(false) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withIdleMode(MotorMode.COAST) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withStatorCurrentLimit(Amps.of(40)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private SmartMotorController smc = new NovaWrapper(rollerNova, DCMotor.getNeoVortex(1), smcConfig); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private final FlyWheelConfig intakeConfig = new FlyWheelConfig(smc) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withDiameter(Inches.of(4)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withMass(Pounds.of(0.5)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withUpperSoftLimit(RPM.of(6000)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withLowerSoftLimit(RPM.of(-6000)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withTelemetry("Intake", TelemetryVerbosity.HIGH); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private FlyWheel intake = new FlyWheel(intakeConfig); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // 5:1, 5:1, 60/18 reduction | ||||||||||||||||||||||||||||||||||||||||||||||||
| private SmartMotorControllerConfig intakePivotSmartMotorConfig = new SmartMotorControllerConfig(this) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withControlMode(ControlMode.CLOSED_LOOP) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withClosedLoopController(200, 0, 0, DegreesPerSecond.of(360), DegreesPerSecondPerSecond.of(360)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withFeedforward(new ArmFeedforward(0, 0, 0.1)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withTelemetry("IntakePivotMotor", TelemetryVerbosity.HIGH) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withGearing(new MechanismGearing(GearBox.fromReductionStages(5, 5, 60.0 / 18))) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withMotorInverted(true) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withIdleMode(MotorMode.BRAKE) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withStatorCurrentLimit(Amps.of(10)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withClosedLoopRampRate(Seconds.of(0.1)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private ThriftyNova pivotMotor = new ThriftyNova(Constants.IntakeConstants.kPivotMotorId); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private SmartMotorController intakePivotController = new NovaWrapper(pivotMotor, DCMotor.getNeoVortex(1), | ||||||||||||||||||||||||||||||||||||||||||||||||
| intakePivotSmartMotorConfig); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private final ArmConfig intakePivotConfig = new ArmConfig(intakePivotController) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withSoftLimits(Degrees.of(-95), Degrees.of(45)) // TODO: Find and set proper limits once setpoints and range is | ||||||||||||||||||||||||||||||||||||||||||||||||
| // known | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withHardLimit(Degrees.of(-100), Degrees.of(50)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withStartingPosition(Degrees.of(-90)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withLength(Feet.of(1)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withMass(Pounds.of(2)) // Reis says: 2 pounds, not a lot | ||||||||||||||||||||||||||||||||||||||||||||||||
| .withTelemetry("IntakePivot", TelemetryVerbosity.HIGH); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| private Arm intakePivot = new Arm(intakePivotConfig); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| public IntakeSubsystem() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Command to run the intake while held. | ||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||
| public Command intakeCommand() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return intake.set(INTAKE_SPEED).finallyDo(() -> smc.setDutyCycle(0)).withName("Intake.Run"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Command to eject while held. | ||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||
| public Command ejectCommand() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return intake.set(-INTAKE_SPEED).finallyDo(() -> smc.setDutyCycle(0)).withName("Intake.Eject"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| public Command setPivotAngle(Angle angle) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return intakePivot.setAngle(angle).withName("IntakePivot.SetAngle"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| public Command rezero() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return Commands.runOnce(() -> pivotMotor.setEncoderPosition(0), this).withName("IntakePivot.Rezero"); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+111
to
+112
|
||||||||||||||||||||||||||||||||||||||||||||||||
| public Command rezero() { | |
| return Commands.runOnce(() -> pivotMotor.setEncoderPosition(0), this).withName("IntakePivot.Rezero"); | |
| /** | |
| * Re-zero the intake pivot encoder. | |
| * <p> | |
| * This command should only be used when the robot is disabled and the intake | |
| * pivot is in its known mechanical zero position (for example, against a hard stop). | |
| * Attempting to re-zero while the robot is enabled is ignored and will report a warning. | |
| */ | |
| public Command rezero() { | |
| return Commands | |
| .runOnce( | |
| () -> { | |
| if (!edu.wpi.first.wpilibj.DriverStation.isDisabled()) { | |
| edu.wpi.first.wpilibj.DriverStation.reportWarning( | |
| "Attempted to rezero IntakePivot while robot is enabled; encoder position not changed.", | |
| false); | |
| return; | |
| } | |
| pivotMotor.setEncoderPosition(0); | |
| }, | |
| this) | |
| .withName("IntakePivot.Rezero"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing null for turret and hood parameters will cause NullPointerException if any Superstructure methods attempt to use these subsystems. Consider either instantiating these subsystems or updating Superstructure to handle null values gracefully.