Guard against race condition with targetReached
This commit is contained in:
+10
-4
@@ -532,9 +532,9 @@ asynStatus masterMacsAxis::doPoll(bool *moving) {
|
||||
|
||||
} else {
|
||||
|
||||
// If we wait for a handshake, but the motor was moving in its last poll
|
||||
// cycle and has reached its target, it is not moving. Otherwise it is
|
||||
// considered moving, even if we're still waiting for the handshake.
|
||||
// If the motor hasn't moved after being enabled, we cannot trust
|
||||
// targetReached. Hence, the targetReachedUninitialized flag guards
|
||||
// against invalid detection of the "moving" status.
|
||||
if (pMasterMacsA_->targetReachedUninitialized) {
|
||||
*moving = false;
|
||||
} else {
|
||||
@@ -545,7 +545,13 @@ asynStatus masterMacsAxis::doPoll(bool *moving) {
|
||||
}
|
||||
}
|
||||
|
||||
if (targetReached()) {
|
||||
// If the motor is not switched on, the targetReached bit is set to
|
||||
// true. targetReachedUninitialized is set to true in the enable
|
||||
// function, which is in a separate thread than doPoll. Therefore,
|
||||
// doPoll can reset targetReachedUninitialized, which then can lead to
|
||||
// a false "moving" status. Therefore, we only trust targetReached if
|
||||
// the motor is switched on.
|
||||
if (targetReached() && switchedOn()) {
|
||||
pMasterMacsA_->targetReachedUninitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user