-
Notifications
You must be signed in to change notification settings - Fork 0
First pass at climber subsystem #32
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
Open
ronansoergel9
wants to merge
3
commits into
main
Choose a base branch
from
Ronan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−9
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
src/main/java/frc/robot/subsystems/climber/ClimberIO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package frc.robot.subsystems.climber; | ||
|
|
||
| import org.littletonrobotics.junction.AutoLog; | ||
|
|
||
| import com.ctre.phoenix6.BaseStatusSignal; | ||
| import com.ctre.phoenix6.CANBus; | ||
| import com.ctre.phoenix6.StatusSignal; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.controls.PositionVoltage; | ||
| import com.ctre.phoenix6.controls.VelocityVoltage; | ||
| import com.ctre.phoenix6.controls.VoltageOut; | ||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import com.ctre.phoenix6.signals.InvertedValue; | ||
| import com.ctre.phoenix6.signals.NeutralModeValue; | ||
| import com.ctre.phoenix6.signals.GravityTypeValue; | ||
| import org.littletonrobotics.junction.AutoLogOutput; | ||
|
|
||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
| import edu.wpi.first.units.measure.Angle; | ||
| import edu.wpi.first.units.measure.Current; | ||
| import edu.wpi.first.units.measure.Temperature; | ||
| import edu.wpi.first.units.measure.Voltage; | ||
| import edu.wpi.first.units.measure.AngularVelocity; | ||
| import edu.wpi.first.units.measure.Frequency; | ||
| import frc.robot.subsystems.shooter.HoodIO; | ||
|
|
||
| public class ClimberIO { | ||
|
|
||
| @AutoLog | ||
| public static class ClimberIOInputs { | ||
| public Rotation2d motorPositionRotations = new Rotation2d(); | ||
| public double motorVelocityMetersPerSec = 0.0; | ||
| public double motorStatorCurrentAmps = 0.0; | ||
| public double motorSupplyCurrentAmps = 0.0; | ||
| public double motorVoltage = 0.0; | ||
| public double motorTempC = 0.0; | ||
| } | ||
|
|
||
| protected final TalonFX climberMotor; | ||
|
|
||
| private final StatusSignal<Angle> motorPositionRotations; | ||
| private final StatusSignal<AngularVelocity> angularVelocityRotsPerSec; | ||
| private final StatusSignal<Current> statorCurrentAmps; | ||
| private final StatusSignal<Current> supplyCurrentAmps; | ||
| private final StatusSignal<Voltage> motorVoltage; | ||
| private final StatusSignal<Temperature> motorTemp; | ||
|
|
||
| private VoltageOut voltageOut = new VoltageOut(0.0) .withEnableFOC(true); | ||
| private PositionVoltage positionVoltage = new PositionVoltage(0.0) .withEnableFOC(true); | ||
| private VelocityVoltage velocityVoltage = new VelocityVoltage(0.0) .withEnableFOC(true); | ||
|
|
||
| private Rotation2d climberSetpoint = Rotation2d.kZero; | ||
|
|
||
|
|
||
| public ClimberIO(CANBus canBus) { | ||
| //todo: set correct motor ID | ||
| climberMotor = new TalonFX(30, canBus); | ||
| climberMotor.getConfigurator().apply(ClimberIO.getClimberConfiguration()); | ||
|
|
||
| angularVelocityRotsPerSec = climberMotor.getVelocity(); | ||
| supplyCurrentAmps = climberMotor.getSupplyCurrent(); | ||
| motorVoltage = climberMotor.getMotorVoltage(); | ||
| statorCurrentAmps = climberMotor.getStatorCurrent(); | ||
| motorTemp = climberMotor.getDeviceTemp(); | ||
| motorPositionRotations = climberMotor.getPosition(); | ||
|
|
||
| BaseStatusSignal.setUpdateFrequencyForAll( | ||
| 50.0, | ||
| angularVelocityRotsPerSec, | ||
| supplyCurrentAmps, | ||
| motorVoltage, | ||
| statorCurrentAmps, | ||
| motorTemp, | ||
| motorPositionRotations); | ||
| climberMotor.optimizeBusUtilization(); | ||
| } | ||
|
|
||
| public static TalonFXConfiguration getClimberConfiguration() { | ||
| TalonFXConfiguration config = new TalonFXConfiguration(); | ||
|
|
||
| config.MotorOutput.NeutralMode = NeutralModeValue.Brake; | ||
|
|
||
| config.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; | ||
|
|
||
| //todo: find and make climber gear ratio variable | ||
| config.Feedback.SensorToMechanismRatio = ClimberSubsystem.GEAR_RATIO; | ||
|
|
||
| //todo: tune | ||
| config.Slot0.kS = 0.0; | ||
| config.Slot0.kG = 0.0; | ||
| config.Slot0.kV = 0.0; | ||
| config.Slot0.kP = 0.0; | ||
| config.Slot0.kD = 0.0; | ||
|
|
||
| //todo: find actual current limits | ||
| config.CurrentLimits.StatorCurrentLimit = 50.00; | ||
| config.CurrentLimits.StatorCurrentLimitEnable = true; | ||
| config.CurrentLimits.SupplyCurrentLimit = 40.00; | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| public void setClimberPosition(Rotation2d climberPosition) { | ||
| climberSetpoint = climberPosition; | ||
| climberMotor.setControl(positionVoltage.withPosition(climberPosition.getRotations())); | ||
| } | ||
|
|
||
| public void setClimberVoltage(double climberVoltage) { | ||
| climberMotor.setControl(voltageOut.withOutput(climberVoltage)); | ||
| } | ||
|
|
||
| public void setClimberVelocity(double climberVelocity) { | ||
| climberMotor.setControl(velocityVoltage.withVelocity(climberVelocity)); | ||
| } | ||
|
|
||
| public void updateInputs(ClimberIOInputs inputs) { | ||
| BaseStatusSignal.refreshAll( | ||
| motorPositionRotations, | ||
| angularVelocityRotsPerSec, | ||
| statorCurrentAmps, | ||
| supplyCurrentAmps, | ||
| motorVoltage, | ||
| motorTemp); | ||
|
|
||
| inputs.motorPositionRotations = | ||
| Rotation2d.fromRotations(motorPositionRotations.getValueAsDouble()); | ||
| inputs.motorVoltage = motorVoltage.getValueAsDouble(); | ||
| inputs.motorTempC = motorTemp.getValueAsDouble(); | ||
| inputs.motorSupplyCurrentAmps = supplyCurrentAmps.getValueAsDouble(); | ||
| inputs.motorStatorCurrentAmps = statorCurrentAmps.getValueAsDouble(); | ||
| inputs.motorVelocityMetersPerSec = angularVelocityRotsPerSec.getValueAsDouble(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
52 changes: 45 additions & 7 deletions
52
src/main/java/frc/robot/subsystems/climber/ClimberSubsystem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,55 @@ | ||
| // 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.climber; | ||
|
|
||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.signals.InvertedValue; | ||
| import com.ctre.phoenix6.signals.NeutralModeValue; | ||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import edu.wpi.first.wpilibj2.command.Commands; | ||
| import frc.robot.components.rollers.RollerIO; | ||
| import frc.robot.components.rollers.RollerIOInputsAutoLogged; | ||
| import org.littletonrobotics.junction.Logger; | ||
|
|
||
|
|
||
|
|
||
| public class ClimberSubsystem extends SubsystemBase { | ||
| /** Creates a new ClimberSubsystem. */ | ||
| public ClimberSubsystem() {} | ||
| //todo: find actual constants | ||
| public static double GEAR_RATIO = (45.0 / 1.0); | ||
| public static Rotation2d MAX_ANGLE = Rotation2d.fromDegrees(180); | ||
| public static Rotation2d MIN_ANGLE = Rotation2d.fromDegrees(0); | ||
| public static double MAX_ACCELERATION = 10.0; | ||
| public static double MAX_VELOCITY = 2.0; | ||
|
|
||
| ClimberIO climberIO; | ||
| ClimberIOInputsAutoLogged climberInputs = new ClimberIOInputsAutoLogged(); | ||
|
|
||
| @Override | ||
| public void periodic() { | ||
| // This method will be called once per scheduler run | ||
| climberIO.updateInputs(climberInputs); | ||
| Logger.processInputs("Climber", climberInputs); | ||
| } | ||
|
|
||
| //member variables here? | ||
|
|
||
| public ClimberSubsystem(ClimberIO climberIO) { | ||
| this.climberIO = climberIO; | ||
| } | ||
|
|
||
| public Command climbUp() { | ||
| return this.run( | ||
| () -> { | ||
| climberIO.setClimberPosition(MAX_ANGLE); | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| public Command climbDown() { | ||
| return this.run( | ||
| () -> { | ||
| climberIO.setClimberPosition(MIN_ANGLE); | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
remember to create the climbersubsystem in Robot.java (L263)