imporved simulation driver M.Z.

This commit is contained in:
cvs
2004-11-17 11:26:26 +00:00
parent 4e06a17518
commit f2a10df78b
2 changed files with 25 additions and 21 deletions

View File

@ -61,11 +61,25 @@
/*---------------------------------------------------------------------------*/
static int RunComplete(SIMDriv *self)
{
time_t tD;
if(time(&tD) > self->iTime)
{
int sign;
time_t now;
if (self->iTime == 0) {
return 1;
}
now=time(NULL);
/* move */
if (self->fTarget > self->fPos) {
sign=1;
} else {
sign=-1;
}
self->fPos += sign * self->fSpeed * (now - self->iTime);
self->iTime = now;
if (sign*(self->fPos - self->fTarget) > 0) {
self->fPos = self->fTarget;
return 1;
}
return 0;
}
/*----------------------------------------------------------------------------*/
@ -91,23 +105,13 @@
return HWFault;
}
if(RunComplete(pDriv))
{
*fPos = pDriv->fPos;
}
else /* simulate a mispositioned motor */
{
*fPos = pDriv->fPos - 1.;
return OKOK;
}
*fPos = pDriv->fPos;
return OKOK;
}
/*----------------------------------------------------------------------------*/
static int SimRun(void *self, float fVal)
{
SIMDriv *pDriv;
float fDiff;
time_t tD;
assert(self);
pDriv = (SIMDriv *)self;
@ -122,10 +126,9 @@
}
/* calculate time for completion */
fDiff = fVal - pDriv->fPos;
if(fDiff < .0) fDiff = -fDiff;
pDriv->iTime = time(&tD) + (long)(fDiff/pDriv->fSpeed);
/* set start time */
pDriv->fTarget = fVal;
pDriv->iTime = time(NULL);
/* in a fifth the failures, simply die, else simply do not find pos */
if(SimRandom() < (pDriv->fFailure/5))
@ -139,7 +142,7 @@
}
else
{
pDriv->fPos = fVal;
/* pDriv->fPos = fVal; */
return OKOK;
}
}
@ -350,7 +353,8 @@ static int SimSetPar(void *self, SConnection *pCon, char *name, float newValue)
/* calculate current position, initialise func pters */
pDriv->fPos = (pDriv->fUpper - pDriv->fLower)/2.;
pDriv->fPos = (pDriv->fUpper + pDriv->fLower)/2.;
pDriv->fTarget = pDriv->fPos;
pDriv->name = strdup("Simulant");
pDriv->GetPosition = GetSimPos;
pDriv->RunTo = SimRun;