[sim] Use DutyCycleEncoder FPGA index for sim device number (#2803)

The source channel doesn't necessarily correspond with the HALSIM device
index.
This commit is contained in:
Tyler Veness
2020-10-24 20:18:58 -07:00
committed by GitHub
parent 1e17e40868
commit 7ae8c7b247
5 changed files with 23 additions and 2 deletions

View File

@@ -132,6 +132,10 @@ void DutyCycleEncoder::SetConnectedFrequencyThreshold(int frequency) {
m_frequencyThreshold = frequency;
}
int DutyCycleEncoder::GetFPGAIndex() const {
return m_dutyCycle->GetFPGAIndex();
}
int DutyCycleEncoder::GetSourceChannel() const {
return m_dutyCycle->GetSourceChannel();
}

View File

@@ -18,7 +18,7 @@ using namespace frc::sim;
DutyCycleEncoderSim::DutyCycleEncoderSim(const frc::DutyCycleEncoder& encoder) {
wpi::SmallString<128> fullname;
wpi::raw_svector_ostream os(fullname);
os << "DutyCycleEncoder" << '[' << encoder.GetSourceChannel() << ']';
os << "DutyCycleEncoder" << '[' << encoder.GetFPGAIndex() << ']';
frc::sim::SimDeviceSim deviceSim{fullname.c_str()};
m_simPosition = deviceSim.GetDouble("Position");
m_simDistancePerRotation = deviceSim.GetDouble("DistancePerRotation");

View File

@@ -154,6 +154,13 @@ class DutyCycleEncoder : public ErrorBase,
*/
double GetDistance() const;
/**
* Get the FPGA index for the DutyCycleEncoder.
*
* @return the FPGA index
*/
int GetFPGAIndex() const;
/**
* Get the channel of the source.
*

View File

@@ -236,6 +236,16 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
}
}
/**
* Get the FPGA index for the DutyCycleEncoder.
*
* @return the FPGA index
*/
@SuppressWarnings("AbbreviationAsWordInName")
public int getFPGAIndex() {
return m_dutyCycle.getFPGAIndex();
}
/**
* Get the channel of the source.
*

View File

@@ -23,7 +23,7 @@ public class DutyCycleEncoderSim {
* @param encoder DutyCycleEncoder to simulate
*/
public DutyCycleEncoderSim(DutyCycleEncoder encoder) {
SimDeviceSim wrappedSimDevice = new SimDeviceSim("DutyCycleEncoder" + "[" + encoder.getSourceChannel() + "]");
SimDeviceSim wrappedSimDevice = new SimDeviceSim("DutyCycleEncoder" + "[" + encoder.getFPGAIndex() + "]");
m_simPosition = wrappedSimDevice.getDouble("Position");
m_simDistancePerRotation = wrappedSimDevice.getDouble("DistancePerRotation");
}