2014-06-12 11:17:57 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2014. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
Replaced WPILib.h includes in integration tests with the minimum required subheaders to improve compilation times
I ran the benchmark in a tmpfs with an Intel Core i5-2430M. I ran it three times for each combination of build invokation and source tree.
First, I tested "make". For master (eb7d55f), I measured an average of 42.751s with a standard deviation of 0.372s. For this commit, I measured an average of 33.394s with a standard deviation of 0.140s. There was a 9.356s, or 22%, improvement with a total error of 1.3%.
Second, I tested "make -j4". For master (eb7d55f), I measured an average of 21.723s with a standard deviation of 0.158s. For this commit, I measured an average of 16.823s with a standard deviation of 0.340s. There was a 4.900s, or 23%, improvement with a total error of 2.7%.
Change-Id: Idb3adce62ed8ef449360c6583896b6da3565cf58
2015-07-22 02:34:12 -07:00
|
|
|
#include <AnalogInput.h>
|
|
|
|
|
#include <Compressor.h>
|
|
|
|
|
#include <DigitalInput.h>
|
|
|
|
|
#include <DigitalOutput.h>
|
|
|
|
|
#include <DoubleSolenoid.h>
|
|
|
|
|
#include <Solenoid.h>
|
|
|
|
|
#include <Timer.h>
|
2014-06-12 11:17:57 -04:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "TestBench.h"
|
|
|
|
|
|
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. */
|
2014-08-15 11:22:01 -04:00
|
|
|
static const double kCompressorDelayTime = 3.0;
|
2014-06-12 11:17:57 -04:00
|
|
|
|
|
|
|
|
/* Solenoids should change much more quickly */
|
2014-08-15 11:22:01 -04:00
|
|
|
static const double kSolenoidDelayTime = 0.5;
|
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:
|
|
|
|
|
Compressor *m_compressor;
|
|
|
|
|
|
|
|
|
|
DigitalOutput *m_fakePressureSwitch;
|
|
|
|
|
AnalogInput *m_fakeCompressor;
|
|
|
|
|
DoubleSolenoid *m_doubleSolenoid;
|
|
|
|
|
DigitalInput *m_fakeSolenoid1, *m_fakeSolenoid2;
|
|
|
|
|
|
|
|
|
|
virtual void SetUp() override {
|
|
|
|
|
m_compressor = new Compressor();
|
|
|
|
|
|
|
|
|
|
m_fakePressureSwitch =
|
|
|
|
|
new DigitalOutput(TestBench::kFakePressureSwitchChannel);
|
|
|
|
|
m_fakeCompressor = new AnalogInput(TestBench::kFakeCompressorChannel);
|
|
|
|
|
m_fakeSolenoid1 = new DigitalInput(TestBench::kFakeSolenoid1Channel);
|
|
|
|
|
m_fakeSolenoid2 = new DigitalInput(TestBench::kFakeSolenoid2Channel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() override {
|
|
|
|
|
delete m_compressor;
|
|
|
|
|
delete m_fakePressureSwitch;
|
|
|
|
|
delete m_fakeCompressor;
|
|
|
|
|
delete m_fakeSolenoid1;
|
|
|
|
|
delete m_fakeSolenoid2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
|
m_compressor->Stop();
|
|
|
|
|
m_fakePressureSwitch->Set(false);
|
|
|
|
|
}
|
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
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
m_compressor->SetClosedLoopControl(true);
|
2014-06-12 11:17:57 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
// Turn on the compressor
|
|
|
|
|
m_fakePressureSwitch->Set(true);
|
|
|
|
|
Wait(kCompressorDelayTime);
|
|
|
|
|
EXPECT_NEAR(kCompressorOnVoltage, m_fakeCompressor->GetVoltage(), 0.1)
|
|
|
|
|
<< "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
|
|
|
|
|
m_fakePressureSwitch->Set(false);
|
|
|
|
|
Wait(kCompressorDelayTime);
|
|
|
|
|
EXPECT_NEAR(kCompressorOffVoltage, m_fakeCompressor->GetVoltage(), 0.1)
|
|
|
|
|
<< "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();
|
|
|
|
|
Solenoid solenoid1(TestBench::kSolenoidChannel1);
|
|
|
|
|
Solenoid solenoid2(TestBench::kSolenoidChannel2);
|
|
|
|
|
|
|
|
|
|
// Turn both solenoids off
|
|
|
|
|
solenoid1.Set(false);
|
|
|
|
|
solenoid2.Set(false);
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
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) {
|
2015-06-25 15:07:55 -04:00
|
|
|
DoubleSolenoid solenoid(TestBench::kSolenoidChannel1,
|
|
|
|
|
TestBench::kSolenoidChannel2);
|
|
|
|
|
|
|
|
|
|
solenoid.Set(DoubleSolenoid::kOff);
|
|
|
|
|
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_TRUE(solenoid.Get() == DoubleSolenoid::kOff) << "Solenoid does not read off";
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
solenoid.Set(DoubleSolenoid::kForward);
|
|
|
|
|
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(solenoid.Get() == DoubleSolenoid::kForward) << "Solenoid does not read forward";
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
solenoid.Set(DoubleSolenoid::kReverse);
|
|
|
|
|
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_TRUE(solenoid.Get() == DoubleSolenoid::kReverse) << "Solenoid does not read reverse";
|
2014-06-12 11:17:57 -04:00
|
|
|
}
|