[hal, wpilib] Incorporate pneumatic control type into wpilibc/j (#3728)

This commit is contained in:
Thad House
2021-11-23 20:32:02 -08:00
committed by GitHub
parent 9aba2b7583
commit b156db400d
35 changed files with 693 additions and 216 deletions

View File

@@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.CompressorConfigType;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticsControlModule;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
@@ -109,7 +110,7 @@ class CTREPCMSimTest {
}
@Test
void setClosedLoopEnabled() {
void setEnableDigital() {
HAL.initialize(500, 0);
CTREPCMSim sim = new CTREPCMSim(0);
@@ -117,12 +118,12 @@ class CTREPCMSimTest {
try (PneumaticsControlModule pcm = new PneumaticsControlModule(0);
CallbackStore cb = sim.registerClosedLoopEnabledCallback(callback, false)) {
pcm.setClosedLoopControl(false);
assertFalse(pcm.getClosedLoopControl());
pcm.disableCompressor();
assertEquals(pcm.getCompressorConfigType(), CompressorConfigType.Disabled);
pcm.setClosedLoopControl(true);
pcm.enableCompressorDigital();
assertTrue(sim.getClosedLoopEnabled());
assertTrue(pcm.getClosedLoopControl());
assertEquals(pcm.getCompressorConfigType(), CompressorConfigType.Digital);
assertTrue(callback.wasTriggered());
assertTrue(callback.getSetValue());
}

View File

@@ -10,11 +10,13 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.CompressorConfigType;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticHub;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
import edu.wpi.first.wpilibj.simulation.testutils.BooleanCallback;
import edu.wpi.first.wpilibj.simulation.testutils.DoubleCallback;
import edu.wpi.first.wpilibj.simulation.testutils.EnumCallback;
import org.junit.jupiter.api.Test;
@SuppressWarnings("AbbreviationAsWordInName")
@@ -109,22 +111,62 @@ class REVPHSimTest {
}
@Test
void setClosedLoopEnabled() {
void setEnableDigital() {
HAL.initialize(500, 0);
REVPHSim sim = new REVPHSim(1);
BooleanCallback callback = new BooleanCallback();
EnumCallback callback = new EnumCallback();
try (PneumaticHub ph = new PneumaticHub(1);
CallbackStore cb = sim.registerClosedLoopEnabledCallback(callback, false)) {
ph.setClosedLoopControl(false);
assertFalse(ph.getClosedLoopControl());
CallbackStore cb = sim.registerCompressorConfigTypeCallback(callback, false)) {
ph.disableCompressor();
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Disabled);
ph.setClosedLoopControl(true);
assertTrue(sim.getClosedLoopEnabled());
assertTrue(ph.getClosedLoopControl());
ph.enableCompressorDigital();
assertEquals(sim.getCompressorConfigType(), CompressorConfigType.Digital.getValue());
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Digital);
assertTrue(callback.wasTriggered());
assertTrue(callback.getSetValue());
assertEquals(callback.getSetValue(), CompressorConfigType.Digital.getValue());
}
}
@Test
void setEnableAnalog() {
HAL.initialize(500, 0);
REVPHSim sim = new REVPHSim(1);
EnumCallback callback = new EnumCallback();
try (PneumaticHub ph = new PneumaticHub(1);
CallbackStore cb = sim.registerCompressorConfigTypeCallback(callback, false)) {
ph.disableCompressor();
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Disabled);
ph.enableCompressorAnalog(1, 2);
assertEquals(sim.getCompressorConfigType(), CompressorConfigType.Analog.getValue());
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Analog);
assertTrue(callback.wasTriggered());
assertEquals(callback.getSetValue(), CompressorConfigType.Analog.getValue());
}
}
@Test
void setEnableHybrid() {
HAL.initialize(500, 0);
REVPHSim sim = new REVPHSim(1);
EnumCallback callback = new EnumCallback();
try (PneumaticHub ph = new PneumaticHub(1);
CallbackStore cb = sim.registerCompressorConfigTypeCallback(callback, false)) {
ph.disableCompressor();
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Disabled);
ph.enableCompressorHybrid(1, 2);
assertEquals(sim.getCompressorConfigType(), CompressorConfigType.Hybrid.getValue());
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Hybrid);
assertTrue(callback.wasTriggered());
assertEquals(callback.getSetValue(), CompressorConfigType.Hybrid.getValue());
}
}