- Reworked the connection object and the IO system
- Reworked the support for TRICS - Added a second generation motor
This commit is contained in:
649
motor.c
649
motor.c
@ -9,6 +9,10 @@
|
||||
callback added: Mark Koennecke, August 1997
|
||||
endscript facility added: Mark Koennecke, August 2002
|
||||
Modified to support driver parameters, Mark Koennecke, January 2003
|
||||
|
||||
Reworked to allow for multiple implementations of motors on the same
|
||||
interface in preparation for second generation motors.
|
||||
Mark Koennecke, December 2008
|
||||
|
||||
Copyright:
|
||||
|
||||
@ -115,7 +119,71 @@
|
||||
self->stopped = 1;
|
||||
return self->pDriver->Halt((void *)self->pDriver);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
MotorCheckBoundary checks for violation of boundary conditions and
|
||||
transforms from SoftCoordinates to hard coordinates.
|
||||
*/
|
||||
|
||||
static int MotorCheckBoundaryImpl(pMotor self, float fVal, float *fNew,
|
||||
char *pError, int iErrLen)
|
||||
{
|
||||
float fHard;
|
||||
float fZero;
|
||||
char pBueffel[512];
|
||||
|
||||
assert(self);
|
||||
|
||||
/* check for fixed */
|
||||
if(ObVal(self->ParArray,FIX) >= 0)
|
||||
{
|
||||
sprintf(pBueffel,"Motor %s is Fixed",self->name);
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0; /* is this an error? */
|
||||
}
|
||||
|
||||
/* check against software boundaries */
|
||||
if(fVal > ObVal(self->ParArray,SUPP))
|
||||
{
|
||||
sprintf(pBueffel,"%f violates upper software limit %f on %s",
|
||||
fVal, ObVal(self->ParArray,SUPP),self->name);
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0;
|
||||
}
|
||||
if(fVal < ObVal(self->ParArray,SLOW))
|
||||
{
|
||||
sprintf(pBueffel,"%f violates lower software limit %f on %s",
|
||||
fVal,ObVal(self->ParArray,SLOW),self->name );
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* correct for zero point */
|
||||
fZero = ObVal(self->ParArray,SZERO);
|
||||
fZero = -fZero;
|
||||
fHard = fVal - fZero;
|
||||
|
||||
/* apply sign */
|
||||
fHard = fHard*ObVal(self->ParArray,SIGN);
|
||||
|
||||
/* check for hardware limits */
|
||||
if(fHard > self->pDriver->fUpper)
|
||||
{
|
||||
sprintf(pBueffel,"%f violates upper hardware limit %f on %s",
|
||||
fVal,self->pDriver->fUpper,self->name);
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0;
|
||||
}
|
||||
if(fHard < self->pDriver->fLower)
|
||||
{
|
||||
sprintf(pBueffel,"%f violates lower hardware limit %f on %s",
|
||||
fVal,self->pDriver->fLower,self->name);
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*fNew = fHard;
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int MotorLimits(void *sulf, float fVal, char *error, int iErrLen)
|
||||
{
|
||||
@ -126,8 +194,42 @@
|
||||
|
||||
self = (pMotor)sulf;
|
||||
|
||||
return MotorCheckBoundary(self,fVal,&fHard,error,iErrLen);
|
||||
return MotorCheckBoundaryImpl(self,fVal,&fHard,error,iErrLen);
|
||||
}
|
||||
/* ------------------------------------------------------------------------*/
|
||||
static int MotorGetSoftPositionImpl(pMotor self, SConnection *pCon, float *fVal)
|
||||
{
|
||||
int iRet;
|
||||
float fValue;
|
||||
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
/* get the hard position */
|
||||
iRet = MotorGetHardPosition(self,pCon,&fValue);
|
||||
if(!iRet)
|
||||
{
|
||||
*fVal = fValue;
|
||||
return 0;
|
||||
}
|
||||
/* apply zeropoint */
|
||||
if(ObVal(self->ParArray,SIGN) < 0.)
|
||||
{
|
||||
fValue += ObVal(self->ParArray,SZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
fValue -= ObVal(self->ParArray,SZERO);
|
||||
}
|
||||
*fVal = fValue;
|
||||
|
||||
/* apply sign */
|
||||
/* *fVal = MotorHardToSoftPosition(self,fValue); */
|
||||
|
||||
*fVal = fValue*ObVal(self->ParArray,SIGN);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static float MotorGetValue(void *pData, SConnection *pCon)
|
||||
{
|
||||
@ -135,7 +237,7 @@
|
||||
float fVal = 0.;
|
||||
|
||||
assert(pData);
|
||||
iRet = MotorGetSoftPosition((pMotor)pData,pCon,&fVal);
|
||||
iRet = MotorGetSoftPositionImpl((pMotor)pData,pCon,&fVal);
|
||||
if(iRet != OKOK)
|
||||
{
|
||||
fVal = -9999999.99;
|
||||
@ -397,143 +499,22 @@ static void handleMoveCallback(pMotor self, SConnection *pCon)
|
||||
return status;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
pMotor MotorInit(char *drivername, char *name, MotorDriver *pDriv)
|
||||
{
|
||||
pMotor pM = NULL;
|
||||
|
||||
assert(drivername);
|
||||
assert(pDriv);
|
||||
assert(name);
|
||||
|
||||
/* get memory */
|
||||
pM = (pMotor)malloc(sizeof(Motor));
|
||||
if(!pM)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* create and initialize parameters */
|
||||
pM->ParArray = ObParCreate(MOTOBPARLENGTH);
|
||||
if(!pM->ParArray)
|
||||
{
|
||||
free(pM);
|
||||
return NULL;
|
||||
}
|
||||
ObParInit(pM->ParArray,SLOW,"softlowerlim",pDriv->fLower,usUser);
|
||||
ObParInit(pM->ParArray,SUPP,"softupperlim",pDriv->fUpper,usUser);
|
||||
ObParInit(pM->ParArray,SZERO,"softzero",ZEROINACTIVE,usUser);
|
||||
ObParInit(pM->ParArray,FIX,"fixed",-1,usUser);
|
||||
ObParInit(pM->ParArray,INT,"interruptmode",INTCONT,usMugger);
|
||||
ObParInit(pM->ParArray,PREC,"precision",0.01,usMugger);
|
||||
ObParInit(pM->ParArray,USRIGHTS,"accesscode",(float)usUser,usMugger);
|
||||
ObParInit(pM->ParArray,SIGN,"sign",1.0,usMugger);
|
||||
ObParInit(pM->ParArray,ECOUNT,"failafter",3.0,usMugger);
|
||||
ObParInit(pM->ParArray,POSCOUNT,"maxretry",3.0,usMugger);
|
||||
ObParInit(pM->ParArray,IGNOREFAULT,"ignorefault",0.0,usMugger);
|
||||
ObParInit(pM->ParArray,MOVECOUNT,"movecount",10.0,usMugger);
|
||||
pDriv->GetPosition(pDriv,&(pM->fPosition));
|
||||
pM->fTarget = pM->fPosition;
|
||||
pM->endScriptID = 0;
|
||||
|
||||
/* copy arguments */
|
||||
pM->pDriver = pDriv;
|
||||
pM->drivername = strdup(drivername);
|
||||
pM->name = strdup(name);
|
||||
|
||||
|
||||
/* initialise object descriptor */
|
||||
pM->pDescriptor = CreateDescriptor("Motor");
|
||||
if(!pM->pDescriptor)
|
||||
{
|
||||
ObParDelete(pM->ParArray);
|
||||
free(pM);
|
||||
return NULL;
|
||||
}
|
||||
pM->pDescriptor->GetInterface = MotorGetInterface;
|
||||
pM->pDescriptor->SaveStatus = MotorSaveStatus;
|
||||
|
||||
/* initialise Drivable interface */
|
||||
pM->pDrivInt = CreateDrivableInterface();
|
||||
if(!pM->pDrivInt)
|
||||
{
|
||||
DeleteDescriptor(pM->pDescriptor);
|
||||
ObParDelete(pM->ParArray);
|
||||
free(pM);
|
||||
return NULL;
|
||||
}
|
||||
pM->pDrivInt->SetValue = MotorRun;
|
||||
pM->pDrivInt->CheckLimits = MotorLimits;
|
||||
pM->pDrivInt->CheckStatus = MotorStatus;
|
||||
pM->pDrivInt->GetValue = MotorGetValue;
|
||||
pM->pDrivInt->Halt = MotorHalt;
|
||||
|
||||
/* initialise callback interface */
|
||||
pM->pCall = CreateCallBackInterface();
|
||||
if(!pM->pCall)
|
||||
{
|
||||
MotorKill(pM);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* done */
|
||||
return pM;
|
||||
}
|
||||
int MotorGetPar(pMotor self, char *name, float *fVal)
|
||||
{
|
||||
return self->MotorGetPar(self,name,fVal);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int MotorSetPar(pMotor self, SConnection *pCon, char *name, float fVal)
|
||||
{
|
||||
return self->MotorSetPar(self,pCon,name,fVal);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int MotorGetHardPosition(pMotor self,SConnection *pCon, float *fVal)
|
||||
{
|
||||
return self->MotorGetHardPosition(self, pCon, fVal);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
extern void KillPiPiezo(void *pData);
|
||||
|
||||
void MotorKill(void *self)
|
||||
{
|
||||
pMotor pM;
|
||||
assert(self);
|
||||
|
||||
pM = (pMotor)self;
|
||||
|
||||
/* MotorHalt(pM); */
|
||||
|
||||
if(pM->name)
|
||||
free(pM->name);
|
||||
|
||||
if(pM->pDrivInt)
|
||||
{
|
||||
free(pM->pDrivInt);
|
||||
}
|
||||
|
||||
if(pM->pCall)
|
||||
{
|
||||
DeleteCallBackInterface(pM->pCall);
|
||||
}
|
||||
|
||||
/* kill driver */
|
||||
if(pM->drivername)
|
||||
{
|
||||
if(pM->pDriver->KillPrivate != NULL)
|
||||
{
|
||||
pM->pDriver->KillPrivate(pM->pDriver);
|
||||
if(pM->pDriver->name != NULL)
|
||||
{
|
||||
free(pM->pDriver->name);
|
||||
}
|
||||
free(pM->pDriver);
|
||||
}
|
||||
free(pM->drivername);
|
||||
}
|
||||
|
||||
/* get rid of parameter space */
|
||||
if(pM->ParArray)
|
||||
{
|
||||
ObParDelete(pM->ParArray);
|
||||
}
|
||||
|
||||
/* kill Descriptor */
|
||||
DeleteDescriptor(pM->pDescriptor);
|
||||
|
||||
free(pM);
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int MotorGetPar(pMotor self, char *name, float *fVal)
|
||||
static int MotorGetParImpl(pMotor self, char *name, float *fVal)
|
||||
{
|
||||
ObPar *pPar = NULL;
|
||||
assert(self);
|
||||
@ -585,7 +566,7 @@ extern void KillPiPiezo(void *pData);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int MotorSetPar(pMotor self, SConnection *pCon, char *name, float fVal)
|
||||
static int MotorSetParImpl(pMotor self, SConnection *pCon, char *name, float fVal)
|
||||
{
|
||||
ObPar *pPar = NULL;
|
||||
char pBueffel[512];
|
||||
@ -657,73 +638,61 @@ extern void KillPiPiezo(void *pData);
|
||||
|
||||
return iRet;
|
||||
}
|
||||
/*---------------------------------------------------------------------------
|
||||
MotorCheckBoundary checks for violation of boundary conditions and
|
||||
transforms from SoftCoordinates to hard coordinates.
|
||||
*/
|
||||
|
||||
int MotorCheckBoundary(pMotor self, float fVal, float *fNew,
|
||||
char *pError, int iErrLen)
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int MotorGetHardPositionImpl(pMotor self,SConnection *pCon, float *fHard)
|
||||
{
|
||||
float fHard;
|
||||
float fZero;
|
||||
char pBueffel[512];
|
||||
int iRet, iCode;
|
||||
float fVal;
|
||||
char pBueffel[512],pError[256];
|
||||
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
assert(self);
|
||||
|
||||
/* check for fixed */
|
||||
if(ObVal(self->ParArray,FIX) >= 0)
|
||||
iRet = self->pDriver->GetPosition(self->pDriver,&fVal);
|
||||
if(iRet == OKOK) /* all went well, the exception */
|
||||
{
|
||||
sprintf(pBueffel,"Motor %s is Fixed",self->name);
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0; /* is this an error? */
|
||||
*fHard = fVal;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check against software boundaries */
|
||||
if(fVal > ObVal(self->ParArray,SUPP))
|
||||
{
|
||||
sprintf(pBueffel,"%f violates upper software limit %f on %s",
|
||||
fVal, ObVal(self->ParArray,SUPP),self->name);
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0;
|
||||
else /* a problem, the usual case: try fix the problem */
|
||||
{ /* no point in trying this three times */
|
||||
self->pDriver->GetError(self->pDriver,&iCode, pError,255);
|
||||
iRet = self->pDriver->TryAndFixIt(self->pDriver,iCode, fVal);
|
||||
sprintf(pBueffel,"WARNING: Trying to fix %s",pError);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
switch(iRet)
|
||||
{
|
||||
case MOTFAIL:
|
||||
sprintf(pBueffel,"ERROR: cannot fix motor %s",
|
||||
self->name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
SCSetInterrupt(pCon,(int)ObVal(self->ParArray,INT));
|
||||
*fHard = fVal;
|
||||
return 0;
|
||||
case MOTOK:
|
||||
case MOTREDO:
|
||||
iRet = self->pDriver->GetPosition(self->pDriver,&fVal);
|
||||
if(iRet)
|
||||
{
|
||||
*fHard = fVal*ObVal(self->ParArray,SIGN);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: cannot fix motor %s",
|
||||
self->name);
|
||||
SCSetInterrupt(pCon,(int)ObVal(self->ParArray,INT));
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
*fHard = fVal;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fVal < ObVal(self->ParArray,SLOW))
|
||||
{
|
||||
sprintf(pBueffel,"%f violates lower software limit %f on %s",
|
||||
fVal,ObVal(self->ParArray,SLOW),self->name );
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* correct for zero point */
|
||||
fZero = ObVal(self->ParArray,SZERO);
|
||||
fZero = -fZero;
|
||||
fHard = fVal - fZero;
|
||||
|
||||
/* apply sign */
|
||||
fHard = fHard*ObVal(self->ParArray,SIGN);
|
||||
|
||||
/* check for hardware limits */
|
||||
if(fHard > self->pDriver->fUpper)
|
||||
{
|
||||
sprintf(pBueffel,"%f violates upper hardware limit %f on %s",
|
||||
fVal,self->pDriver->fUpper,self->name);
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0;
|
||||
}
|
||||
if(fHard < self->pDriver->fLower)
|
||||
{
|
||||
sprintf(pBueffel,"%f violates lower hardware limit %f on %s",
|
||||
fVal,self->pDriver->fLower,self->name);
|
||||
strncpy(pError,pBueffel,iErrLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*fNew = fHard;
|
||||
return 1;
|
||||
}
|
||||
*fHard = fVal*ObVal(self->ParArray,SIGN);
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
long MotorRun(void *sulf, SConnection *pCon, float fNew)
|
||||
static long MotorRunImpl(void *sulf, SConnection *pCon, float fNew)
|
||||
{
|
||||
float fHard;
|
||||
int i, iRet, iCode;
|
||||
@ -748,7 +717,7 @@ extern void KillPiPiezo(void *pData);
|
||||
}
|
||||
|
||||
/* check boundaries first */
|
||||
iRet = MotorCheckBoundary(self,fNew,&fHard,pError,131);
|
||||
iRet = MotorCheckBoundaryImpl(self,fNew,&fHard,pError,131);
|
||||
if(!iRet)
|
||||
{
|
||||
snprintf(pBueffel,511,"ERROR: %s",pError);
|
||||
@ -824,59 +793,171 @@ extern void KillPiPiezo(void *pData);
|
||||
}
|
||||
return OKOK;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int MotorGetHardPosition(pMotor self,SConnection *pCon, float *fHard)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
pMotor MotorInit(char *drivername, char *name, MotorDriver *pDriv)
|
||||
{
|
||||
int iRet, iCode;
|
||||
float fVal;
|
||||
char pBueffel[512],pError[256];
|
||||
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
iRet = self->pDriver->GetPosition(self->pDriver,&fVal);
|
||||
if(iRet == OKOK) /* all went well, the exception */
|
||||
pMotor pM = NULL;
|
||||
|
||||
assert(drivername);
|
||||
assert(pDriv);
|
||||
assert(name);
|
||||
|
||||
/* get memory */
|
||||
pM = (pMotor)malloc(sizeof(Motor));
|
||||
if(!pM)
|
||||
{
|
||||
*fHard = fVal;
|
||||
return 1;
|
||||
return NULL;
|
||||
}
|
||||
else /* a problem, the usual case: try fix the problem */
|
||||
{ /* no point in trying this three times */
|
||||
self->pDriver->GetError(self->pDriver,&iCode, pError,255);
|
||||
iRet = self->pDriver->TryAndFixIt(self->pDriver,iCode, fVal);
|
||||
sprintf(pBueffel,"WARNING: Trying to fix %s",pError);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
switch(iRet)
|
||||
|
||||
|
||||
/* create and initialize parameters */
|
||||
pM->ParArray = ObParCreate(MOTOBPARLENGTH);
|
||||
if(!pM->ParArray)
|
||||
{
|
||||
free(pM);
|
||||
return NULL;
|
||||
}
|
||||
ObParInit(pM->ParArray,SLOW,"softlowerlim",pDriv->fLower,usUser);
|
||||
ObParInit(pM->ParArray,SUPP,"softupperlim",pDriv->fUpper,usUser);
|
||||
ObParInit(pM->ParArray,SZERO,"softzero",ZEROINACTIVE,usUser);
|
||||
ObParInit(pM->ParArray,FIX,"fixed",-1,usUser);
|
||||
ObParInit(pM->ParArray,INT,"interruptmode",INTCONT,usMugger);
|
||||
ObParInit(pM->ParArray,PREC,"precision",0.01,usMugger);
|
||||
ObParInit(pM->ParArray,USRIGHTS,"accesscode",(float)usUser,usMugger);
|
||||
ObParInit(pM->ParArray,SIGN,"sign",1.0,usMugger);
|
||||
ObParInit(pM->ParArray,ECOUNT,"failafter",3.0,usMugger);
|
||||
ObParInit(pM->ParArray,POSCOUNT,"maxretry",3.0,usMugger);
|
||||
ObParInit(pM->ParArray,IGNOREFAULT,"ignorefault",0.0,usMugger);
|
||||
ObParInit(pM->ParArray,MOVECOUNT,"movecount",10.0,usMugger);
|
||||
pDriv->GetPosition(pDriv,&(pM->fPosition));
|
||||
pM->fTarget = pM->fPosition;
|
||||
pM->endScriptID = 0;
|
||||
|
||||
/* copy arguments */
|
||||
pM->pDriver = pDriv;
|
||||
pM->drivername = strdup(drivername);
|
||||
pM->name = strdup(name);
|
||||
|
||||
|
||||
/* initialise object descriptor */
|
||||
pM->pDescriptor = CreateDescriptor("Motor");
|
||||
if(!pM->pDescriptor)
|
||||
{
|
||||
ObParDelete(pM->ParArray);
|
||||
free(pM);
|
||||
return NULL;
|
||||
}
|
||||
pM->pDescriptor->GetInterface = MotorGetInterface;
|
||||
pM->pDescriptor->SaveStatus = MotorSaveStatus;
|
||||
|
||||
/* initialise Drivable interface */
|
||||
pM->pDrivInt = CreateDrivableInterface();
|
||||
if(!pM->pDrivInt)
|
||||
{
|
||||
DeleteDescriptor(pM->pDescriptor);
|
||||
ObParDelete(pM->ParArray);
|
||||
free(pM);
|
||||
return NULL;
|
||||
}
|
||||
pM->pDrivInt->SetValue = MotorRunImpl;
|
||||
pM->pDrivInt->CheckLimits = MotorLimits;
|
||||
pM->pDrivInt->CheckStatus = MotorStatus;
|
||||
pM->pDrivInt->GetValue = MotorGetValue;
|
||||
pM->pDrivInt->Halt = MotorHalt;
|
||||
|
||||
/* initialize function pointers */
|
||||
pM->MotorGetPar = MotorGetParImpl;
|
||||
pM->MotorSetPar = MotorSetParImpl;
|
||||
pM->MotorGetHardPosition = MotorGetHardPositionImpl;
|
||||
|
||||
/* initialise callback interface */
|
||||
pM->pCall = CreateCallBackInterface();
|
||||
if(!pM->pCall)
|
||||
{
|
||||
MotorKill(pM);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* done */
|
||||
return pM;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
long MotorRun(void *data, SConnection *pCon, float fNew)
|
||||
{
|
||||
pMotor self = (pMotor)data;
|
||||
|
||||
return self->pDrivInt->SetValue(data,pCon,fNew);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int MotorCheckBoundary(pMotor self, float fVal, float *fHard,
|
||||
char *error, int iErrLen)
|
||||
{
|
||||
return self->pDrivInt->CheckLimits(self,fVal,error,iErrLen);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int MotorGetSoftPosition(pMotor self,SConnection *pCon, float *fVal)
|
||||
{
|
||||
float myVal;
|
||||
myVal = self->pDrivInt->GetValue(self,pCon);
|
||||
*fVal = myVal;
|
||||
if(myVal <= -9999999.99){
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
extern void KillPiPiezo(void *pData);
|
||||
|
||||
void MotorKill(void *self)
|
||||
{
|
||||
pMotor pM;
|
||||
assert(self);
|
||||
|
||||
pM = (pMotor)self;
|
||||
|
||||
/* MotorHalt(pM); */
|
||||
|
||||
if(pM->name)
|
||||
free(pM->name);
|
||||
|
||||
if(pM->pDrivInt)
|
||||
{
|
||||
free(pM->pDrivInt);
|
||||
}
|
||||
|
||||
if(pM->pCall)
|
||||
{
|
||||
DeleteCallBackInterface(pM->pCall);
|
||||
}
|
||||
|
||||
/* kill driver */
|
||||
if(pM->drivername)
|
||||
{
|
||||
if(pM->pDriver->KillPrivate != NULL)
|
||||
{
|
||||
case MOTFAIL:
|
||||
sprintf(pBueffel,"ERROR: cannot fix motor %s",
|
||||
self->name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
SCSetInterrupt(pCon,(int)ObVal(self->ParArray,INT));
|
||||
*fHard = fVal;
|
||||
return 0;
|
||||
case MOTOK:
|
||||
case MOTREDO:
|
||||
iRet = self->pDriver->GetPosition(self->pDriver,&fVal);
|
||||
if(iRet)
|
||||
{
|
||||
*fHard = fVal*ObVal(self->ParArray,SIGN);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: cannot fix motor %s",
|
||||
self->name);
|
||||
SCSetInterrupt(pCon,(int)ObVal(self->ParArray,INT));
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
*fHard = fVal;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*fHard = fVal*ObVal(self->ParArray,SIGN);
|
||||
return 0;
|
||||
}
|
||||
pM->pDriver->KillPrivate(pM->pDriver);
|
||||
if(pM->pDriver->name != NULL)
|
||||
{
|
||||
free(pM->pDriver->name);
|
||||
}
|
||||
free(pM->pDriver);
|
||||
}
|
||||
free(pM->drivername);
|
||||
}
|
||||
|
||||
/* get rid of parameter space */
|
||||
if(pM->ParArray)
|
||||
{
|
||||
ObParDelete(pM->ParArray);
|
||||
}
|
||||
|
||||
/* kill Descriptor */
|
||||
DeleteDescriptor(pM->pDescriptor);
|
||||
|
||||
free(pM);
|
||||
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
float MotorHardToSoftPosition(pMotor self, float fValue)
|
||||
{
|
||||
@ -892,40 +973,6 @@ extern void KillPiPiezo(void *pData);
|
||||
/* apply sign */
|
||||
return fValue*ObVal(self->ParArray,SIGN);
|
||||
}
|
||||
/* ------------------------------------------------------------------------*/
|
||||
int MotorGetSoftPosition(pMotor self, SConnection *pCon, float *fVal)
|
||||
{
|
||||
int iRet;
|
||||
float fValue;
|
||||
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
/* get the hard position */
|
||||
iRet = MotorGetHardPosition(self,pCon,&fValue);
|
||||
if(!iRet)
|
||||
{
|
||||
*fVal = fValue;
|
||||
return 0;
|
||||
}
|
||||
/* apply zeropoint */
|
||||
if(ObVal(self->ParArray,SIGN) < 0.)
|
||||
{
|
||||
fValue += ObVal(self->ParArray,SZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
fValue -= ObVal(self->ParArray,SZERO);
|
||||
}
|
||||
*fVal = fValue;
|
||||
|
||||
/* apply sign */
|
||||
/* *fVal = MotorHardToSoftPosition(self,fValue); */
|
||||
|
||||
*fVal = fValue*ObVal(self->ParArray,SIGN);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int MotorCheckPosition(void *sulf, SConnection *pCon)
|
||||
{
|
||||
@ -1079,9 +1126,9 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
|
||||
sprintf(pBueffel,"Parameter Listing for motor %s",self->name);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
sprintf(pBueffel,"%s.Position = %f\n", self->name,self->fPosition);
|
||||
SCWrite(pCon,pBueffel,eStatus);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
sprintf(pBueffel,"%s.TargetPosition = %f\n", self->name,self->fTarget);
|
||||
SCWrite(pCon,pBueffel,eStatus);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
|
||||
snprintf(pBueffel,511,"%s.hardlowerlim = %f",self->name,
|
||||
self->pDriver->fLower);
|
||||
@ -1093,7 +1140,7 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
|
||||
{
|
||||
sprintf(pBueffel,"%s.%s = %f\n",self->name,
|
||||
self->ParArray[i].name,self->ParArray[i].fVal);
|
||||
SCWrite(pCon,pBueffel,eStatus);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1129,11 +1176,14 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
|
||||
{
|
||||
free(self->pName);
|
||||
}
|
||||
if(self->pCon != NULL)
|
||||
{
|
||||
SCDeleteConnection(self->pCon);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
/*------------------- The CallBack function for interest ------------------*/
|
||||
static int InterestCallback(int iEvent, void *pEvent, void *pUser,
|
||||
commandContext cc)
|
||||
static int InterestCallback(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
pMotInfo pInfo = NULL;
|
||||
char pBueffel[80];
|
||||
@ -1145,11 +1195,15 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
|
||||
psCall = (MotCallback *)pEvent;
|
||||
pInfo = (MotInfo *)pUser;
|
||||
|
||||
if(!SCisConnected(pInfo->pCon)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pInfo->lastValue != psCall->fVal) {
|
||||
pInfo->lastValue = psCall->fVal;
|
||||
(pInfo->pCon)->conEventType=POSITION;
|
||||
sprintf(pBueffel,"%s.position = %f ", pInfo->pName, pInfo->lastValue);
|
||||
SCWriteInContext(pInfo->pCon,pBueffel,eEvent,cc);
|
||||
SCWrite(pInfo->pCon,pBueffel,eEvent);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -1162,8 +1216,7 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
|
||||
}
|
||||
}
|
||||
/*------------------------ The endscript callback function ----------------*/
|
||||
static int EndScriptCallback(int iEvent, void *pEvent, void *pUser,
|
||||
commandContext cc)
|
||||
static int EndScriptCallback(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
char *pScript = NULL;
|
||||
MotCallback *psCall;
|
||||
@ -1269,7 +1322,7 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
|
||||
return 0;
|
||||
}
|
||||
pMoti->pName = strdup(argv[0]);
|
||||
pMoti->pCon = pCon;
|
||||
pMoti->pCon = SCCopyConnection(pCon);
|
||||
iRet = MotorGetSoftPosition(self,pCon,&fValue);
|
||||
if(!iRet)
|
||||
{
|
||||
@ -1280,16 +1333,15 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
|
||||
}
|
||||
pMoti->lastValue = fValue;
|
||||
|
||||
lID = RegisterCallback(self->pCall, SCGetContext(pCon),MOTDRIVE, InterestCallback,
|
||||
lID = RegisterCallback(self->pCall, MOTDRIVE, InterestCallback,
|
||||
pMoti, KillInfo);
|
||||
SCRegister(pCon,pSics, self->pCall,lID);
|
||||
DeleteTokenList(pList);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(pCurrent->text,"uninterest") == 0)
|
||||
{
|
||||
RemoveCallback2(self->pCall,pCon);
|
||||
RemoveCallbackCon(self->pCall,pCon);
|
||||
SCSendOK(pCon);
|
||||
DeleteTokenList(pList);
|
||||
return 1;
|
||||
@ -1312,9 +1364,8 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray);
|
||||
return 0;
|
||||
}
|
||||
self->endScriptID =
|
||||
RegisterCallback(self->pCall, SCGetContext(pCon),MOTEND, EndScriptCallback,
|
||||
RegisterCallback(self->pCall, MOTEND, EndScriptCallback,
|
||||
strdup(pCurrent->text), KillScript);
|
||||
SCRegister(pCon,pSics, self->pCall,self->endScriptID);
|
||||
DeleteTokenList(pList);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user