blob: 39aee79968337dcb5ff0c8875df9c5d012c7081f [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
James Kuszmaulb13e13f2023-11-22 20:44:04 -08007#include <gtest/gtest.h>
8
Brian Silverman8fce7482020-01-05 13:18:21 -08009#include "TestBench.h"
10#include "frc/AnalogOutput.h"
11#include "frc/RobotController.h"
12#include "frc/Timer.h"
Brian Silverman8fce7482020-01-05 13:18:21 -080013
Austin Schuh812d0d12021-11-04 20:16:48 -070014static constexpr double kScale = 270.0;
15static constexpr double kAngle = 180.0;
Brian Silverman8fce7482020-01-05 13:18:21 -080016
Austin Schuh812d0d12021-11-04 20:16:48 -070017TEST(AnalogPotentiometerTest, InitialSettings) {
18 frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel};
19 frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale};
Brian Silverman8fce7482020-01-05 13:18:21 -080020
Austin Schuh812d0d12021-11-04 20:16:48 -070021 m_fakePot.SetVoltage(0.0);
22 frc::Wait(100_ms);
23 EXPECT_NEAR(0.0, m_pot.Get(), 5.0)
Brian Silverman8fce7482020-01-05 13:18:21 -080024 << "The potentiometer did not initialize to 0.";
25}
26
Austin Schuh812d0d12021-11-04 20:16:48 -070027TEST(AnalogPotentiometerTest, RangeValues) {
28 frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel};
29 frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale};
30
31 m_fakePot.SetVoltage(kAngle / kScale * frc::RobotController::GetVoltage5V());
32 frc::Wait(100_ms);
33 EXPECT_NEAR(kAngle, m_pot.Get(), 2.0)
Brian Silverman8fce7482020-01-05 13:18:21 -080034 << "The potentiometer did not measure the correct angle.";
35}