Skip to content
This repository was archived by the owner on Jan 17, 2026. It is now read-only.

Commit 816a7d4

Browse files
committed
[elevator] Use PD gains from feedback analysis
Signed-off-by: Jade Turner <spacey-sooty@proton.me>
1 parent bb93a17 commit 816a7d4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/main/java/org/curtinfrc/frc2025/subsystems/elevator/ElevatorIOSim.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22

33
import edu.wpi.first.math.controller.ElevatorFeedforward;
44
import edu.wpi.first.math.controller.PIDController;
5+
import edu.wpi.first.math.numbers.N1;
6+
import edu.wpi.first.math.numbers.N2;
7+
import edu.wpi.first.math.system.LinearSystem;
58
import edu.wpi.first.math.system.plant.DCMotor;
9+
import edu.wpi.first.math.system.plant.LinearSystemId;
610
import edu.wpi.first.math.trajectory.TrapezoidProfile;
711
import edu.wpi.first.wpilibj.simulation.ElevatorSim;
12+
import org.curtinfrc.frc2025.util.FeedbackAnalysis;
13+
import org.curtinfrc.frc2025.util.FeedbackAnalysis.FeedbackGains;
814

915
public class ElevatorIOSim implements ElevatorIO {
1016
private static final double KV = 3.35;
1117
private static final double KA = 0.02;
1218
private static final double KG = 0.12;
1319

20+
private final LinearSystem<N2, N1, N2> elevatorSystem =
21+
LinearSystemId.identifyPositionSystem(KV, KA);
1422
private final ElevatorSim elevatorSim =
15-
new ElevatorSim(KV, KA, DCMotor.getKrakenX60Foc(2), 0, 0.62, true, 0);
23+
new ElevatorSim(elevatorSystem, DCMotor.getKrakenX60Foc(2), 0, 0.62, true, 0);
24+
private final FeedbackGains gains =
25+
FeedbackAnalysis.getPositionGains(elevatorSystem, 12, 0.005, 0.1, 0.02, 0.02);
1626
private double volts = 0;
1727

1828
private final TrapezoidProfile.Constraints constraints =
1929
new TrapezoidProfile.Constraints(3.53, 48.74);
2030
private final TrapezoidProfile profile = new TrapezoidProfile(constraints);
2131

22-
private final PIDController pid = new PIDController(0, 0, 0);
32+
private final PIDController pid = new PIDController(gains.kP(), 0, gains.kD());
2333
private final ElevatorFeedforward ff = new ElevatorFeedforward(0, KG, KV, KA);
2434

2535
@Override
@@ -39,12 +49,11 @@ public void setVoltage(double volts) {
3949

4050
@Override
4151
public void setPosition(double positionMetres) {
52+
var currentState =
53+
new TrapezoidProfile.State(
54+
elevatorSim.getPositionMeters(), elevatorSim.getVelocityMetersPerSecond());
4255
var setpoint =
43-
profile.calculate(
44-
0.02,
45-
new TrapezoidProfile.State(
46-
elevatorSim.getPositionMeters(), elevatorSim.getVelocityMetersPerSecond()),
47-
new TrapezoidProfile.State(positionMetres, 0));
56+
profile.calculate(0.02, currentState, new TrapezoidProfile.State(positionMetres, 0));
4857
setVoltage(
4958
pid.calculate(elevatorSim.getPositionMeters(), setpoint.position)
5059
+ ff.calculateWithVelocities(

0 commit comments

Comments
 (0)