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
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
static constexpr double kScale = 270.0;
|
|
|
|
|
static constexpr double kAngle = 180.0;
|
2016-11-01 22:33:12 -07:00
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
TEST(AnalogPotentiometerTest, TestInitialSettings) {
|
|
|
|
|
frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel};
|
|
|
|
|
frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale};
|
2014-06-18 16:35:00 -04:00
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
m_fakePot.SetVoltage(0.0);
|
|
|
|
|
frc::Wait(100_ms);
|
|
|
|
|
EXPECT_NEAR(0.0, m_pot.Get(), 5.0)
|
2015-06-25 15:07:55 -04:00
|
|
|
<< "The potentiometer did not initialize to 0.";
|
2014-06-18 16:35:00 -04:00
|
|
|
}
|
|
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
TEST(AnalogPotentiometerTest, TestRangeValues) {
|
|
|
|
|
frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel};
|
|
|
|
|
frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale};
|
|
|
|
|
|
|
|
|
|
m_fakePot.SetVoltage(kAngle / kScale * frc::RobotController::GetVoltage5V());
|
|
|
|
|
frc::Wait(100_ms);
|
|
|
|
|
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
|
|
|
}
|