Skip to content

Commit

Permalink
Merge pull request #214 from epics-modules/issue213
Browse files Browse the repository at this point in the history
devMotorAsyn.c: Set encoder ratio to 1 if ERES is 0 to avoid dividing by 0.
  • Loading branch information
kmpeters authored Jan 22, 2024
2 parents f8a3239 + 148c943 commit 8166246
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion motorApp/MotorSrc/devMotorAsyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8166246

Please sign in to comment.