mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Merge "Fixed FRCSim artf2609 - double ports handled wrong."
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user