Files
allwpilib/wpilibc/src/test/native/cpp/simulation/AnalogEncoderSimTest.cpp
Tyler Veness 181723e573 Replace .to<double>() and .template to<double>() with .value() (#3667)
It's a less verbose way to do the same thing.
2021-10-25 08:58:12 -07:00

28 lines
881 B
C++

// 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.
#include <hal/HAL.h>
#include <units/math.h>
#include <wpi/numbers>
#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)
TEST(AnalogEncoderSimTest, Basic) {
frc::AnalogInput ai(0);
frc::AnalogEncoder encoder{ai};
frc::sim::AnalogEncoderSim encoderSim{encoder};
encoderSim.SetPosition(180_deg);
EXPECT_NEAR(encoder.Get().value(), 0.5, 1E-8);
EXPECT_NEAR(encoderSim.GetTurns().value(), 0.5, 1E-8);
EXPECT_NEAR(encoderSim.GetPosition().Radians().value(), wpi::numbers::pi,
1E-8);
}