blob: 107310fdbb5d62f07b82f644e35e62be8fe28ba2 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
Brian Silverman8fce7482020-01-05 13:18:21 -08004
5#include "frc/AnalogPotentiometer.h" // NOLINT(build/include_order)
6
7#include "TestBench.h"
8#include "frc/AnalogOutput.h"
9#include "frc/RobotController.h"
10#include "frc/Timer.h"
11#include "gtest/gtest.h"
12
Austin Schuh812d0d12021-11-04 20:16:48 -070013static constexpr double kScale = 270.0;
14static constexpr double kAngle = 180.0;
Brian Silverman8fce7482020-01-05 13:18:21 -080015
Austin Schuh812d0d12021-11-04 20:16:48 -070016TEST(AnalogPotentiometerTest, InitialSettings) {
17 frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel};
18 frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale};
Brian Silverman8fce7482020-01-05 13:18:21 -080019
Austin Schuh812d0d12021-11-04 20:16:48 -070020 m_fakePot.SetVoltage(0.0);
21 frc::Wait(100_ms);
22 EXPECT_NEAR(0.0, m_pot.Get(), 5.0)
Brian Silverman8fce7482020-01-05 13:18:21 -080023 << "The potentiometer did not initialize to 0.";
24}
25
Austin Schuh812d0d12021-11-04 20:16:48 -070026TEST(AnalogPotentiometerTest, RangeValues) {
27 frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel};
28 frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale};
29
30 m_fakePot.SetVoltage(kAngle / kScale * frc::RobotController::GetVoltage5V());
31 frc::Wait(100_ms);
32 EXPECT_NEAR(kAngle, m_pot.Get(), 2.0)
Brian Silverman8fce7482020-01-05 13:18:21 -080033 << "The potentiometer did not measure the correct angle.";
34}