2021-08-12 02:04:14 -04:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
2025-11-07 19:55:43 -05:00
|
|
|
package org.wpilib.simulation;
|
2021-08-12 02:04:14 -04:00
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
|
2025-11-07 19:55:43 -05:00
|
|
|
import org.wpilib.hardware.hal.HAL;
|
|
|
|
|
import org.wpilib.hardware.pneumatic.CompressorConfigType;
|
|
|
|
|
import org.wpilib.hardware.pneumatic.DoubleSolenoid;
|
|
|
|
|
import org.wpilib.hardware.pneumatic.PneumaticsControlModule;
|
|
|
|
|
import org.wpilib.hardware.pneumatic.PneumaticsModuleType;
|
|
|
|
|
import org.wpilib.simulation.testutils.BooleanCallback;
|
|
|
|
|
import org.wpilib.simulation.testutils.DoubleCallback;
|
2021-08-12 02:04:14 -04:00
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
class CTREPCMSimTest {
|
|
|
|
|
@Test
|
|
|
|
|
void testInitialization() {
|
|
|
|
|
HAL.initialize(500, 0);
|
|
|
|
|
|
|
|
|
|
CTREPCMSim sim = new CTREPCMSim(0);
|
|
|
|
|
sim.resetData();
|
|
|
|
|
assertFalse(sim.getInitialized());
|
|
|
|
|
|
|
|
|
|
BooleanCallback callback = new BooleanCallback();
|
|
|
|
|
|
|
|
|
|
try (CallbackStore cb = sim.registerInitializedCallback(callback, false);
|
|
|
|
|
PneumaticsControlModule pcm = new PneumaticsControlModule(0)) {
|
|
|
|
|
assertTrue(sim.getInitialized());
|
|
|
|
|
}
|
2021-09-16 18:50:27 -07:00
|
|
|
assertFalse(sim.getInitialized());
|
2021-08-12 02:04:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void solenoidOutputTest() {
|
|
|
|
|
HAL.initialize(500, 0);
|
|
|
|
|
|
|
|
|
|
try (PneumaticsControlModule pcm = new PneumaticsControlModule(0);
|
2021-09-16 18:50:27 -07:00
|
|
|
DoubleSolenoid doubleSolenoid = new DoubleSolenoid(0, PneumaticsModuleType.CTREPCM, 3, 4)) {
|
|
|
|
|
CTREPCMSim sim = new CTREPCMSim(0);
|
2021-08-12 02:04:14 -04:00
|
|
|
sim.resetData();
|
|
|
|
|
|
|
|
|
|
BooleanCallback callback3 = new BooleanCallback();
|
|
|
|
|
BooleanCallback callback4 = new BooleanCallback();
|
|
|
|
|
|
|
|
|
|
try (CallbackStore cb3 = sim.registerSolenoidOutputCallback(3, callback3, false);
|
|
|
|
|
CallbackStore cb4 = sim.registerSolenoidOutputCallback(4, callback4, false)) {
|
|
|
|
|
// Reverse
|
|
|
|
|
callback3.reset();
|
|
|
|
|
callback4.reset();
|
|
|
|
|
doubleSolenoid.set(DoubleSolenoid.Value.kReverse);
|
|
|
|
|
assertFalse(callback3.wasTriggered());
|
|
|
|
|
assertNull(callback3.getSetValue());
|
|
|
|
|
assertTrue(callback4.wasTriggered());
|
|
|
|
|
assertTrue(callback4.getSetValue());
|
|
|
|
|
assertFalse(sim.getSolenoidOutput(3));
|
|
|
|
|
assertTrue(sim.getSolenoidOutput(4));
|
|
|
|
|
assertEquals(0x10, pcm.getSolenoids());
|
|
|
|
|
|
|
|
|
|
// Forward
|
|
|
|
|
callback3.reset();
|
|
|
|
|
callback4.reset();
|
|
|
|
|
doubleSolenoid.set(DoubleSolenoid.Value.kForward);
|
|
|
|
|
assertTrue(callback3.wasTriggered());
|
|
|
|
|
assertTrue(callback3.getSetValue());
|
|
|
|
|
assertTrue(callback4.wasTriggered());
|
|
|
|
|
assertFalse(callback4.getSetValue());
|
|
|
|
|
assertTrue(sim.getSolenoidOutput(3));
|
|
|
|
|
assertFalse(sim.getSolenoidOutput(4));
|
|
|
|
|
assertEquals(0x8, pcm.getSolenoids());
|
|
|
|
|
|
|
|
|
|
// Off
|
|
|
|
|
callback3.reset();
|
|
|
|
|
callback4.reset();
|
2021-09-16 18:50:27 -07:00
|
|
|
doubleSolenoid.set(DoubleSolenoid.Value.kOff);
|
|
|
|
|
assertTrue(callback3.wasTriggered());
|
|
|
|
|
assertFalse(callback3.getSetValue());
|
2021-08-12 02:04:14 -04:00
|
|
|
assertFalse(callback4.wasTriggered());
|
|
|
|
|
assertNull(callback4.getSetValue());
|
2021-09-16 18:50:27 -07:00
|
|
|
assertFalse(sim.getSolenoidOutput(3));
|
|
|
|
|
assertFalse(sim.getSolenoidOutput(4));
|
|
|
|
|
assertEquals(0x0, pcm.getSolenoids());
|
2021-08-12 02:04:14 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void setCompressorOnTest() {
|
|
|
|
|
HAL.initialize(500, 0);
|
|
|
|
|
|
|
|
|
|
CTREPCMSim sim = new CTREPCMSim(0);
|
|
|
|
|
BooleanCallback callback = new BooleanCallback();
|
|
|
|
|
|
|
|
|
|
try (PneumaticsControlModule pcm = new PneumaticsControlModule(0);
|
|
|
|
|
CallbackStore cb = sim.registerCompressorOnCallback(callback, false)) {
|
|
|
|
|
assertFalse(pcm.getCompressor());
|
|
|
|
|
assertFalse(sim.getCompressorOn());
|
|
|
|
|
sim.setCompressorOn(true);
|
|
|
|
|
assertTrue(pcm.getCompressor());
|
|
|
|
|
assertTrue(sim.getCompressorOn());
|
|
|
|
|
assertTrue(callback.wasTriggered());
|
|
|
|
|
assertTrue(callback.getSetValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2021-11-23 20:32:02 -08:00
|
|
|
void setEnableDigital() {
|
2021-08-12 02:04:14 -04:00
|
|
|
HAL.initialize(500, 0);
|
|
|
|
|
|
|
|
|
|
CTREPCMSim sim = new CTREPCMSim(0);
|
|
|
|
|
BooleanCallback callback = new BooleanCallback();
|
|
|
|
|
|
|
|
|
|
try (PneumaticsControlModule pcm = new PneumaticsControlModule(0);
|
|
|
|
|
CallbackStore cb = sim.registerClosedLoopEnabledCallback(callback, false)) {
|
2021-11-23 20:32:02 -08:00
|
|
|
pcm.disableCompressor();
|
|
|
|
|
assertEquals(pcm.getCompressorConfigType(), CompressorConfigType.Disabled);
|
2021-08-12 02:04:14 -04:00
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
pcm.enableCompressorDigital();
|
2021-08-12 02:04:14 -04:00
|
|
|
assertTrue(sim.getClosedLoopEnabled());
|
2021-11-23 20:32:02 -08:00
|
|
|
assertEquals(pcm.getCompressorConfigType(), CompressorConfigType.Digital);
|
2021-08-12 02:04:14 -04:00
|
|
|
assertTrue(callback.wasTriggered());
|
|
|
|
|
assertTrue(callback.getSetValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void setPressureSwitchEnabledTest() {
|
|
|
|
|
HAL.initialize(500, 0);
|
|
|
|
|
|
|
|
|
|
CTREPCMSim sim = new CTREPCMSim(0);
|
|
|
|
|
BooleanCallback callback = new BooleanCallback();
|
|
|
|
|
|
|
|
|
|
try (PneumaticsControlModule pcm = new PneumaticsControlModule(0);
|
|
|
|
|
CallbackStore cb = sim.registerPressureSwitchCallback(callback, false)) {
|
|
|
|
|
assertFalse(pcm.getPressureSwitch());
|
|
|
|
|
|
|
|
|
|
sim.setPressureSwitch(true);
|
|
|
|
|
assertTrue(sim.getPressureSwitch());
|
|
|
|
|
assertTrue(pcm.getPressureSwitch());
|
|
|
|
|
assertTrue(callback.wasTriggered());
|
|
|
|
|
assertTrue(callback.getSetValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void setCompressorCurrentTest() {
|
|
|
|
|
HAL.initialize(500, 0);
|
|
|
|
|
|
|
|
|
|
CTREPCMSim sim = new CTREPCMSim(0);
|
|
|
|
|
DoubleCallback callback = new DoubleCallback();
|
|
|
|
|
|
|
|
|
|
try (PneumaticsControlModule pcm = new PneumaticsControlModule(0);
|
|
|
|
|
CallbackStore cb = sim.registerCompressorCurrentCallback(callback, false)) {
|
|
|
|
|
assertFalse(pcm.getPressureSwitch());
|
|
|
|
|
|
|
|
|
|
sim.setCompressorCurrent(35.04);
|
|
|
|
|
assertEquals(35.04, sim.getCompressorCurrent());
|
|
|
|
|
assertEquals(35.04, pcm.getCompressorCurrent());
|
|
|
|
|
assertTrue(callback.wasTriggered());
|
|
|
|
|
assertEquals(35.04, callback.getSetValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|