- Improvements to the chooper driver for the SANS2 chopper
- Fixes to the new counter and motor drivers - Updated Linux makefiles to linux_def
This commit is contained in:
86
dornier2.c
86
dornier2.c
@ -41,6 +41,8 @@ typedef struct __VelSelDriv *pVelSelDriv;
|
||||
/*--------- special Dornier conditions*/
|
||||
#define STARTED -88
|
||||
#define HALTREQ -77
|
||||
#define INVALIDSTATUS -7000
|
||||
#define TARGETREJECTED -7001
|
||||
|
||||
/*---------- DORNIER status modes */
|
||||
#define STATSEND 1
|
||||
@ -58,6 +60,7 @@ typedef struct __VelSelDriv *pVelSelDriv;
|
||||
DornierStatus lastStatus;
|
||||
int minRPM; /* the minimum control speed of the thing*/
|
||||
int haltCount;
|
||||
int rejectCount;
|
||||
} Dornier, *pDornier;
|
||||
/*------------------------------------------------------------------*/
|
||||
static int requestDornierStatus(pDornier pDorn){
|
||||
@ -81,10 +84,24 @@ static int readAndInterpretStatus(pDornier pDorn, DornierStatus *DStatus){
|
||||
pDorn->iLastError = status;
|
||||
return 0;
|
||||
}
|
||||
if(strlen(reply) < 80){
|
||||
pDorn->iLastError = INVALIDSTATUS;
|
||||
pDorn->statusMode = STATSEND;
|
||||
return 0;
|
||||
}
|
||||
|
||||
DecodeNewDornierStatus(reply,DStatus);
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------*/
|
||||
static int takeControl(pDornier pDorn){
|
||||
int iRet;
|
||||
char pError[80];
|
||||
setRS232ReplyTerminator(pDorn->controller,"\\");
|
||||
iRet = transactRS232(pDorn->controller,"REM\n",4,pError,79);
|
||||
setRS232ReplyTerminator(pDorn->controller,"\r\n");
|
||||
return iRet;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int GetDornierPos(pVelSelDriv self, float *fPos)
|
||||
{
|
||||
@ -146,33 +163,42 @@ static int readAndInterpretStatus(pDornier pDorn, DornierStatus *DStatus){
|
||||
less then minRPM, means halt in this case.
|
||||
Accept this only after three times, see code in GetError as well.
|
||||
*/
|
||||
if(fVal < pDorn->minRPM - self->fTolerance)
|
||||
if(fVal < 0){
|
||||
fVal = - fVal;
|
||||
}
|
||||
memset(pCommand,0,50);
|
||||
pDorn->rejectCount = 0;
|
||||
if(fVal < pDorn->minRPM - 3*self->fTolerance)
|
||||
{
|
||||
if(pDorn->haltCount < 3){
|
||||
pDorn->iLastError = HALTREQ;
|
||||
return 0;
|
||||
}
|
||||
strcpy(pCommand,"HAL\n");
|
||||
setRS232ReplyTerminator(pDorn->controller,"\\");
|
||||
} else {
|
||||
if(pDorn->lastStatus.cur_rpm < pDorn->minRPM){
|
||||
strcpy(pCommand,"SST\n");
|
||||
setRS232ReplyTerminator(pDorn->controller,"\\");
|
||||
startFlag = 1;
|
||||
pDorn->fTarget = pDorn->minRPM;
|
||||
} else {
|
||||
snprintf(pCommand,49,"SDR %5u\n",(int)nintf(fVal));
|
||||
pDorn->fTarget = fVal;
|
||||
sprintf(pCommand,"SDR %d\n",(int)fVal);
|
||||
}
|
||||
}
|
||||
|
||||
setRS232ReplyTerminator(pDorn->controller,"\\");
|
||||
pDorn->fTarget = fVal;
|
||||
iRet = transactRS232(pDorn->controller,pCommand,strlen(pCommand),
|
||||
pAnswer,49);
|
||||
setRS232ReplyTerminator(pDorn->controller,"\r\n");
|
||||
if(iRet != 1)
|
||||
{
|
||||
if(iRet != INCOMPLETE){
|
||||
|
||||
pDorn->iLastError = iRet;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
pDorn->statusMode = STATSEND;
|
||||
if(startFlag){
|
||||
pDorn->iLastError = STARTED;
|
||||
@ -201,6 +227,12 @@ static int DornierError(pVelSelDriv self, int *iCode,
|
||||
"Started selector, standby and check manually when ready",
|
||||
iErrLen);
|
||||
break;
|
||||
case INVALIDSTATUS:
|
||||
strncpy(error,"Received invalid status reply",iErrLen);
|
||||
break;
|
||||
case TARGETREJECTED:
|
||||
strncpy(error,"VS in local mode or target out of range", iErrLen);
|
||||
break;
|
||||
default:
|
||||
getRS232Error(pDorn->iLastError,error,iErrLen);
|
||||
break;
|
||||
@ -210,7 +242,7 @@ static int DornierError(pVelSelDriv self, int *iCode,
|
||||
/*-------------------------------------------------------------------*/
|
||||
static int DornierFixIt(pVelSelDriv self, int iCode){
|
||||
pDornier pDorn = NULL;
|
||||
int status;
|
||||
int status, oldReject;
|
||||
|
||||
assert(self);
|
||||
pDorn = (pDornier)self->pPrivate;
|
||||
@ -226,8 +258,23 @@ static int DornierFixIt(pVelSelDriv self, int iCode){
|
||||
break;
|
||||
case TIMEOUT:
|
||||
case INCOMPLETE:
|
||||
case INVALIDSTATUS:
|
||||
return VELOREDO;
|
||||
break;
|
||||
case TARGETREJECTED:
|
||||
if(pDorn->rejectCount >= 1){
|
||||
pDorn->rejectCount = 0;
|
||||
return VELOFAIL;
|
||||
}
|
||||
oldReject = pDorn->rejectCount;
|
||||
status = takeControl(pDorn);
|
||||
if(status == 1){
|
||||
DornierRun(self,pDorn->fTarget);
|
||||
pDorn->rejectCount = oldReject + 1;
|
||||
return VELOREDO;
|
||||
}
|
||||
return VELOFAIL;
|
||||
break;
|
||||
default:
|
||||
return VELOFAIL;
|
||||
}
|
||||
@ -262,6 +309,21 @@ static int evaluateStatus(pVelSelDriv self, int *iCode){
|
||||
}
|
||||
|
||||
*iCode = ROTMOVE;
|
||||
|
||||
/*
|
||||
sometimes the velocity selector does not accept a new target:
|
||||
Two reasons: a) it is local, b) out of range
|
||||
Check for this here as it is the only place appropriate.
|
||||
*/
|
||||
fDelta = sStatus.nom_rpm - pDorn->fTarget;
|
||||
if(fDelta < 0){
|
||||
fDelta = - fDelta;
|
||||
}
|
||||
if(fDelta > self->fTolerance){
|
||||
pDorn->iLastError = TARGETREJECTED;
|
||||
return VSFAIL;
|
||||
}
|
||||
|
||||
/*
|
||||
This code considers the velocity selector arrived if it reads
|
||||
four times a difference between requested spped and actual speed
|
||||
@ -433,12 +495,11 @@ static int DornierStatNew(pVelSelDriv self, int *iCode, float *fCur){
|
||||
static void DornierKill(void *pData)
|
||||
{
|
||||
pDornier pDorn = NULL;
|
||||
char pAns[10];
|
||||
|
||||
pDorn = (pDornier)pData;
|
||||
assert(pDorn);
|
||||
|
||||
transactRS232(pDorn->controller,"TTY\n",4,pAns,10);
|
||||
writeRS232(pDorn->controller,"TTY\n",4);
|
||||
KillRS232(pDorn->controller);
|
||||
free(pDorn);
|
||||
}
|
||||
@ -460,15 +521,13 @@ static int DornierStatNew(pVelSelDriv self, int *iCode, float *fCur){
|
||||
}
|
||||
setRS232SendTerminator(pDorn->controller,"\n");
|
||||
setRS232Timeout(pDorn->controller,pDorn->iTimeOut);
|
||||
setRS232Debug(pDorn->controller,1);
|
||||
setRS232Debug(pDorn->controller,0);
|
||||
|
||||
/*
|
||||
tell him that we want control.
|
||||
Funny enough no <cr> or <nl> is sent in the reply to this.
|
||||
*/
|
||||
setRS232ReplyTerminator(pDorn->controller,"\\");
|
||||
iRet = transactRS232(pDorn->controller,"REM\n",4,pError,79);
|
||||
setRS232ReplyTerminator(pDorn->controller,"\r\n");
|
||||
iRet = takeControl(pDorn);
|
||||
if(iRet != 1)
|
||||
{
|
||||
sprintf(pBueffel,
|
||||
@ -480,11 +539,6 @@ static int DornierStatNew(pVelSelDriv self, int *iCode, float *fCur){
|
||||
check which status the velo is in
|
||||
*/
|
||||
pDorn->statusMode = STATSEND;
|
||||
GetDornierPos(self,&fRot);
|
||||
if(fRot < 0){
|
||||
GetDornierPos(self,&fRot);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
@ -132,7 +132,7 @@ static int EL734Run(void *pData,float fValue){
|
||||
assert(self);
|
||||
|
||||
self->oredMsr = 0;
|
||||
snprintf(pCommand,79,"p %d %3.f\r",self->iMotor,fValue);
|
||||
snprintf(pCommand,79,"p %d %.3f\r",self->iMotor,fValue);
|
||||
status = transactRS232(self->controller,pCommand,strlen(pCommand),
|
||||
pReply,79);
|
||||
if(status != 1){
|
||||
|
@ -283,7 +283,7 @@ static int EL737Start(struct __COUNTER *self){
|
||||
|
||||
fixMode(pPriv);
|
||||
if(self->eMode == ePreset){
|
||||
snprintf(pCommand,49,"MP %d\r",(int)nintf(self->fPreset));
|
||||
snprintf(pCommand,49,"MP %d\r",(int)self->fPreset);
|
||||
} else {
|
||||
snprintf(pCommand,49,"TP %.2f\r", self->fPreset);
|
||||
}
|
||||
|
@ -5,9 +5,8 @@
|
||||
# Mark Koennecke, November 1996
|
||||
# Markus Zolliker, March 2003
|
||||
#--------------------------------------------------------------------------
|
||||
# the following line only for fortified version
|
||||
#DFORTIFY=-DFORTIFY
|
||||
#==========================================================================
|
||||
|
||||
include ../../linux_def
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -g -DLINUX $(DFORTIFY) -I$(SRC). -I.. -I../..
|
||||
|
@ -5,16 +5,13 @@
|
||||
# Mark Koennecke 1996-2001
|
||||
# Markus Zolliker, March 2003
|
||||
#==========================================================================
|
||||
# the following lines only for fortified version
|
||||
#DFORTIFY=-DFORTIFY
|
||||
#FORTIFYOBJ=strdup.o fortify.o
|
||||
#==========================================================================
|
||||
|
||||
include ../linux_def
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -I$(HDFROOT)/include -DHDF4 -DHDF5 $(NI) -Ihardsup \
|
||||
-I../ -fwritable-strings -DCYGNUS -DNONINTF -g $(DFORTIFY)
|
||||
|
||||
HDFROOT=/afs/psi.ch/project/sinq/linux
|
||||
EXTRA=nintf.o
|
||||
|
||||
include make_gen
|
||||
|
4
psi.c
4
psi.c
@ -160,7 +160,7 @@ static pMotor CreatePsiMotor(SConnection *pCon, int argc, char *argv[]){
|
||||
return NULL;
|
||||
}
|
||||
} else if(strcmp(argv[1],"ecb") == 0){
|
||||
pDriver = (MotorDriver *)CreateECBMotor(pCon,argc-1,&argv[2]);
|
||||
pDriver = (MotorDriver *)CreateECBMotor(pCon,argc-2,&argv[2]);
|
||||
if(!pDriver){
|
||||
return NULL;
|
||||
}
|
||||
@ -198,8 +198,8 @@ static pCounterDriver CreatePsiCounterDriver(SConnection *pCon,
|
||||
"ERROR: insufficient no of arguments to create ECB counter",
|
||||
eError);
|
||||
return NULL;
|
||||
pNew = MakeECBCounter(argv[3]);
|
||||
}
|
||||
pNew = MakeECBCounter(argv[3]);
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
|
@ -4,10 +4,8 @@
|
||||
#
|
||||
# Markus Zolliker, March 2003
|
||||
#--------------------------------------------------------------------------
|
||||
# the following lines only for fortified version
|
||||
DFORTIFY=-DFORTIFY -I$(SRC)..
|
||||
FORTIFYOBJ=../strdup.o ../fortify.o
|
||||
#==========================================================================
|
||||
|
||||
include ../../linux_def
|
||||
|
||||
SICST=..
|
||||
SICS=$(SRC)..
|
||||
|
Reference in New Issue
Block a user