77import com .ctre .phoenix6 .hardware .TalonFX ;
88import com .ctre .phoenix6 .signals .InvertedValue ;
99import com .ctre .phoenix6 .signals .NeutralModeValue ;
10+ import com .revrobotics .RelativeEncoder ;
11+ import com .revrobotics .spark .SparkBase .PersistMode ;
12+ import com .revrobotics .spark .SparkBase .ResetMode ;
1013import com .revrobotics .spark .SparkMax ;
1114import com .revrobotics .spark .SparkLowLevel .MotorType ;
15+ import com .revrobotics .spark .config .SparkMaxConfig ;
1216
1317import edu .wpi .first .math .controller .ArmFeedforward ;
1418import edu .wpi .first .math .controller .ProfiledPIDController ;
@@ -24,7 +28,10 @@ public class Climber extends SubsystemBase{
2428 public static class Settings {
2529 static final int kClimberPivotId = 27 ; //TODO: change this to sparkmax ID
2630
27- static final InvertedValue kClimberPivotInverted = InvertedValue .Clockwise_Positive ;
31+ // static final InvertedValue kClimberPivotInverted = InvertedValue.Clockwise_Positive;
32+ static final boolean kClimberPivotInverted = false ;
33+
34+ static final int kStallCurrentLimit = 80 ; // in amps
2835
2936 static final double kG = 0.1 ; // V
3037 static final double kS = 0.0 ; // V / rad
@@ -38,8 +45,8 @@ public static class Settings {
3845 public static final Rotation2d kMaxVelocity = Rotation2d .fromDegrees (200 ); //120
3946 public static final Rotation2d kMaxAcceleration = Rotation2d .fromDegrees (300 );
4047
41- public static final Rotation2d kMaxPos = Rotation2d .fromRotations (0.8 );
42- public static final Rotation2d kMinPos = Rotation2d .fromRotations (0.0 );
48+ public static final Rotation2d kMaxPos = Rotation2d .fromRotations (0.8 ); //TODO: change this
49+ public static final Rotation2d kMinPos = Rotation2d .fromRotations (0.0 ); //TODO: change this
4350
4451 public static final Rotation2d kAFFAngleOffset = Rotation2d .fromDegrees (0 );
4552
@@ -48,9 +55,10 @@ public static class Settings {
4855 }
4956
5057 public enum State {
51- kDeploy (Rotation2d .fromRotations (150.91650390625 )),
52- kRetract (Rotation2d .fromRotations (80.5693359375 )),
53- kStow (Settings .kMinPos );
58+ //TODO: redo these states based on the climber encoder position
59+ kDeploy (Rotation2d .fromRotations (150.91650390625 )), //TODO
60+ kRetract (Rotation2d .fromRotations (80.5693359375 )), //TODO
61+ kStow (Settings .kMinPos ); //TODO
5462
5563 State (Rotation2d pos ) {
5664 this .pos = pos ;
@@ -66,12 +74,23 @@ public enum State {
6674 private Constraints mConstraints ;
6775 private final ArmFeedforward mAFFController ;
6876
69- private SparkMax mClimberPivotNeo ;
77+ private SparkMax mClimberPivotMotor ;
78+ private SparkMaxConfig mClimberPivotMotorConfig ;
79+ private RelativeEncoder mClimberPivotMotorEncoder ;
80+
7081
7182 public static State kLastState ;
7283
7384 public Climber () {
74- mClimberPivotNeo = new SparkMax (Settings .kClimberPivotId , MotorType .kBrushless );
85+ mClimberPivotMotor = new SparkMax (Settings .kClimberPivotId , MotorType .kBrushless );
86+
87+ mClimberPivotMotorConfig = new SparkMaxConfig ();
88+ mClimberPivotMotorConfig .inverted (Settings .kClimberPivotInverted );
89+ mClimberPivotMotorConfig .smartCurrentLimit (Settings .kStallCurrentLimit );
90+ mClimberPivotMotor .configure (mClimberPivotMotorConfig , ResetMode .kResetSafeParameters , PersistMode .kPersistParameters );
91+
92+ mClimberPivotMotorEncoder = mClimberPivotMotor .getEncoder ();
93+
7594
7695 // ClimberPivot = new TalonFX(Settings.kClimberPivotId);
7796
@@ -120,20 +139,18 @@ public void setTargetPos(Rotation2d pos) {
120139 }
121140
122141 public Rotation2d getPos () {
123- // var pos = ClimberPivot.getPosition().getValueAsDouble();
124-
125- return Rotation2d .k180deg ;
142+ return Rotation2d .fromRotations (mClimberPivotMotorEncoder .getPosition ());
126143 }
127144
128145 public Rotation2d getAngularVelocity () {
129146 // return Rotation2d.fromRotations(ClimberPivot.getVelocity().getValueAsDouble());
130- return null ;
147+ return Rotation2d . fromRotations ( mClimberPivotMotorEncoder . getVelocity ()); //TODO: i dont know what the unit conversions are
131148 }
132149
133150 public static class DefaultCommand extends Command {
134151
135152 public DefaultCommand () {
136- addRequirements (RushinatorPivot .getInstance ());
153+ addRequirements (Climber .getInstance ());
137154 }
138155
139156 @ Override
@@ -156,6 +173,8 @@ public void periodic() {
156173 speed += mAFFController .calculate (getPos ().getRotations (), mPPIDController .getSetpoint ().velocity );
157174
158175 SmartDashboard .putNumber ("mPPIDC + mFFC Output" , speed );
176+
177+ mClimberPivotMotor .setVoltage (speed );
159178
160179 // ClimberPivot.setVoltage(speed);
161180 }
0 commit comments