From 55fde6b61686a7989c7b4c602b59e7701342fcb0 Mon Sep 17 00:00:00 2001 From: Colby Skeggs Date: Thu, 3 Jul 2014 11:56:19 -0700 Subject: [PATCH] Fixed FRCSim artf2609 - double ports handled wrong. Change-Id: I2dc59c8d3113f3024d237763eb4e2f94bb85ff1a --- wpilibc/wpilibC++Sim/include/Encoder.h | 2 +- wpilibc/wpilibC++Sim/src/Encoder.cpp | 12 +++++++++--- .../java/edu/wpi/first/wpilibj/DoubleSolenoid.java | 6 ++++-- .../src/main/java/edu/wpi/first/wpilibj/Encoder.java | 12 ++++++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/wpilibc/wpilibC++Sim/include/Encoder.h b/wpilibc/wpilibC++Sim/include/Encoder.h index af52aa2dad..560d2a37ad 100644 --- a/wpilibc/wpilibC++Sim/include/Encoder.h +++ b/wpilibc/wpilibC++Sim/include/Encoder.h @@ -70,7 +70,7 @@ private: double m_distancePerPulse; // distance of travel for each encoder tick EncodingType m_encodingType; // Encoding type PIDSourceParameter m_pidSource; // Encoder parameter that sources a PID controller - bool reversed; + bool m_reverseDirection; SimEncoder* impl; ITable *m_table; diff --git a/wpilibc/wpilibC++Sim/src/Encoder.cpp b/wpilibc/wpilibC++Sim/src/Encoder.cpp index 7a1a4f58a4..1e204abd63 100644 --- a/wpilibc/wpilibC++Sim/src/Encoder.cpp +++ b/wpilibc/wpilibC++Sim/src/Encoder.cpp @@ -24,7 +24,6 @@ void Encoder::InitEncoder(int channelA, int channelB, bool reverseDirection, Enc m_table = NULL; this->channelA = channelA; this->channelB = channelB; - reversed = reverseDirection; m_encodingType = encodingType; int32_t index = 0; @@ -37,6 +36,9 @@ void Encoder::InitEncoder(int channelA, int channelB, bool reverseDirection, Enc int channel = channelB; channelB = channelA; channelA = channel; + m_reverseDirection = !reverseDirection; + } else { + m_reverseDirection = reverseDirection; } char buffer[50]; int n = sprintf(buffer, "dio/1/%d/1/%d", channelA, channelB); @@ -288,7 +290,11 @@ void Encoder::SetMinRate(double minRate) */ void Encoder::SetDistancePerPulse(double distancePerPulse) { - m_distancePerPulse = distancePerPulse; + if (m_reverseDirection) { + m_distancePerPulse = -distancePerPulse; + } else { + m_distancePerPulse = distancePerPulse; + } } /** @@ -334,7 +340,7 @@ void Encoder::UpdateTable() { if (m_table != NULL) { m_table->PutNumber("Speed", GetRate()); m_table->PutNumber("Distance", GetDistance()); - m_table->PutNumber("Distance per Tick", m_distancePerPulse); + m_table->PutNumber("Distance per Tick", m_reverseDirection ? -m_distancePerPulse : m_distancePerPulse); } } diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java index f036b29f41..b34e559b61 100644 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java +++ b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java @@ -45,6 +45,7 @@ public class DoubleSolenoid implements LiveWindowSendable { private int m_forwardChannel; ///< The forward channel on the module to control. private int m_reverseChannel; ///< The reverse channel on the module to control. private int m_moduleNumber; + private boolean m_reverseDirection; private SimSpeedController m_impl; private Value m_value; @@ -61,6 +62,7 @@ public class DoubleSolenoid implements LiveWindowSendable { int channel = forwardChannel; forwardChannel = reverseChannel; reverseChannel = channel; + m_reverseDirection = true; } m_impl = new SimSpeedController("simulator/pneumatic/"+moduleNumber+"/"+forwardChannel+"/"+moduleNumber+"/"+reverseChannel); } @@ -103,10 +105,10 @@ public class DoubleSolenoid implements LiveWindowSendable { m_impl.set(0); break; case Value.kForward_val: - m_impl.set(1); + m_impl.set(m_reverseDirection ? -1 : 1); break; case Value.kReverse_val: - m_impl.set(-1); + m_impl.set(m_reverseDirection ? 1 : -1); break; } } diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Encoder.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Encoder.java index edf7737a05..98ae3d7d18 100644 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Encoder.java +++ b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Encoder.java @@ -31,6 +31,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, private boolean m_allocatedA; private boolean m_allocatedB; private boolean m_allocatedI; + private boolean m_reverseDirection; private PIDSourceParameter m_pidSource; private SimEncoder impl; @@ -59,6 +60,9 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, int channel = bChannel; bChannel = aChannel; aChannel = channel; + m_reverseDirection = !reverseDirection; + } else { + m_reverseDirection = reverseDirection; } impl = new SimEncoder("simulator/dio/1/"+aChannel+"/1/"+bChannel); setDistancePerPulse(1); @@ -243,7 +247,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, */ public void setDistancePerPulse(double distancePerPulse) { System.err.println("NOTE|WPILibJSim: Encoder.setDistancePerPulse() assumes 360 pulses per revolution in simulation."); - m_distancePerPulse = distancePerPulse; + if (m_reverseDirection) { + m_distancePerPulse = -distancePerPulse; + } else { + m_distancePerPulse = distancePerPulse; + } } /** @@ -309,7 +317,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, if (m_table != null) { m_table.putNumber("Speed", getRate()); m_table.putNumber("Distance", getDistance()); - m_table.putNumber("Distance per Tick", m_distancePerPulse); + m_table.putNumber("Distance per Tick", m_reverseDirection ? -m_distancePerPulse : m_distancePerPulse); } }