diff --git a/wpilibc/wpilibC++/include/WPILib.h b/wpilibc/wpilibC++/include/WPILib.h index 5727f1e43d..be87890969 100644 --- a/wpilibc/wpilibC++/include/WPILib.h +++ b/wpilibc/wpilibC++/include/WPILib.h @@ -67,6 +67,7 @@ #include "PIDOutput.h" #include "PIDSource.h" #include "Preferences.h" +#include "PowerDistributionPanel.h" #include "PWM.h" #include "Relay.h" #include "Resource.h" diff --git a/wpilibc/wpilibC++IntegrationTests/include/TestBench.h b/wpilibc/wpilibC++IntegrationTests/include/TestBench.h index 8eb1a8223e..b1e2b8a09b 100644 --- a/wpilibc/wpilibC++IntegrationTests/include/TestBench.h +++ b/wpilibc/wpilibC++IntegrationTests/include/TestBench.h @@ -50,4 +50,9 @@ public: /* CAN IDs */ static const uint32_t kCANJaguarID = 1; + + /* PDP channels */ + static const uint32_t kJaguarPDPChannel = 7; + static const uint32_t kVictorPDPChannel = 11; + static const uint32_t kTalonPDPChannel = 12; }; diff --git a/wpilibc/wpilibC++IntegrationTests/src/PDPTest.cpp b/wpilibc/wpilibC++IntegrationTests/src/PDPTest.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wpilibc/wpilibC++IntegrationTests/src/PowerDistributionPanelTest.cpp b/wpilibc/wpilibC++IntegrationTests/src/PowerDistributionPanelTest.cpp new file mode 100644 index 0000000000..2630fe0435 --- /dev/null +++ b/wpilibc/wpilibC++IntegrationTests/src/PowerDistributionPanelTest.cpp @@ -0,0 +1,100 @@ +/*----------------------------------------------------------------------------*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ + +#include "WPILib.h" +#include "gtest/gtest.h" +#include "TestBench.h" + +/* The current returned when the motor is not being driven */ +static const double kLowCurrent = 1.52; +static const double kCurrentTolerance = 0.1; + +class PowerDistributionPanelTest : public testing::Test { +protected: + PowerDistributionPanel *m_pdp; + Talon *m_talon; + Victor *m_victor; + Jaguar *m_jaguar; + + virtual void SetUp() { + m_pdp = new PowerDistributionPanel(); + m_talon = new Talon(TestBench::kTalonChannel); + m_victor = new Victor(TestBench::kVictorChannel); + m_jaguar = new Jaguar(TestBench::kJaguarChannel); + } + + virtual void TearDown() { + delete m_pdp; + delete m_talon; + delete m_victor; + delete m_jaguar; + } + + void Reset() { + /* Reset all speed controllers to 0.0 */ + m_talon->Set(0.0f); + m_victor->Set(0.0f); + m_jaguar->Set(0.0f); + } +}; + +/** + * Test if the current changes when the motor is driven using a talon + */ +TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) { + Reset(); + + /* The Current should be kLowCurrent */ + EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kTalonPDPChannel), kCurrentTolerance) + << "The low current was not within the expected range."; + + /* Set the motor to full forward */ + m_talon->Set(1.0); + Wait(0.02); + + /* The current should now be greater than the low current */ + ASSERT_GT(m_pdp->GetCurrent(TestBench::kTalonPDPChannel), kLowCurrent) + << "The driven current is not greater than the resting current."; +} + +/** + * Test if the current changes when the motor is driven using a victor + */ +TEST_F(PowerDistributionPanelTest,CheckCurrentVictor) { + Reset(); + + /* The Current should be kLowCurrent */ + EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kVictorPDPChannel), kCurrentTolerance) + << "The low current was not within the expected range."; + + /* Set the motor to full forward */ + m_victor->Set(1.0); + Wait(0.02); + + /* The current should now be greater than the low current */ + ASSERT_GT(m_pdp->GetCurrent(TestBench::kVictorPDPChannel), kLowCurrent) + << "The driven current is not greater than the resting current."; +} + +/** + * Test if the current changes when the motor is driven using a jaguar + */ +TEST_F(PowerDistributionPanelTest, CheckCurrentJaguar) { + Reset(); + + /* The Current should be kLowCurrent */ + EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kJaguarPDPChannel), kCurrentTolerance) + << "The low current was not within the expected range."; + + /* Set the motor to full forward */ + m_jaguar->Set(1.0); + Wait(0.02); + + /* The current should now be greater than the low current */ + ASSERT_GT(m_pdp->GetCurrent(TestBench::kJaguarPDPChannel), kLowCurrent) + << "The driven current is not greater than the resting current."; +} diff --git a/wpilibj/wpilibJavaIntegrationTests/pom.xml b/wpilibj/wpilibJavaIntegrationTests/pom.xml index b13f2e5a33..788080179d 100644 --- a/wpilibj/wpilibJavaIntegrationTests/pom.xml +++ b/wpilibj/wpilibJavaIntegrationTests/pom.xml @@ -26,7 +26,7 @@ org.hamcrest - hamcrest-core + hamcrest-all 1.3