blob: 5917361fb1a08d072b8f5805e530b49b5d97323f [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) 2014-2018 FIRST. 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 "frc/PowerDistributionPanel.h" // NOLINT(build/include_order)
9
10#include <thread>
11
12#include <hal/Ports.h>
13
14#include "TestBench.h"
15#include "frc/Jaguar.h"
16#include "frc/Talon.h"
17#include "frc/Timer.h"
18#include "frc/Victor.h"
19#include "gtest/gtest.h"
20
21using namespace frc;
22
23static const double kMotorTime = 0.25;
24
25class PowerDistributionPanelTest : public testing::Test {
26 protected:
27 PowerDistributionPanel* m_pdp;
28 Talon* m_talon;
29 Victor* m_victor;
30 Jaguar* m_jaguar;
31
32 void SetUp() override {
33 m_pdp = new PowerDistributionPanel();
34 m_talon = new Talon(TestBench::kTalonChannel);
35 m_victor = new Victor(TestBench::kVictorChannel);
36 m_jaguar = new Jaguar(TestBench::kJaguarChannel);
37 }
38
39 void TearDown() override {
40 delete m_pdp;
41 delete m_talon;
42 delete m_victor;
43 delete m_jaguar;
44 }
45};
46
47TEST_F(PowerDistributionPanelTest, CheckRepeatedCalls) {
48 auto numChannels = HAL_GetNumPDPChannels();
49 // 1 second
50 for (int i = 0; i < 50; i++) {
51 for (int j = 0; j < numChannels; j++) {
52 m_pdp->GetCurrent(j);
53 ASSERT_TRUE(m_pdp->GetError().GetCode() == 0);
54 }
55 m_pdp->GetVoltage();
56 ASSERT_TRUE(m_pdp->GetError().GetCode() == 0);
57 }
58 std::this_thread::sleep_for(std::chrono::milliseconds(20));
59}
60
61/**
62 * Test if the current changes when the motor is driven using a talon
63 */
64TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) {
65 Wait(kMotorTime);
66
67 /* The Current should be 0 */
68 EXPECT_FLOAT_EQ(0, m_pdp->GetCurrent(TestBench::kTalonPDPChannel))
69 << "The Talon current was non-zero";
70
71 /* Set the motor to full forward */
72 m_talon->Set(1.0);
73 Wait(kMotorTime);
74
75 /* The current should now be positive */
76 ASSERT_GT(m_pdp->GetCurrent(TestBench::kTalonPDPChannel), 0)
77 << "The Talon current was not positive";
78}