@@ -24,14 +24,13 @@ public class ElevatorIOSim implements ElevatorIO {
2424 ElevatorConstants .ELEVATOR_MIN_HEIGHT .in (Meter ),
2525 ElevatorConstants .ELEVATOR_MAX_HEIGHT .in (Meter ),
2626 true ,
27- 0.00 );
27+ ElevatorConstants . ELEVATOR_MIN_HEIGHT . in ( Meter ) );
2828
29- // TODO(vdikov): Looks like IOReal and IOSim could share the motor instance.
3029 private TalonFX motor ;
3130 private TalonFXSimState motorSim ;
3231
3332 // Used for actually moving the motor to a given position with PID applied to a voltage input.
34- private final PositionVoltage positionControl = new PositionVoltage (0 );
33+ private final PositionVoltage positionControl = new PositionVoltage (Rotations . of ( 0 ) );
3534
3635 public ElevatorIOSim () {}
3736
@@ -55,25 +54,28 @@ public void updateState(ElevatorIOInputs inputs) {
5554
5655 private void updateSim () {
5756 motorSim .setSupplyVoltage (Volts .of (12 ));
57+ double motorInverted = -1.0 ; // -1 for inverted, 1 for forward motor.
5858
5959 // Apply the voltage to the sim elevator that we apply to the sim motor.
60- elevatorSim .setInputVoltage (motorSim .getMotorVoltage ());
60+ // Negating the sim motor value since it is set to use negative value when pushing
61+ // the cartrage UP.
62+ elevatorSim .setInputVoltage (motorInverted * motorSim .getMotorVoltage ());
63+ elevatorSim .update (0.02 ); // Same update cycle as an actual robot, 20 ms.
6164
6265 // Logs to "Real Outputs" NT
6366 Logger .recordOutput ("Simulated Elevator/motorSim/Voltage" , motorSim .getMotorVoltage ());
67+ Logger .recordOutput ("Simulated Elevator/elevatorSim/position (meters)" , elevatorSim .getPositionMeters ());
6468 Logger .recordOutput ("Simulated Elevator/elevatorSim/hitsUpperLimit" , elevatorSim .hasHitUpperLimit ());
6569 Logger .recordOutput ("Simulated Elevator/elevatorSim/hitsLowerLimit" , elevatorSim .hasHitLowerLimit ());
6670
67- elevatorSim .update (0.02 ); // Same update cycle as an actual robot, 20 ms.
68-
69- motorSim .setRawRotorPosition (getMotorRotations (elevatorSim .getPositionMeters ()));
71+ motorSim .setRawRotorPosition (motorInverted * getMotorRotations (elevatorSim .getPositionMeters ()));
7072
7173 // angular velocity = linear velocity / radius, taken also from 5414
72- motorSim .setRotorVelocity (
73- ((elevatorSim .getVelocityMetersPerSecond () / ElevatorConstants .ELEVATOR_SPOOL_RADIUS .in (Meters ))
74- // radians/sec to rotations/sec
75- / (2.0 * Math .PI ))
76- * ElevatorConstants .MOTOR_TO_ELEVATOR_GEARING );
74+ motorSim .setRotorVelocity (motorInverted
75+ * ((elevatorSim .getVelocityMetersPerSecond () / ElevatorConstants .ELEVATOR_SPOOL_RADIUS .in (Meters ))
76+ // radians/sec to rotations/sec
77+ / (2.0 * Math .PI ))
78+ * ElevatorConstants .MOTOR_TO_ELEVATOR_GEARING );
7779 }
7880
7981 @ Override
0 commit comments