2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2014-06-19 14:56:06 -04:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/PowerDistributionPanel.h" // NOLINT(build/include_order)
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2018-12-29 13:57:23 -08:00
|
|
|
#include <hal/Ports.h>
|
2021-05-28 22:06:59 -07:00
|
|
|
#include <units/time.h>
|
2018-12-29 13:57:23 -08:00
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include "TestBench.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/Timer.h"
|
2021-04-17 11:27:16 -07:00
|
|
|
#include "frc/motorcontrol/Jaguar.h"
|
|
|
|
|
#include "frc/motorcontrol/Talon.h"
|
|
|
|
|
#include "frc/motorcontrol/Victor.h"
|
2016-09-05 13:55:31 -07:00
|
|
|
#include "gtest/gtest.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2021-05-28 22:06:59 -07:00
|
|
|
static constexpr auto kMotorTime = 0.25_s;
|
2014-06-19 14:56:06 -04:00
|
|
|
|
|
|
|
|
class PowerDistributionPanelTest : public testing::Test {
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2016-05-20 17:30:37 -07:00
|
|
|
PowerDistributionPanel* m_pdp;
|
|
|
|
|
Talon* m_talon;
|
|
|
|
|
Victor* m_victor;
|
|
|
|
|
Jaguar* m_jaguar;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
void SetUp() override {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_pdp = new PowerDistributionPanel();
|
|
|
|
|
m_talon = new Talon(TestBench::kTalonChannel);
|
|
|
|
|
m_victor = new Victor(TestBench::kVictorChannel);
|
|
|
|
|
m_jaguar = new Jaguar(TestBench::kJaguarChannel);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
void TearDown() override {
|
2015-06-25 15:07:55 -04:00
|
|
|
delete m_pdp;
|
|
|
|
|
delete m_talon;
|
|
|
|
|
delete m_victor;
|
|
|
|
|
delete m_jaguar;
|
|
|
|
|
}
|
2014-06-19 14:56:06 -04:00
|
|
|
};
|
|
|
|
|
|
2018-12-29 13:57:23 -08:00
|
|
|
TEST_F(PowerDistributionPanelTest, CheckRepeatedCalls) {
|
|
|
|
|
auto numChannels = HAL_GetNumPDPChannels();
|
|
|
|
|
// 1 second
|
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
|
for (int j = 0; j < numChannels; j++) {
|
|
|
|
|
m_pdp->GetCurrent(j);
|
|
|
|
|
}
|
|
|
|
|
m_pdp->GetVoltage();
|
|
|
|
|
}
|
2021-05-28 22:06:59 -07:00
|
|
|
Wait(20_ms);
|
2018-12-29 13:57:23 -08:00
|
|
|
}
|
|
|
|
|
|
2014-06-19 14:56:06 -04:00
|
|
|
/**
|
|
|
|
|
* Test if the current changes when the motor is driven using a talon
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) {
|
|
|
|
|
Wait(kMotorTime);
|
2014-06-19 14:56:06 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/* The Current should be 0 */
|
|
|
|
|
EXPECT_FLOAT_EQ(0, m_pdp->GetCurrent(TestBench::kTalonPDPChannel))
|
|
|
|
|
<< "The Talon current was non-zero";
|
2014-06-19 14:56:06 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Set the motor to full forward */
|
|
|
|
|
m_talon->Set(1.0);
|
|
|
|
|
Wait(kMotorTime);
|
2014-06-19 14:56:06 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/* The current should now be positive */
|
|
|
|
|
ASSERT_GT(m_pdp->GetCurrent(TestBench::kTalonPDPChannel), 0)
|
|
|
|
|
<< "The Talon current was not positive";
|
2014-06-19 14:56:06 -04:00
|
|
|
}
|