From a6cfbe8b7f2f56d67f98547c5553ddb840e78736 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Sat, 27 Apr 2013 18:16:30 +1000 Subject: [PATCH] SICS-597: Don't drive a motor if it is within precision of the target. --- motor.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/motor.c b/motor.c index 57175954..b4452f03 100644 --- a/motor.c +++ b/motor.c @@ -689,8 +689,8 @@ static int MotorGetHardPositionImpl(pMotor self, SConnection * pCon, /*---------------------------------------------------------------------------*/ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew) { - float fHard; - int i, iRet, iCode; + float fHard, fCurrHard, fNewHard, fZero; + int i, iRet, iCode, iSign; char pBueffel[512]; char pError[132]; pMotor self; @@ -709,6 +709,13 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew) SCSetInterrupt(pCon, eAbortBatch); return 0; } + self->pDriver->GetPosition(self->pDriver, &fCurrHard); + iSign = ObVal(self->ParArray, SIGN); + fZero = ObVal(self->ParArray, SZERO); + fNewHard = iSign * (fNew + fZero); + if (absf(fCurrHard - fNewHard) <= ObVal(self->ParArray, PREC)) { + return OKOK; + } /* check boundaries first */ iRet = MotorCheckBoundaryImpl(self, fNew, &fHard, pError, 131);