Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | // 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 4 | |
| 5 | #include "frc/AnalogPotentiometer.h" // NOLINT(build/include_order) |
| 6 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 7 | #include <gtest/gtest.h> |
| 8 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 9 | #include "TestBench.h" |
| 10 | #include "frc/AnalogOutput.h" |
| 11 | #include "frc/RobotController.h" |
| 12 | #include "frc/Timer.h" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 13 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 14 | static constexpr double kScale = 270.0; |
| 15 | static constexpr double kAngle = 180.0; |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 16 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 17 | TEST(AnalogPotentiometerTest, InitialSettings) { |
| 18 | frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel}; |
| 19 | frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale}; |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 20 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 21 | m_fakePot.SetVoltage(0.0); |
| 22 | frc::Wait(100_ms); |
| 23 | EXPECT_NEAR(0.0, m_pot.Get(), 5.0) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 24 | << "The potentiometer did not initialize to 0."; |
| 25 | } |
| 26 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 27 | TEST(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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 34 | << "The potentiometer did not measure the correct angle."; |
| 35 | } |