Skip to content

Commit 90c3ff0

Browse files
committed
updated Climber to utilize BangBang and FF Controller
1 parent 1618b3e commit 90c3ff0

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

src/main/java/frc/robot/climber/Climber.java

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.revrobotics.spark.config.SparkMaxConfig;
1616

1717
import edu.wpi.first.math.controller.ArmFeedforward;
18+
import edu.wpi.first.math.controller.BangBangController;
1819
import edu.wpi.first.math.controller.ProfiledPIDController;
1920
import edu.wpi.first.math.geometry.Rotation2d;
2021
import edu.wpi.first.math.trajectory.TrapezoidProfile;
@@ -35,7 +36,7 @@ public static class Settings {
3536

3637
static final double kG = 0.1; // V
3738
static final double kS = 0.0; // V / rad
38-
static final double kV = 1.0; // V * sec / rad
39+
static final double kV = 0.0; // V * sec / rad
3940
static final double kA = 0.0; // V * sec^2 / rad
4041

4142
static final double kP = 0.01;
@@ -70,8 +71,9 @@ public enum State {
7071
public static Climber mInstance;
7172

7273
// private TalonFX ClimberPivot;
73-
private final ProfiledPIDController mPPIDController;
74+
// private final ProfiledPIDController mPPIDController;
7475
private Constraints mConstraints;
76+
private final BangBangController mBBController;
7577
private final ArmFeedforward mAFFController;
7678

7779
private SparkMax mClimberPivotMotor;
@@ -90,6 +92,15 @@ public Climber() {
9092
mClimberPivotMotor.configure(mClimberPivotMotorConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
9193

9294
mClimberPivotMotorEncoder = mClimberPivotMotor.getEncoder();
95+
96+
mAFFController = new ArmFeedforward(Settings.kS, Settings.kG, Settings.kV, Settings.kA);
97+
98+
mBBController = new BangBangController(0.01);
99+
100+
if (kLastState == null) {
101+
kLastState = State.kStow;
102+
}
103+
// mPPIDController.setGoal(kLastState.pos.getRotations());
93104

94105

95106
// ClimberPivot = new TalonFX(Settings.kClimberPivotId);
@@ -109,22 +120,16 @@ public Climber() {
109120

110121
// ElbowPivotConfigurator.apply(ElbowPivotConfigs);
111122

112-
mPPIDController = new ProfiledPIDController(Settings.kP, Settings.kI, Settings.kD, new TrapezoidProfile.Constraints(
113-
Settings.kMaxVelocity.getRadians(),
114-
Settings.kMaxAcceleration.getRadians()
115-
));
116-
mPPIDController.setTolerance(0.01);
117-
mAFFController = new ArmFeedforward(Settings.kS, Settings.kG, Settings.kV, Settings.kA);
123+
// mPPIDController = new ProfiledPIDController(Settings.kP, Settings.kI, Settings.kD, new TrapezoidProfile.Constraints(
124+
// Settings.kMaxVelocity.getRadians(),
125+
// Settings.kMaxAcceleration.getRadians()
126+
// ));
127+
// mPPIDController.setTolerance(0.01);
128+
118129

119130
// ClimberPivot.setPosition(0.0);
120131

121132
// ClimberPivot.getConfigurator().apply(new CurrentLimitsConfigs().withSupplyCurrentLimit(Settings.kCurrentLimit));
122-
123-
if (kLastState == null) {
124-
kLastState = State.kStow;
125-
}
126-
mPPIDController.setGoal(kLastState.pos.getRotations());
127-
128133
}
129134

130135
public static Climber getInstance() {
@@ -135,7 +140,8 @@ public static Climber getInstance() {
135140
}
136141

137142
public void setTargetPos(Rotation2d pos) {
138-
mPPIDController.setGoal(pos.getRotations());
143+
// mPPIDController.setGoal(pos.getRotations());
144+
mBBController.setSetpoint(pos.getRotations());
139145
}
140146

141147
public Rotation2d getPos() {
@@ -163,14 +169,17 @@ public void execute() {
163169
@Override
164170
public void periodic() {
165171
SmartDashboard.putNumber("Climber Pivot Angle (Rotations)", getPos().getRotations());
166-
SmartDashboard.putNumber("Climber Pivot Angular Velocity (Rotations / sec)", getAngularVelocity().getRotations());
172+
SmartDashboard.putNumber("Climber Pivot Angular Velocity (Rotations / sec)", getAngularVelocity().getRotations() * 60.0);
173+
174+
// SmartDashboard.putNumber("Climber Target Pos", mPPIDController.getSetpoint().position);
175+
// SmartDashboard.putNumber("Target Vel", mPPIDController.getSetpoint().velocity);
167176

168-
SmartDashboard.putNumber("Climber Target Pos", mPPIDController.getSetpoint().position);
169-
SmartDashboard.putNumber("Target Vel", mPPIDController.getSetpoint().velocity);
177+
SmartDashboard.putNumber("Climber Target Pos", mBBController.getSetpoint());
178+
SmartDashboard.putNumber("Target Vel (RPS)", mBBController.getSetpoint() / 60.0);
170179

171180
// Method to run pivots
172-
double speed = mPPIDController.calculate(getPos().getRotations());
173-
speed += mAFFController.calculate(getPos().getRotations(), mPPIDController.getSetpoint().velocity);
181+
double speed = mBBController.calculate(getPos().getRotations());
182+
speed += mAFFController.calculate(getPos().getRotations(), mBBController.getSetpoint() / 60.0);
174183

175184
SmartDashboard.putNumber("mPPIDC + mFFC Output", speed);
176185

0 commit comments

Comments
 (0)