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
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
#include "frc/PowerDistribution.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/Talon.h"
|
2016-09-05 13:55:31 -07:00
|
|
|
#include "gtest/gtest.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2021-05-28 22:06:59 -07:00
|
|
|
static constexpr auto kMotorTime = 0.25_s;
|
2014-06-19 14:56:06 -04:00
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
class PowerDistributionTest : public testing::Test {
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2021-08-04 20:31:17 -07:00
|
|
|
frc::PowerDistribution m_pdp;
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Talon m_talon{TestBench::kTalonChannel};
|
2014-06-19 14:56:06 -04:00
|
|
|
};
|
|
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
TEST_F(PowerDistributionTest, CheckRepeatedCalls) {
|
2021-08-14 11:44:56 -07:00
|
|
|
auto numChannels = HAL_GetNumCTREPDPChannels();
|
2018-12-29 13:57:23 -08:00
|
|
|
// 1 second
|
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
|
for (int j = 0; j < numChannels; j++) {
|
2021-05-31 10:21:34 -07:00
|
|
|
m_pdp.GetCurrent(j);
|
2018-12-29 13:57:23 -08:00
|
|
|
}
|
2021-05-31 10:21:34 -07:00
|
|
|
m_pdp.GetVoltage();
|
2018-12-29 13:57:23 -08:00
|
|
|
}
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::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
|
|
|
|
|
*/
|
2021-08-04 20:31:17 -07:00
|
|
|
TEST_F(PowerDistributionTest, CheckCurrentTalon) {
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(kMotorTime);
|
2014-06-19 14:56:06 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/* The Current should be 0 */
|
2021-05-31 10:21:34 -07:00
|
|
|
EXPECT_FLOAT_EQ(0, m_pdp.GetCurrent(TestBench::kTalonPDPChannel))
|
2015-06-25 15:07:55 -04:00
|
|
|
<< "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 */
|
2021-05-31 10:21:34 -07:00
|
|
|
m_talon.Set(1.0);
|
|
|
|
|
frc::Wait(kMotorTime);
|
2014-06-19 14:56:06 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/* The current should now be positive */
|
2021-05-31 10:21:34 -07:00
|
|
|
ASSERT_GT(m_pdp.GetCurrent(TestBench::kTalonPDPChannel), 0)
|
2015-06-25 15:07:55 -04:00
|
|
|
<< "The Talon current was not positive";
|
2014-06-19 14:56:06 -04:00
|
|
|
}
|