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 "frc/simulation/AnalogEncoderSim.h"
|
|
|
|
|
|
|
|
|
|
#include "frc/AnalogEncoder.h"
|
|
|
|
|
#include "frc/simulation/SimDeviceSim.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc::sim;
|
|
|
|
|
|
2020-10-22 20:38:12 -07:00
|
|
|
AnalogEncoderSim::AnalogEncoderSim(const frc::AnalogEncoder& encoder) {
|
2021-05-26 07:23:13 -07:00
|
|
|
frc::sim::SimDeviceSim deviceSim{"AnalogEncoder", encoder.GetChannel()};
|
2020-08-19 22:59:52 -07:00
|
|
|
m_positionSim = deviceSim.GetDouble("Position");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnalogEncoderSim::SetPosition(frc::Rotation2d angle) {
|
|
|
|
|
SetTurns(angle.Degrees());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnalogEncoderSim::SetTurns(units::turn_t turns) {
|
2021-10-25 08:58:12 -07:00
|
|
|
m_positionSim.Set(turns.value());
|
2020-08-19 22:59:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
units::turn_t AnalogEncoderSim::GetTurns() {
|
|
|
|
|
return units::turn_t{m_positionSim.Get()};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frc::Rotation2d AnalogEncoderSim::GetPosition() {
|
|
|
|
|
units::radian_t rads = GetTurns();
|
|
|
|
|
return frc::Rotation2d{rads};
|
|
|
|
|
}
|