From 148c943719b3de41c0d31439185398fcfacd0d22 Mon Sep 17 00:00:00 2001 From: Kevin Peterson Date: Mon, 22 Jan 2024 09:02:27 -0600 Subject: [PATCH] Set encoder ratio to 1 if ERES is 0 to avoid dividing by 0 --- motorApp/MotorSrc/devMotorAsyn.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/motorApp/MotorSrc/devMotorAsyn.c b/motorApp/MotorSrc/devMotorAsyn.c index 79ad5ea88..603f49f8c 100644 --- a/motorApp/MotorSrc/devMotorAsyn.c +++ b/motorApp/MotorSrc/devMotorAsyn.c @@ -174,10 +174,17 @@ static void init_controller(struct motorRecord *pmr, asynUser *pasynUser ) int use_rel = (pmr->rtry != 0 && pmr->rmod != motorRMOD_I && (pmr->ueip || pmr->urip)); int dval_non_zero_pos_near_zero = (fabs(pmr->dval) > rdbd) && (pmr->mres != 0) && (fabs(position * pmr->mres) < rdbd); - epicsFloat64 eratio = pmr->mres / pmr->eres; + epicsFloat64 eratio; int initPos = 0; int status; + /* Don't let the encoder ratio be infinite */ + if (pmr->eres == 0.0) { + eratio = 1.0; + } else { + eratio = pmr->mres / pmr->eres; + } + /* Write encoder ratio to the driver.*/ pPvt->pasynUserSync->reason = pPvt->driverReasons[motorEncRatio]; status = pasynFloat64SyncIO->write(pPvt->pasynUserSync, eratio, pasynUser->timeout);