From 1440fafc7d59ce0280827f65bdabced3f22f9f2a Mon Sep 17 00:00:00 2001 From: smathis Date: Tue, 9 Jun 2026 15:12:22 +0200 Subject: [PATCH] Fixed wrong limits after power cycle --- src/masterMacsAxis.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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