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-18 16:35:00 -04:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/AnalogPotentiometer.h" // NOLINT(build/include_order)
|
2016-05-25 22:38:11 -07:00
|
|
|
|
|
|
|
|
#include "TestBench.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/AnalogOutput.h"
|
|
|
|
|
#include "frc/RobotController.h"
|
|
|
|
|
#include "frc/Timer.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;
|
|
|
|
|
|
2014-10-23 16:42:15 +00:00
|
|
|
static const double kScale = 270.0;
|
2014-06-18 16:35:00 -04:00
|
|
|
static const double kAngle = 180.0;
|
|
|
|
|
|
|
|
|
|
class AnalogPotentiometerTest : public testing::Test {
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2016-05-20 17:30:37 -07:00
|
|
|
AnalogOutput* m_fakePot;
|
|
|
|
|
AnalogPotentiometer* m_pot;
|
2014-06-18 16:35:00 -04:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
void SetUp() override {
|
2014-06-18 16:35:00 -04:00
|
|
|
m_fakePot = new AnalogOutput(TestBench::kAnalogOutputChannel);
|
2015-06-25 15:07:55 -04:00
|
|
|
m_pot =
|
|
|
|
|
new AnalogPotentiometer(TestBench::kFakeAnalogOutputChannel, kScale);
|
2014-06-18 16:35:00 -04:00
|
|
|
}
|
|
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
void TearDown() override {
|
2014-06-18 16:35:00 -04:00
|
|
|
delete m_fakePot;
|
|
|
|
|
delete m_pot;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(AnalogPotentiometerTest, TestInitialSettings) {
|
|
|
|
|
m_fakePot->SetVoltage(0.0);
|
2021-05-28 22:06:59 -07:00
|
|
|
Wait(0.1_s);
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_NEAR(0.0, m_pot->Get(), 5.0)
|
|
|
|
|
<< "The potentiometer did not initialize to 0.";
|
2014-06-18 16:35:00 -04:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_F(AnalogPotentiometerTest, TestRangeValues) {
|
2017-12-11 22:15:29 -08:00
|
|
|
m_fakePot->SetVoltage(kAngle / kScale * RobotController::GetVoltage5V());
|
2021-05-28 22:06:59 -07:00
|
|
|
Wait(0.1_s);
|
2014-10-23 16:42:15 +00:00
|
|
|
EXPECT_NEAR(kAngle, m_pot->Get(), 2.0)
|
2015-06-25 15:07:55 -04:00
|
|
|
<< "The potentiometer did not measure the correct angle.";
|
2014-06-18 16:35:00 -04:00
|
|
|
}
|