mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user