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.
|
2020-08-19 22:59:52 -07:00
|
|
|
|
|
|
|
|
#include <hal/HAL.h>
|
|
|
|
|
#include <units/math.h>
|
2021-05-26 00:09:36 -07:00
|
|
|
#include <wpi/numbers>
|
2020-08-19 22:59:52 -07:00
|
|
|
|
|
|
|
|
#include "frc/AnalogEncoder.h"
|
|
|
|
|
#include "frc/AnalogInput.h"
|
|
|
|
|
#include "frc/simulation/AnalogEncoderSim.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
#define EXPECT_NEAR_UNITS(val1, val2, eps) \
|
|
|
|
|
EXPECT_LE(units::math::abs(val1 - val2), eps)
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST(AnalogEncoderSimTest, Basic) {
|
2020-08-19 22:59:52 -07:00
|
|
|
frc::AnalogInput ai(0);
|
|
|
|
|
frc::AnalogEncoder encoder{ai};
|
|
|
|
|
frc::sim::AnalogEncoderSim encoderSim{encoder};
|
|
|
|
|
|
|
|
|
|
encoderSim.SetPosition(180_deg);
|
|
|
|
|
EXPECT_NEAR(encoder.Get().to<double>(), 0.5, 1E-8);
|
|
|
|
|
EXPECT_NEAR(encoderSim.GetTurns().to<double>(), 0.5, 1E-8);
|
2021-05-26 00:09:36 -07:00
|
|
|
EXPECT_NEAR(encoderSim.GetPosition().Radians().to<double>(), wpi::numbers::pi,
|
2020-08-19 22:59:52 -07:00
|
|
|
1E-8);
|
|
|
|
|
}
|