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 <wpi/SmallString.h>
|
|
|
|
|
#include <wpi/raw_ostream.h>
|
|
|
|
|
|
|
|
|
|
#include "frc/DutyCycleEncoder.h"
|
|
|
|
|
#include "frc/simulation/SimDeviceSim.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc::sim;
|
|
|
|
|
|
|
|
|
|
DutyCycleEncoderSim::DutyCycleEncoderSim(const frc::DutyCycleEncoder& encoder) {
|
|
|
|
|
wpi::SmallString<128> fullname;
|
|
|
|
|
wpi::raw_svector_ostream os(fullname);
|
2020-12-24 12:23:38 -08:00
|
|
|
os << "DutyCycle:DutyCycleEncoder" << '[' << encoder.GetSourceChannel()
|
|
|
|
|
<< ']';
|
2020-10-23 20:18:49 -07:00
|
|
|
frc::sim::SimDeviceSim deviceSim{fullname.c_str()};
|
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) {
|
|
|
|
|
m_simPosition.Set(turns.to<double>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DutyCycleEncoderSim::SetDistance(double distance) {
|
|
|
|
|
m_simPosition.Set(distance / m_simDistancePerRotation.Get());
|
|
|
|
|
}
|