-
Notifications
You must be signed in to change notification settings - Fork 0
Climb #6
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
base: main
Are you sure you want to change the base?
Climb #6
Changes from all commits
405aefc
daa4f12
d2c2d33
73518c1
ac78a53
997ff4d
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,49 @@ | ||
| package frc.robot.subsystems.climber; | ||
|
|
||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
| import com.revrobotics.spark.SparkMax; | ||
| import com.revrobotics.spark.SparkLowLevel.MotorType; | ||
| import com.revrobotics.RelativeEncoder; | ||
| import com.revrobotics.spark.SparkClosedLoopController; | ||
| import com.revrobotics.spark.config.SparkMaxConfig; | ||
| import com.revrobotics.spark.SparkBase.PersistMode; | ||
| import com.revrobotics.spark.SparkBase.ResetMode; | ||
| import com.revrobotics.spark.config.SparkBaseConfig.IdleMode; | ||
| import com.revrobotics.spark.SparkBase.ControlType; | ||
|
|
||
| public class Climber extends SubsystemBase { | ||
| private static final double DEPLOY_POSITION = 3.00; // Change this value as needed (Unit is rotations) | ||
| private static final double RETRACT_POSITION = 0.00; // Change this value as needed (Unit is rotations) | ||
| private final SparkMax climberMotor; | ||
| private final RelativeEncoder climberEncoder; | ||
| private final SparkClosedLoopController climberController; | ||
|
|
||
| public Climber(int ClimberMotorID) { | ||
| //Motor initialization | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments are only for when the code can't explain itself; this code can explain itself. Additionally, there should be a space after the |
||
| this.climberMotor = new SparkMax(ClimberMotorID, MotorType.kBrushless); | ||
| //Encoder initialization | ||
| climberEncoder = climberMotor.getEncoder(); | ||
| climberEncoder.setPosition(0.0); | ||
|
|
||
| //Closed loop controller initialization | ||
| climberController = climberMotor.getClosedLoopController(); | ||
|
|
||
| SparkMaxConfig config = new SparkMaxConfig(); | ||
| config.smartCurrentLimit(20); //20 amps | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current limit should go in constants; default should be ~40 amps. |
||
| config.idleMode(IdleMode.kBrake); | ||
| climberMotor.configure(config, ResetMode.kResetSafeParameters, PersistMode.kNoPersistParameters); // Note to set PID in this line | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch to |
||
| } | ||
|
|
||
| public void gotoPOS(double position) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| climberController.setReference(position, ControlType.kPosition); | ||
| } | ||
|
|
||
|
|
||
| public void deploy() { | ||
| gotoPOS(DEPLOY_POSITION); | ||
| } | ||
|
|
||
| public void retract() { | ||
| gotoPOS(RETRACT_POSITION); | ||
| } | ||
| } | ||
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.
These are constants, so they should go in
Constants.java.