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 | |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 13 | static constexpr double kScale = 270.0; |
| 14 | static constexpr double kAngle = 180.0; |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 15 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 16 | TEST(AnalogPotentiometerTest, InitialSettings) { |
| 17 | frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel}; |
| 18 | frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale}; |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 19 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 20 | m_fakePot.SetVoltage(0.0); |
| 21 | frc::Wait(100_ms); |
| 22 | EXPECT_NEAR(0.0, m_pot.Get(), 5.0) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 23 | << "The potentiometer did not initialize to 0."; |
| 24 | } |
| 25 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 26 | TEST(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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 33 | << "The potentiometer did not measure the correct angle."; |
| 34 | } |