mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[sim] Process WS Encoder reset internally (#2927)
Currently, Encoder.reset() must make a round trip to the sensor and back in order for the count to be updated for the user program. As the sim layer also resets the internal encoder count, this creates a race condition (a WS message with a new count can be "in flight" during a reset and update the count). This changes the WS layer to not put reset on the wire, but instead keep an offset count internal to the robot program. The value on the wire is not reset, but rather all sends and receives are adjusted as necessary to the internal robot count. This approach is straightforward, but does result in the value on the wire not matching the value in the user program. A future improvement will fix this, but this change fixes the immediate race condition problem.
This commit is contained in:
@@ -174,9 +174,9 @@ void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
SimEncoderData[encoder->index].reset = true;
|
||||
SimEncoderData[encoder->index].count = 0;
|
||||
SimEncoderData[encoder->index].period = std::numeric_limits<double>::max();
|
||||
SimEncoderData[encoder->index].reset = true;
|
||||
}
|
||||
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||
auto encoder = encoderHandles->Get(encoderHandle);
|
||||
|
||||
Reference in New Issue
Block a user