mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[sim] Fix ADXRS450_GyroSim and DutyCycleEncoderSim (#2963)
These were broken by #2952. Also fix Java ADXRS450_Gyro angle/rate SimValue names.
This commit is contained in:
@@ -60,6 +60,8 @@ void DutyCycleEncoder::Init() {
|
||||
if (m_simDevice) {
|
||||
m_simPosition =
|
||||
m_simDevice.CreateDouble("position", hal::SimDevice::kInput, 0.0);
|
||||
m_simDistancePerRotation = m_simDevice.CreateDouble(
|
||||
"distance_per_rot", hal::SimDevice::kOutput, 1.0);
|
||||
m_simIsConnected =
|
||||
m_simDevice.CreateBoolean("connected", hal::SimDevice::kInput, true);
|
||||
} else {
|
||||
@@ -101,6 +103,7 @@ units::turn_t DutyCycleEncoder::Get() const {
|
||||
|
||||
void DutyCycleEncoder::SetDistancePerRotation(double distancePerRotation) {
|
||||
m_distancePerRotation = distancePerRotation;
|
||||
m_simDistancePerRotation.Set(distancePerRotation);
|
||||
}
|
||||
|
||||
double DutyCycleEncoder::GetDistancePerRotation() const {
|
||||
|
||||
@@ -18,10 +18,10 @@ using namespace frc::sim;
|
||||
ADXRS450_GyroSim::ADXRS450_GyroSim(const frc::ADXRS450_Gyro& gyro) {
|
||||
wpi::SmallString<128> fullname;
|
||||
wpi::raw_svector_ostream os(fullname);
|
||||
os << "ADXRS450_Gyro" << '[' << gyro.GetPort() << ']';
|
||||
os << "Gyro:ADXRS450" << '[' << gyro.GetPort() << ']';
|
||||
frc::sim::SimDeviceSim deviceSim{fullname.c_str()};
|
||||
m_simAngle = deviceSim.GetDouble("Angle");
|
||||
m_simRate = deviceSim.GetDouble("Rate");
|
||||
m_simAngle = deviceSim.GetDouble("angle_x");
|
||||
m_simRate = deviceSim.GetDouble("rate_x");
|
||||
}
|
||||
|
||||
void ADXRS450_GyroSim::SetAngle(units::degree_t angle) {
|
||||
|
||||
@@ -18,10 +18,11 @@ using namespace frc::sim;
|
||||
DutyCycleEncoderSim::DutyCycleEncoderSim(const frc::DutyCycleEncoder& encoder) {
|
||||
wpi::SmallString<128> fullname;
|
||||
wpi::raw_svector_ostream os(fullname);
|
||||
os << "DutyCycleEncoder" << '[' << encoder.GetFPGAIndex() << ']';
|
||||
os << "DutyCycle:DutyCycleEncoder" << '[' << encoder.GetSourceChannel()
|
||||
<< ']';
|
||||
frc::sim::SimDeviceSim deviceSim{fullname.c_str()};
|
||||
m_simPosition = deviceSim.GetDouble("Position");
|
||||
m_simDistancePerRotation = deviceSim.GetDouble("DistancePerRotation");
|
||||
m_simPosition = deviceSim.GetDouble("position");
|
||||
m_simDistancePerRotation = deviceSim.GetDouble("distance_per_rot");
|
||||
}
|
||||
|
||||
void DutyCycleEncoderSim::Set(units::turn_t turns) {
|
||||
|
||||
@@ -183,6 +183,7 @@ class DutyCycleEncoder : public ErrorBase,
|
||||
|
||||
hal::SimDevice m_simDevice;
|
||||
hal::SimDouble m_simPosition;
|
||||
hal::SimDouble m_simDistancePerRotation;
|
||||
hal::SimBoolean m_simIsConnected;
|
||||
};
|
||||
} // namespace frc
|
||||
|
||||
@@ -72,8 +72,8 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, Sendable
|
||||
m_simDevice = SimDevice.create("Gyro:ADXRS450", port.value);
|
||||
if (m_simDevice != null) {
|
||||
m_simConnected = m_simDevice.createBoolean("connected", SimDevice.Direction.kInput, true);
|
||||
m_simAngle = m_simDevice.createDouble("angle", SimDevice.Direction.kInput, 0.0);
|
||||
m_simRate = m_simDevice.createDouble("rate", SimDevice.Direction.kInput, 0.0);
|
||||
m_simAngle = m_simDevice.createDouble("angle_x", SimDevice.Direction.kInput, 0.0);
|
||||
m_simRate = m_simDevice.createDouble("rate_x", SimDevice.Direction.kInput, 0.0);
|
||||
}
|
||||
|
||||
m_spi.setClockRate(3000000);
|
||||
|
||||
@@ -32,6 +32,7 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
|
||||
protected SimDevice m_simDevice;
|
||||
protected SimDouble m_simPosition;
|
||||
protected SimDouble m_simDistancePerRotation;
|
||||
protected SimBoolean m_simIsConnected;
|
||||
|
||||
/**
|
||||
@@ -72,6 +73,8 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
|
||||
if (m_simDevice != null) {
|
||||
m_simPosition = m_simDevice.createDouble("position", SimDevice.Direction.kInput, 0.0);
|
||||
m_simDistancePerRotation = m_simDevice.createDouble("distance_per_rot",
|
||||
SimDevice.Direction.kOutput, 1.0);
|
||||
m_simIsConnected = m_simDevice.createBoolean("connected", SimDevice.Direction.kInput, true);
|
||||
} else {
|
||||
m_counter = new Counter();
|
||||
|
||||
@@ -24,9 +24,9 @@ public class ADXRS450_GyroSim {
|
||||
* @param gyro ADXRS450_Gyro to simulate
|
||||
*/
|
||||
public ADXRS450_GyroSim(ADXRS450_Gyro gyro) {
|
||||
SimDeviceSim wrappedSimDevice = new SimDeviceSim("ADXRS450_Gyro" + "[" + gyro.getPort() + "]");
|
||||
m_simAngle = wrappedSimDevice.getDouble("Angle");
|
||||
m_simRate = wrappedSimDevice.getDouble("Rate");
|
||||
SimDeviceSim wrappedSimDevice = new SimDeviceSim("Gyro:ADXRS450" + "[" + gyro.getPort() + "]");
|
||||
m_simAngle = wrappedSimDevice.getDouble("angle_x");
|
||||
m_simRate = wrappedSimDevice.getDouble("rate_x");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,9 +23,10 @@ public class DutyCycleEncoderSim {
|
||||
* @param encoder DutyCycleEncoder to simulate
|
||||
*/
|
||||
public DutyCycleEncoderSim(DutyCycleEncoder encoder) {
|
||||
SimDeviceSim wrappedSimDevice = new SimDeviceSim("DutyCycleEncoder" + "[" + encoder.getFPGAIndex() + "]");
|
||||
m_simPosition = wrappedSimDevice.getDouble("Position");
|
||||
m_simDistancePerRotation = wrappedSimDevice.getDouble("DistancePerRotation");
|
||||
SimDeviceSim wrappedSimDevice = new SimDeviceSim("DutyCycle:DutyCycleEncoder" + "["
|
||||
+ encoder.getSourceChannel() + "]");
|
||||
m_simPosition = wrappedSimDevice.getDouble("position");
|
||||
m_simDistancePerRotation = wrappedSimDevice.getDouble("distance_per_rot");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user