mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Fixed DoubleSolenoid, added a double solenoid test
Change-Id: I161337c8b528be7662650889d6ab7bcd2bbe2704 Fixed double solenoid, added a C++ test Change-Id: Ib0821155efce85be87d354fc8e197fcc4deabd7c
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. All Rights Reserved. */
|
||||
/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -50,8 +50,8 @@ void DoubleSolenoid::InitSolenoid()
|
||||
return;
|
||||
}
|
||||
|
||||
m_forwardMask = 1 << (m_forwardChannel - 1);
|
||||
m_reverseMask = 1 << (m_reverseChannel - 1);
|
||||
m_forwardMask = 1 << m_forwardChannel;
|
||||
m_reverseMask = 1 << m_reverseChannel;
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_Solenoid, m_forwardChannel, m_moduleNumber);
|
||||
HALReport(HALUsageReporting::kResourceType_Solenoid, m_reverseChannel, m_moduleNumber);
|
||||
|
||||
@@ -28,7 +28,7 @@ void Solenoid::InitSolenoid()
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
return;
|
||||
}
|
||||
Resource::CreateResourceObject(&m_allocated, solenoid_kNumDO7_0Elements * kSolenoidChannels);
|
||||
Resource::CreateResourceObject(&m_allocated, kSolenoidChannels * 63);
|
||||
|
||||
snprintf(buf, 64, "Solenoid %d (Module: %d)", m_channel, m_moduleNumber);
|
||||
if (m_allocated->Allocate(m_moduleNumber * kSolenoidChannels + m_channel, buf) == ~0ul)
|
||||
|
||||
@@ -59,4 +59,8 @@ public:
|
||||
static const uint32_t kJaguarPDPChannel = 6;
|
||||
static const uint32_t kVictorPDPChannel = 8;
|
||||
static const uint32_t kTalonPDPChannel = 11;
|
||||
|
||||
/* PCM channels */
|
||||
static const int32_t kSolenoidChannel1 = 7;
|
||||
static const int32_t kSolenoidChannel2 = 6;
|
||||
};
|
||||
|
||||
@@ -10,110 +10,126 @@
|
||||
#include "TestBench.h"
|
||||
|
||||
/* The PCM switches the compressor up to 2 seconds after the pressure switch
|
||||
changes. */
|
||||
changes. */
|
||||
static const double kCompressorDelayTime = 2.0;
|
||||
|
||||
/* Solenoids should change much more quickly */
|
||||
static const double kSolenoidDelayTime = 0.1;
|
||||
|
||||
/* The voltage divider on the test bench should bring the compressor output
|
||||
to around these values. */
|
||||
to around these values. */
|
||||
static const double kCompressorOnVoltage = 5.00;
|
||||
static const double kCompressorOffVoltage = 1.68;
|
||||
|
||||
class PCMTest : public testing::Test {
|
||||
protected:
|
||||
Compressor *m_compressor;
|
||||
Compressor *m_compressor;
|
||||
|
||||
DigitalOutput *m_fakePressureSwitch;
|
||||
AnalogInput *m_fakeCompressor;
|
||||
DigitalOutput *m_fakePressureSwitch;
|
||||
AnalogInput *m_fakeCompressor;
|
||||
DoubleSolenoid *m_doubleSolenoid;
|
||||
DigitalInput *m_fakeSolenoid1, *m_fakeSolenoid2;
|
||||
|
||||
Solenoid *m_solenoid1, *m_solenoid2;
|
||||
DigitalInput *m_fakeSolenoid1, *m_fakeSolenoid2;
|
||||
virtual void SetUp() {
|
||||
m_compressor = new Compressor();
|
||||
|
||||
virtual void SetUp() {
|
||||
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);
|
||||
}
|
||||
|
||||
m_fakePressureSwitch = new DigitalOutput(TestBench::kFakePressureSwitchChannel);
|
||||
m_fakeCompressor = new AnalogInput(TestBench::kFakeCompressorChannel);
|
||||
virtual void TearDown() {
|
||||
delete m_compressor;
|
||||
delete m_fakePressureSwitch;
|
||||
delete m_fakeCompressor;
|
||||
delete m_fakeSolenoid1;
|
||||
delete m_fakeSolenoid2;
|
||||
}
|
||||
|
||||
m_solenoid1 = new Solenoid(7);
|
||||
m_solenoid2 = new Solenoid(6);
|
||||
|
||||
m_fakeSolenoid1 = new DigitalInput(TestBench::kFakeSolenoid1Channel);
|
||||
m_fakeSolenoid2 = new DigitalInput(TestBench::kFakeSolenoid2Channel);
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
delete m_compressor;
|
||||
delete m_fakePressureSwitch;
|
||||
delete m_fakeCompressor;
|
||||
delete m_solenoid1;
|
||||
delete m_solenoid2;
|
||||
delete m_fakeSolenoid1;
|
||||
delete m_fakeSolenoid2;
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
m_compressor->Stop();
|
||||
m_fakePressureSwitch->Set(false);
|
||||
m_solenoid1->Set(false);
|
||||
m_solenoid2->Set(false);
|
||||
}
|
||||
void Reset() {
|
||||
m_compressor->Stop();
|
||||
m_fakePressureSwitch->Set(false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if the compressor turns on and off when the pressure switch is toggled
|
||||
*/
|
||||
TEST_F(PCMTest, PressureSwitch) {
|
||||
Reset();
|
||||
Reset();
|
||||
|
||||
m_compressor->SetClosedLoopControl(true);
|
||||
m_compressor->SetClosedLoopControl(true);
|
||||
|
||||
// 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.";
|
||||
// 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.";
|
||||
|
||||
// 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.";
|
||||
// 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.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the correct solenoids turn on and off when they should
|
||||
*/
|
||||
TEST_F(PCMTest, Solenoid) {
|
||||
Reset();
|
||||
Reset();
|
||||
Solenoid solenoid1(TestBench::kSolenoidChannel1);
|
||||
Solenoid solenoid2(TestBench::kSolenoidChannel2);
|
||||
|
||||
// Turn both solenoids off
|
||||
m_solenoid1->Set(false);
|
||||
m_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";
|
||||
// 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";
|
||||
|
||||
// Turn one solenoid on and one off
|
||||
m_solenoid1->Set(true);
|
||||
m_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";
|
||||
// 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";
|
||||
|
||||
// Turn one solenoid on and one off
|
||||
m_solenoid1->Set(false);
|
||||
m_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";
|
||||
// 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";
|
||||
|
||||
// Turn both on
|
||||
m_solenoid1->Set(true);
|
||||
m_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";
|
||||
// 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";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the correct solenoids turn on and off when they should when used
|
||||
* with the DoubleSolenoid class.
|
||||
*/
|
||||
TEST_F(PCMTest, DoubleSolenoid) {
|
||||
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";
|
||||
|
||||
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";
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user