diff --git a/src/masterMacsAxis.cpp b/src/masterMacsAxis.cpp index e1724da..70967d6 100644 --- a/src/masterMacsAxis.cpp +++ b/src/masterMacsAxis.cpp @@ -793,9 +793,22 @@ asynStatus masterMacsAxis::doPoll(bool *moving) { } } - // Update the enable PV - setAxisParamChecked(this, motorEnableRBV, - readyToBeSwitchedOn() && switchedOn()); + /* + If the motor just got enabled, we need to initialize it, because some + parameters like the limits on the motor controllers are lost during a power + cycle and are rewritten from the masterMacs "meta-controller" when enabling. + */ + int wasEnabled = 0; + int isEnabled = readyToBeSwitchedOn() && switchedOn(); + + getAxisParamChecked(this, motorEnableRBV, &wasEnabled); + if (isEnabled && !wasEnabled) { + rwStatus = init(); + if (rwStatus != asynSuccess) { + return rwStatus; + } + } + setAxisParamChecked(this, motorEnableRBV, isEnabled); if (*moving) { // If the axis is moving, evaluate the movement direction