Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2014-2017. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "PowerDistributionPanel.h" // NOLINT(build/include_order) |
| 9 | |
| 10 | #include "Jaguar.h" |
| 11 | #include "Talon.h" |
| 12 | #include "TestBench.h" |
| 13 | #include "Timer.h" |
| 14 | #include "Victor.h" |
| 15 | #include "gtest/gtest.h" |
| 16 | |
| 17 | using namespace frc; |
| 18 | |
| 19 | static const double kMotorTime = 0.25; |
| 20 | |
| 21 | class PowerDistributionPanelTest : public testing::Test { |
| 22 | protected: |
| 23 | PowerDistributionPanel* m_pdp; |
| 24 | Talon* m_talon; |
| 25 | Victor* m_victor; |
| 26 | Jaguar* m_jaguar; |
| 27 | |
| 28 | void SetUp() override { |
| 29 | m_pdp = new PowerDistributionPanel(); |
| 30 | m_talon = new Talon(TestBench::kTalonChannel); |
| 31 | m_victor = new Victor(TestBench::kVictorChannel); |
| 32 | m_jaguar = new Jaguar(TestBench::kJaguarChannel); |
| 33 | } |
| 34 | |
| 35 | void TearDown() override { |
| 36 | delete m_pdp; |
| 37 | delete m_talon; |
| 38 | delete m_victor; |
| 39 | delete m_jaguar; |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * Test if the current changes when the motor is driven using a talon |
| 45 | */ |
| 46 | TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) { |
| 47 | Wait(kMotorTime); |
| 48 | |
| 49 | /* The Current should be 0 */ |
| 50 | EXPECT_FLOAT_EQ(0, m_pdp->GetCurrent(TestBench::kTalonPDPChannel)) |
| 51 | << "The Talon current was non-zero"; |
| 52 | |
| 53 | /* Set the motor to full forward */ |
| 54 | m_talon->Set(1.0); |
| 55 | Wait(kMotorTime); |
| 56 | |
| 57 | /* The current should now be positive */ |
| 58 | ASSERT_GT(m_pdp->GetCurrent(TestBench::kTalonPDPChannel), 0) |
| 59 | << "The Talon current was not positive"; |
| 60 | } |