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

Commit 2d86508

Browse files
committed
high hz simulation, gains should be good
Signed-off-by: Jade Turner <spacey-sooty@proton.me>
1 parent fa2f8bc commit 2d86508

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public ElevatorIOComp() {
5050
slot0.GravityType = GravityTypeValue.Elevator_Static;
5151
// we lie about units cause of how the dimensional analysis works out
5252
slot0.kG = 0.09;
53-
slot0.kP = rotationsToMetres(19.11);
54-
slot0.kD = rotationsToMetres(0.05);
53+
slot0.kP = rotationsToMetres(318.70);
54+
slot0.kD = rotationsToMetres(1.33);
5555
slot0.kV = rotationsToMetres(5.29);
5656
slot0.kV = rotationsToMetres(0.01);
5757

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
package org.curtinfrc.frc2025.subsystems.elevator;
22

33
import edu.wpi.first.math.system.plant.DCMotor;
4+
import edu.wpi.first.wpilibj.Notifier;
5+
import edu.wpi.first.wpilibj.RobotController;
46
import edu.wpi.first.wpilibj.simulation.ElevatorSim;
57

68
public class ElevatorIOSim extends ElevatorIOComp {
79
private final ElevatorSim elevatorSim =
8-
// new ElevatorSim(3.35, 0.02, DCMotor.getKrakenX60Foc(2), 0, 0.6, true, 0.01);
910
new ElevatorSim(5.29, 0.01, DCMotor.getKrakenX60Foc(2), -1, 1, true, 0, 0.001, 0.01);
1011

11-
@Override
12-
public void updateInputs(ElevatorIOInputs inputs) {
13-
super.updateInputs(inputs);
12+
private double lastSimTime;
13+
private final Notifier notifier;
14+
15+
public ElevatorIOSim() {
16+
super();
17+
lastSimTime = RobotController.getFPGATime();
18+
19+
notifier =
20+
new Notifier(
21+
() -> {
22+
final double currentTime = RobotController.getFPGATime();
23+
double deltaTime = currentTime - lastSimTime;
24+
lastSimTime = currentTime;
25+
26+
updateSimState(deltaTime);
27+
});
28+
notifier.startPeriodic(0.001);
29+
}
30+
31+
private void updateSimState(double deltaTime) {
1432
var simState = motor.getSimState();
1533
elevatorSim.setInput(simState.getMotorVoltage());
1634
elevatorSim.update(0.02);
@@ -19,4 +37,13 @@ public void updateInputs(ElevatorIOInputs inputs) {
1937
var rotorVel = metresToRotations(elevatorSim.getVelocityMetersPerSecond());
2038
simState.setRotorVelocity(rotorVel);
2139
}
40+
41+
@Override
42+
public void updateInputs(ElevatorIOInputs inputs) {
43+
super.updateInputs(inputs);
44+
final double currentTime = RobotController.getFPGATime();
45+
double deltaTime = currentTime - lastSimTime;
46+
lastSimTime = currentTime;
47+
updateSimState(deltaTime);
48+
}
2249
}

0 commit comments

Comments
 (0)