2020-12-26 14:12:05 -08: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.
|
2014-06-12 11:17:57 -04:00
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include "TestBench.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/AnalogInput.h"
|
|
|
|
|
#include "frc/DigitalInput.h"
|
|
|
|
|
#include "frc/DigitalOutput.h"
|
|
|
|
|
#include "frc/DoubleSolenoid.h"
|
2021-06-05 22:36:39 -07:00
|
|
|
#include "frc/PneumaticsControlModule.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/Solenoid.h"
|
|
|
|
|
#include "frc/Timer.h"
|
2016-09-05 13:55:31 -07:00
|
|
|
#include "gtest/gtest.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2014-08-15 11:22:01 -04:00
|
|
|
/* The PCM switches the compressor up to a couple seconds after the pressure
|
2015-06-25 15:07:55 -04:00
|
|
|
switch changes. */
|
2021-05-28 22:06:59 -07:00
|
|
|
static constexpr auto kCompressorDelayTime = 3_s;
|
2014-06-12 11:17:57 -04:00
|
|
|
|
|
|
|
|
/* Solenoids should change much more quickly */
|
2021-05-28 22:06:59 -07:00
|
|
|
static constexpr auto kSolenoidDelayTime = 0.5_s;
|
2014-06-12 11:17:57 -04:00
|
|
|
|
|
|
|
|
/* The voltage divider on the test bench should bring the compressor output
|
2015-06-25 15:07:55 -04:00
|
|
|
to around these values. */
|
2014-06-12 11:17:57 -04:00
|
|
|
static const double kCompressorOnVoltage = 5.00;
|
|
|
|
|
static const double kCompressorOffVoltage = 1.68;
|
|
|
|
|
|
|
|
|
|
class PCMTest : public testing::Test {
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2021-06-05 22:36:39 -07:00
|
|
|
frc::PneumaticsControlModule m_pneumaticsModule;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::DigitalOutput m_fakePressureSwitch{
|
|
|
|
|
TestBench::kFakePressureSwitchChannel};
|
|
|
|
|
frc::AnalogInput m_fakeCompressor{TestBench::kFakeCompressorChannel};
|
|
|
|
|
frc::DigitalInput m_fakeSolenoid1{TestBench::kFakeSolenoid1Channel};
|
|
|
|
|
frc::DigitalInput m_fakeSolenoid2{TestBench::kFakeSolenoid2Channel};
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
void Reset() {
|
2021-06-05 22:36:39 -07:00
|
|
|
m_pneumaticsModule.SetClosedLoopControl(false);
|
2021-05-31 10:21:34 -07:00
|
|
|
m_fakePressureSwitch.Set(false);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
2014-06-12 11:17:57 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if the compressor turns on and off when the pressure switch is toggled
|
|
|
|
|
*/
|
2015-12-01 17:37:14 -05:00
|
|
|
TEST_F(PCMTest, PressureSwitch) {
|
2015-06-25 15:07:55 -04:00
|
|
|
Reset();
|
2014-06-12 11:17:57 -04:00
|
|
|
|
2021-06-05 22:36:39 -07:00
|
|
|
m_pneumaticsModule.SetClosedLoopControl(true);
|
2014-06-12 11:17:57 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
// Turn on the compressor
|
2021-05-31 10:21:34 -07:00
|
|
|
m_fakePressureSwitch.Set(true);
|
|
|
|
|
frc::Wait(kCompressorDelayTime);
|
|
|
|
|
EXPECT_NEAR(kCompressorOnVoltage, m_fakeCompressor.GetVoltage(), 0.5)
|
2015-06-25 15:07:55 -04:00
|
|
|
<< "Compressor did not turn on when the pressure switch turned on.";
|
2014-06-12 11:17:57 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
// Turn off the compressor
|
2021-05-31 10:21:34 -07:00
|
|
|
m_fakePressureSwitch.Set(false);
|
|
|
|
|
frc::Wait(kCompressorDelayTime);
|
|
|
|
|
EXPECT_NEAR(kCompressorOffVoltage, m_fakeCompressor.GetVoltage(), 0.5)
|
2015-06-25 15:07:55 -04:00
|
|
|
<< "Compressor did not turn off when the pressure switch turned off.";
|
2014-06-12 11:17:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if the correct solenoids turn on and off when they should
|
|
|
|
|
*/
|
2015-11-14 16:54:07 -08:00
|
|
|
TEST_F(PCMTest, Solenoid) {
|
2015-06-25 15:07:55 -04:00
|
|
|
Reset();
|
2021-09-16 18:50:27 -07:00
|
|
|
frc::Solenoid solenoid1{frc::PneumaticsModuleType::CTREPCM,
|
|
|
|
|
TestBench::kSolenoidChannel1};
|
|
|
|
|
frc::Solenoid solenoid2{frc::PneumaticsModuleType::CTREPCM,
|
|
|
|
|
TestBench::kSolenoidChannel2};
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// Turn both solenoids off
|
|
|
|
|
solenoid1.Set(false);
|
|
|
|
|
solenoid2.Set(false);
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
2015-11-14 16:54:07 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// Turn one solenoid on and one off
|
|
|
|
|
solenoid1.Set(true);
|
|
|
|
|
solenoid2.Set(false);
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
2015-11-14 16:54:07 -08:00
|
|
|
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
|
|
|
|
|
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// Turn one solenoid on and one off
|
|
|
|
|
solenoid1.Set(false);
|
|
|
|
|
solenoid2.Set(true);
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
|
2015-11-14 16:54:07 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// Turn both on
|
|
|
|
|
solenoid1.Set(true);
|
|
|
|
|
solenoid2.Set(true);
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
|
2015-11-14 16:54:07 -08:00
|
|
|
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
|
|
|
|
|
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
|
2014-08-05 15:21:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if the correct solenoids turn on and off when they should when used
|
|
|
|
|
* with the DoubleSolenoid class.
|
|
|
|
|
*/
|
2015-11-14 16:54:07 -08:00
|
|
|
TEST_F(PCMTest, DoubleSolenoid) {
|
2021-09-16 18:50:27 -07:00
|
|
|
frc::DoubleSolenoid solenoid{frc::PneumaticsModuleType::CTREPCM,
|
|
|
|
|
TestBench::kSolenoidChannel1,
|
2021-05-31 10:21:34 -07:00
|
|
|
TestBench::kSolenoidChannel2};
|
|
|
|
|
|
|
|
|
|
solenoid.Set(frc::DoubleSolenoid::kOff);
|
|
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
|
|
|
|
EXPECT_TRUE(solenoid.Get() == frc::DoubleSolenoid::kOff)
|
2016-05-20 17:30:37 -07:00
|
|
|
<< "Solenoid does not read off";
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
solenoid.Set(frc::DoubleSolenoid::kForward);
|
|
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
|
|
|
|
EXPECT_TRUE(solenoid.Get() == frc::DoubleSolenoid::kForward)
|
2016-05-20 17:30:37 -07:00
|
|
|
<< "Solenoid does not read forward";
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
solenoid.Set(frc::DoubleSolenoid::kReverse);
|
|
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
|
|
|
|
|
EXPECT_TRUE(solenoid.Get() == frc::DoubleSolenoid::kReverse)
|
2016-05-20 17:30:37 -07:00
|
|
|
<< "Solenoid does not read reverse";
|
2014-06-12 11:17:57 -04:00
|
|
|
}
|
2017-11-26 12:55:21 -08:00
|
|
|
|
|
|
|
|
TEST_F(PCMTest, OneShot) {
|
|
|
|
|
Reset();
|
2021-09-16 18:50:27 -07:00
|
|
|
frc::Solenoid solenoid1{frc::PneumaticsModuleType::CTREPCM,
|
|
|
|
|
TestBench::kSolenoidChannel1};
|
|
|
|
|
frc::Solenoid solenoid2{frc::PneumaticsModuleType::CTREPCM,
|
|
|
|
|
TestBench::kSolenoidChannel2};
|
2017-11-26 12:55:21 -08:00
|
|
|
|
|
|
|
|
// Turn both solenoids off
|
|
|
|
|
solenoid1.Set(false);
|
|
|
|
|
solenoid2.Set(false);
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
|
|
|
|
|
|
|
|
|
|
// Pulse Solenoid #1 on, and turn Solenoid #2 off
|
|
|
|
|
solenoid1.SetPulseDuration(2 * kSolenoidDelayTime);
|
|
|
|
|
solenoid2.Set(false);
|
|
|
|
|
solenoid1.StartPulse();
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
|
|
|
|
|
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(2 * kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
|
|
|
|
|
|
|
|
|
|
// Turn Solenoid #1 off, and pulse Solenoid #2 on
|
|
|
|
|
solenoid1.Set(false);
|
|
|
|
|
solenoid2.SetPulseDuration(2 * kSolenoidDelayTime);
|
|
|
|
|
solenoid2.StartPulse();
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(2 * kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
|
|
|
|
|
|
|
|
|
|
// Pulse both Solenoids on
|
|
|
|
|
solenoid1.SetPulseDuration(2 * kSolenoidDelayTime);
|
|
|
|
|
solenoid2.SetPulseDuration(2 * kSolenoidDelayTime);
|
|
|
|
|
solenoid1.StartPulse();
|
|
|
|
|
solenoid2.StartPulse();
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
|
|
|
|
|
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(2 * kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
|
|
|
|
|
|
|
|
|
|
// Pulse both Solenoids on with different durations
|
|
|
|
|
solenoid1.SetPulseDuration(1.5 * kSolenoidDelayTime);
|
|
|
|
|
solenoid2.SetPulseDuration(2.5 * kSolenoidDelayTime);
|
|
|
|
|
solenoid1.StartPulse();
|
|
|
|
|
solenoid2.StartPulse();
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
|
|
|
|
|
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(2 * kSolenoidDelayTime);
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
|
|
|
|
|
EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
|
2017-11-26 12:55:21 -08:00
|
|
|
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
|
|
|
|
|
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
|
|
|
|
|
}
|