Skip to content

Commit

Permalink
[sim] Fix ADXRS450_GyroSim and DutyCycleEncoderSim (#2963)
Browse files Browse the repository at this point in the history
These were broken by #2952.

Also fix Java ADXRS450_Gyro angle/rate SimValue names.
  • Loading branch information
PeterJohnson authored Dec 24, 2020
1 parent 240c629 commit a8bb2ef
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
3 changes: 3 additions & 0 deletions wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions wpilibc/src/main/native/cpp/simulation/ADXRS450_GyroSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions wpilibc/src/main/native/include/frc/DutyCycleEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public ADXRS450_Gyro(SPI.Port port) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -72,6 +73,8 @@ private void init() {

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down

0 comments on commit a8bb2ef

Please sign in to comment.