Skip to content

Commit fc77d7e

Browse files
Added setInput method to use simState only for TalonFX in simulatePeriodic methods (#33)
1 parent c92ac33 commit fc77d7e

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

public/templates/arm-subsystem.java.hbs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,15 @@ public class {{subsystemName}} extends SubsystemBase {
171171
// Set input voltage from motor controller to simulation
172172
// Note: This may need to be talonfx.getSimState().getMotorVoltage() as the input.
173173
//armSim.setInput(dcMotor.getVoltage(dcMotor.getTorque(armSim.getCurrentDrawAmps()), armSim.getVelocityRadPerSec()));
174+
// armSim.setInput(getVoltage());
175+
// Sets input voltage based on whether it is talon fx or not
176+
{{#if (or (eq motorControllerType 'TalonFX') (eq motorControllerType 'TalonFXS'))}}
177+
// Use motor voltage for TalonFX simulation input
178+
armSim.setInput(talonfx.getSimState().getMotorVoltage());
179+
{{else}}
180+
// Use getVoltage() for other controllers
174181
armSim.setInput(getVoltage());
182+
{{/if}}
175183

176184
// Update simulation by 20ms
177185
armSim.update(0.020);

public/templates/elevator-subsystem.java.hbs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,15 @@ public class {{subsystemName}} extends SubsystemBase {
170170
// Set input voltage from motor controller to simulation
171171
// Note: This may need to be talonfx.getSimState().getMotorVoltage() as the input
172172
//elevatorSim.setInput(dcMotor.getVoltage(dcMotor.getTorque(elevatorSim.getCurrentDrawAmps()), elevatorSim.getVelocityMetersPerSecond() * positionToRotations * 2 * Math.PI));
173-
elevatorSim.setInput(getVoltage());
173+
// elevatorSim.setInput(getVoltage());
174+
175+
{{#if (or (eq motorControllerType 'TalonFX') (eq motorControllerType 'TalonFXS'))}}
176+
// Use motor voltage for TalonFX simulation input
177+
elevatorSim.setInput(motor.getSimState().getMotorVoltage());
178+
{{else}}
179+
// Use getVoltage() for other controllers
180+
elevatorSim.setInput(getVoltage());
181+
{{/if}}
174182

175183
// Update simulation by 20ms
176184
elevatorSim.update(0.020);

public/templates/pivot-subsystem.java.hbs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,15 @@ public void simulationPeriodic() {
178178
// Set input voltage from motor controller to simulation
179179
// Note: This may need to be talonfx.getSimState().getMotorVoltage() as the input
180180
//pivotSim.setInput(dcMotor.getVoltage(dcMotor.getTorque(pivotSim.getCurrentDrawAmps()), pivotSim.getVelocityRadPerSec()));
181-
pivotSim.setInput(getVoltage());
181+
// pivotSim.setInput(getVoltage());
182+
// Set input voltage from motor controller to simulation
183+
{{#if (or (eq motorControllerType 'TalonFX') (eq motorControllerType 'TalonFXS'))}}
184+
// Use motor voltage for TalonFX simulation input
185+
pivotSim.setInput(motor.getSimState().getMotorVoltage());
186+
{{else}}
187+
// Use getVoltage() for other controllers
188+
pivotSim.setInput(getVoltage());
189+
{{/if}}
182190

183191
// Update simulation by 20ms
184192
pivotSim.update(0.020);

0 commit comments

Comments
 (0)