Skip to content

Commit db78b96

Browse files
committed
Stop motor at hard limits in Pivot sim
When the Pivot mechanism hits its lower or upper hard limit the sim previously only snapped the encoder position, allowing the simulated motor to keep driving past the limit. This change stops the motor by zeroing the DC motor angular velocity and clearing the duty cycle in both the lower- and upper-limit branches, and adds comments explaining the intent to prevent further movement past hard limits.
1 parent 653f64b commit db78b96

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

yams/java/yams/mechanisms/positional/Pivot.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,19 @@ public void simIterate()
377377
m_smc.getSimSupplier().get().starveUpdateSim();
378378
if (m_config.getLowerHardLimit().isPresent() && m_dcmotorSim.get().getAngularVelocityRadPerSec() < 0 &&
379379
m_smc.getMechanismPosition().lt(m_config.getLowerHardLimit().get()))
380+
// Stop the motor from moving further in the direction of the hard limit
381+
m_dcmotorSim.get().setAngularVelocity(0);
382+
m_smc.setDutyCycle(0);
380383
{
381384
m_smc.setEncoderPosition(m_config.getLowerHardLimit().get());
382385
}
383386
if (m_config.getUpperHardLimit().isPresent() && m_dcmotorSim.get().getAngularVelocityRadPerSec() > 0 &&
384387
m_smc.getMechanismPosition().gt(m_config.getUpperHardLimit().get()))
385388
{
386389
m_smc.setEncoderPosition(m_config.getUpperHardLimit().get());
390+
// Stop the motor from moving further in the direction of the hard limit
391+
m_dcmotorSim.get().setAngularVelocity(0);
392+
m_smc.setDutyCycle(0);
387393
}
388394
RoboRioSim.setVInVoltage(BatterySim.calculateDefaultBatteryLoadedVoltage(m_dcmotorSim.get()
389395
.getCurrentDrawAmps()));

0 commit comments

Comments
 (0)