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-10-23 20:18:49 -07:00
|
|
|
|
|
|
|
|
#include "frc/simulation/DutyCycleEncoderSim.h"
|
|
|
|
|
|
|
|
|
|
#include "frc/DutyCycleEncoder.h"
|
|
|
|
|
#include "frc/simulation/SimDeviceSim.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc::sim;
|
|
|
|
|
|
|
|
|
|
DutyCycleEncoderSim::DutyCycleEncoderSim(const frc::DutyCycleEncoder& encoder) {
|
2021-05-26 07:23:13 -07:00
|
|
|
frc::sim::SimDeviceSim deviceSim{"DutyCycle:DutyCycleEncoder",
|
|
|
|
|
encoder.GetSourceChannel()};
|
2020-12-24 12:23:38 -08:00
|
|
|
m_simPosition = deviceSim.GetDouble("position");
|
|
|
|
|
m_simDistancePerRotation = deviceSim.GetDouble("distance_per_rot");
|
2020-10-23 20:18:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DutyCycleEncoderSim::Set(units::turn_t turns) {
|
2021-10-25 08:58:12 -07:00
|
|
|
m_simPosition.Set(turns.value());
|
2020-10-23 20:18:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DutyCycleEncoderSim::SetDistance(double distance) {
|
|
|
|
|
m_simPosition.Set(distance / m_simDistancePerRotation.Get());
|
|
|
|
|
}
|