diff --git a/src/sinqAxis.cpp b/src/sinqAxis.cpp index f1afe04..accce7e 100644 --- a/src/sinqAxis.cpp +++ b/src/sinqAxis.cpp @@ -493,6 +493,31 @@ asynStatus sinqAxis::setMotorPosition(double motorPos) { return status; } +asynStatus sinqAxis::setLimits(double highLimit, double lowLimit) { + asynStatus status = asynSuccess; + + if (highLimit < lowLimit) { + double motorPos; + double motorRecRes; + status = motorPosition(&motorPos); + if (status != asynSuccess) { + return status; + } + getAxisParamChecked(this, motorRecResolution, &motorRecRes); + + // This is a safe fallback + setAxisParamChecked(this, motorHighLimitFromDriver, + motorPos + motorRecRes); + setAxisParamChecked(this, motorLowLimitFromDriver, + motorPos - motorRecRes); + } else { + setAxisParamChecked(this, motorHighLimitFromDriver, highLimit); + setAxisParamChecked(this, motorLowLimitFromDriver, lowLimit); + } + + return status; +} + asynStatus sinqAxis::assertConnected() { int connected = 0; getAxisParamChecked(this, motorConnected, &connected); diff --git a/src/sinqAxis.h b/src/sinqAxis.h index 212334f..33588c1 100644 --- a/src/sinqAxis.h +++ b/src/sinqAxis.h @@ -391,6 +391,20 @@ class HIDDEN sinqAxis : public asynMotorAxis { */ asynStatus setMotorPosition(double motorPosition); + /** + * @brief Sanity-check the limits and write them into the database + * + * If the given `highLimit` is smaller than the `lowLimit`, the limits are + * set to `highLimit = motorPosition + motorRecResolution`, + * `lowLimit = motorPosition - motorRecResolution` and a warning is + * displayed in the IOC shell. This is not an error + * + * @param highLimit + * @param lowLimit + * @return asynStatus + */ + asynStatus setLimits(double highLimit, double lowLimit); + /** * @brief Check if the axis is not connected and print a corresponding error * message