From 6c71e32f4bb74d60b9e09663e693537b2ddeb58a Mon Sep 17 00:00:00 2001 From: koennecke Date: Thu, 26 Apr 2007 14:33:36 +0000 Subject: [PATCH] - Added scaling to sicsdata - Fixed fixed motor driving in tasdrive - Fixed stdscan to behnave nicely when various things are missing - Fixed a bug in multicounter --- motor.c | 5 +- multicounter.c | 8 +- nxutil.c | 4 +- sicsdata.c | 25 ++++ stdscan.c | 7 +- tasdrive.c | 371 ++++++++++++++++++++----------------------------- 6 files changed, 190 insertions(+), 230 deletions(-) diff --git a/motor.c b/motor.c index 8945b3e8..83795a21 100644 --- a/motor.c +++ b/motor.c @@ -255,6 +255,8 @@ static void finishDriving(pMotor self, SConnection *pCon) MotCallback sCall; MotorGetSoftPosition(self,pCon,&sCall.fVal); sCall.pName = self->name; + self->fPosition = sCall.fVal; + self->fPosition = sCall.fVal; InvokeCallBack(self->pCall, MOTDRIVE, &sCall); /* send also very last position */ InvokeCallBack(self->pCall, MOTEND, &sCall); } @@ -329,7 +331,7 @@ static int evaluateStatus(pMotor self, SConnection *pCon) newStatus = checkPosition(self,pCon); if(newStatus != HWBusy) { - finishDriving(self,pCon); + finishDriving(self,pCon); } } break; @@ -350,6 +352,7 @@ static int evaluateStatus(pMotor self, SConnection *pCon) } if(newStatus == HWFault) { + finishDriving(self,pCon); MotorInterrupt(pCon,ObVal(self->ParArray,INT)); self->retryCount = 0; } diff --git a/multicounter.c b/multicounter.c index 8ab9a351..97b6ea3a 100644 --- a/multicounter.c +++ b/multicounter.c @@ -282,13 +282,11 @@ static int MultiCounterSend(struct __COUNTER *self, char *pText, return 0; } /*---------------------------------------------------------------------*/ -static int MultiCounterError(struct __COUNTER *pData, int *iCode, +static int MultiCounterError(struct __COUNTER *pDriv, int *iCode, char *error, int errlen){ - pCounter pCount = NULL; + - pCount = (pCounter)pData; - - if(pCount->pDriv->iErrorCode == NOCOUNTERS){ + if(pDriv->iErrorCode == NOCOUNTERS){ strncpy(error,"NO counters configured!",errlen); } else { strncpy(error,"Not Implemented", errlen); diff --git a/nxutil.c b/nxutil.c index 82a4edc4..07c74429 100644 --- a/nxutil.c +++ b/nxutil.c @@ -115,7 +115,9 @@ VarGetText(pVar,&pText); if(pText != NULL) { - iRet = NXDputalias(hFil,pDict,pAlias,pText); + memset(pBueffel,0,511); + strncpy(pBueffel,pText,511); + iRet = NXDputalias(hFil,pDict,pAlias,pBueffel); free(pText); return iRet; } diff --git a/sicsdata.c b/sicsdata.c index 4e2e0d67..5b274d8a 100644 --- a/sicsdata.c +++ b/sicsdata.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "fortify.h" #include "sics.h" #include "splitter.h" @@ -375,6 +376,23 @@ static int divideSicsData(pSICSData self, SicsInterp *pSics, } return 1; } +/*------------------------------------------------------------------*/ +static int scaleSicsData(pSICSData self, SicsInterp *pSics, + SConnection *pCon, float scale){ + int i; + float div; + + for(i = 0; i < self->dataUsed; i++){ + div = getDataPos(self,i); + div *= scale; + if(self->dataType[i] == INTTYPE){ + self->data[i] = (int)fabsf(div); + } else { + memcpy(&self->data[i],&div,sizeof(float)); + } + } + return 1; +} /*-------------------------------------------------------------------*/ static int copyScanCounts(pSICSData self, int argc, char *argv[], SConnection *pCon, SicsInterp *pSics){ @@ -703,6 +721,7 @@ int SICSDataAction(SConnection *pCon, SicsInterp *pSics, void *pData, pSICSData self = NULL; char pBueffel[132]; int pos; + float scale; self = (pSICSData)pData; assert(self); @@ -750,6 +769,12 @@ int SICSDataAction(SConnection *pCon, SicsInterp *pSics, void *pData, return 0; } return divideSicsData(self,pSics,pCon,argv[2]); + } else if(strcmp(argv[1],"scale") == 0){ + if(argc < 3){ + SCWrite(pCon,"ERROR: need a scale factor to apply",eError); + return 0; + } + return scaleSicsData(self,pSics,pCon,atof(argv[2])); } else if(strcmp(argv[1],"copydata") == 0){ return copyData(self,pSics,pCon,argc, argv); } else if(strcmp(argv[1],"putint") == 0){ diff --git a/stdscan.c b/stdscan.c index a4d38bf1..aacbd9dc 100644 --- a/stdscan.c +++ b/stdscan.c @@ -610,7 +610,7 @@ int prepareDataFile(pScanData self){ char pBueffel[512]; /* allocate a new data file */ - pPtr = ScanMakeFileName(self->pSics,self->pCon); + pPtr = ScanMakeFileName(pServ->pSics,self->pCon); if(!pPtr) { SCWrite(self->pCon, @@ -637,7 +637,6 @@ int prepareDataFile(pScanData self){ char pMessage[1024]; assert(self); - assert(self->iNP > 0); assert(self->pCon); /* check boundaries of scan variables and allocate storage */ @@ -1124,6 +1123,10 @@ int StandardScanWrapper(SConnection *pCon, SicsInterp *pSics, void *pData, return 0; } + if(self->pCon == NULL){ + self->pCon = pCon; + } + if(strcmp(argv[1],"writeheader") == 0){ return WriteHeader(self); } else if(strcmp(argv[1],"prepare") == 0){ diff --git a/tasdrive.c b/tasdrive.c index de3fff85..ad3ba81d 100644 --- a/tasdrive.c +++ b/tasdrive.c @@ -217,11 +217,33 @@ static float getMotorValue(pMotor mot, SConnection *pCon){ MotorGetSoftPosition(mot,pCon,&val); return val; -} +} +/*--------------------------------------------------------------------------*/ +static int startTASMotor(pMotor mot, SConnection *pCon, char *name, + double target, int silent){ + float val, fixed; + int status = OKOK; + char buffer[132]; + + val = getMotorValue(mot,pCon); + MotorGetPar(mot,"fixed",&fixed); + if(ABS(fixed - 1.0) < .1) { + snprintf(buffer,131,"WARNING: %s is FIXED", name); + SCWrite(pCon,buffer,eWarning); + return OKOK; + } + if(ABS(val - target) > MOTPREC){ + status = mot->pDrivInt->SetValue(mot,pCon,(float)target); + if(status != OKOK){ + return status; + } + } + writeMotPos(pCon,silent,name,val, target); + return status; +} /*---------------------------------------------------------------------------*/ static int startMotors(ptasMot self, tasAngles angles, SConnection *pCon, int driveQ, int driveTilt){ - float val; double curve; int status, silent; @@ -229,115 +251,71 @@ static int startMotors(ptasMot self, tasAngles angles, /* monochromator */ - val = getMotorValue(self->math->motors[A1],pCon); - if(ABS(val - angles.monochromator_two_theta/2.) > MOTPREC){ - status = self->math->motors[A1]->pDrivInt->SetValue(self->math->motors[A1], - pCon, - angles.monochromator_two_theta/2.); - if(status != OKOK){ - return status; - } + status = startTASMotor(self->math->motors[A1],pCon, "a1", + angles.monochromator_two_theta/2.,silent); + if(status != OKOK){ + return status; } - writeMotPos(pCon,silent,"a1",val, angles.monochromator_two_theta/2.); - - val = getMotorValue(self->math->motors[A2],pCon); - if(ABS(val - angles.monochromator_two_theta) > MOTPREC){ - status = self->math->motors[A2]->pDrivInt->SetValue(self->math->motors[A2], - pCon, - angles.monochromator_two_theta); - if(status != OKOK){ - return status; - } + status = startTASMotor(self->math->motors[A2],pCon, "a2", + angles.monochromator_two_theta,silent); + if(status != OKOK){ + return status; } - writeMotPos(pCon,silent,"a2",val, angles.monochromator_two_theta); - + if(self->math->motors[MCV] != NULL){ curve = maCalcVerticalCurvature(self->math->machine.monochromator, angles.monochromator_two_theta); - - val = getMotorValue(self->math->motors[MCV],pCon); - if(ABS(val - curve) > MOTPREC){ - status = self->math->motors[MCV]->pDrivInt->SetValue(self->math->motors[MCV], - pCon, - curve); - if(status != OKOK){ - return status; - } + status = startTASMotor(self->math->motors[MCV],pCon, "mcv", + curve,silent); + if(status != OKOK){ + return status; } - writeMotPos(pCon,silent,"mcv",val, curve); - } - + } + if(self->math->motors[MCH] != NULL){ curve = maCalcHorizontalCurvature(self->math->machine.monochromator, - angles.monochromator_two_theta); - - val = getMotorValue(self->math->motors[MCH],pCon); - if(ABS(val - curve) > MOTPREC){ - status = self->math->motors[MCH]->pDrivInt->SetValue(self->math->motors[MCH], - pCon, - curve); - if(status != OKOK){ - return status; - } + angles.monochromator_two_theta); + status = startTASMotor(self->math->motors[MCH],pCon, "mch", + curve,silent); + if(status != OKOK){ + return status; } - writeMotPos(pCon,silent,"mch",val, curve); } + /* analyzer */ if(self->math->tasMode != ELASTIC){ - val = getMotorValue(self->math->motors[A5],pCon); - if(ABS(val - angles.analyzer_two_theta/2.) > MOTPREC){ - status = self->math->motors[A5]->pDrivInt->SetValue(self->math->motors[A5], - pCon, - angles.analyzer_two_theta/2.); - if(status != OKOK){ - return status; - } - } - writeMotPos(pCon,silent,self->math->motors[A5]->name, - val, angles.analyzer_two_theta/2.); - - val = getMotorValue(self->math->motors[A6],pCon); - if(ABS(val - angles.analyzer_two_theta) > MOTPREC){ - status = self->math->motors[A6]->pDrivInt->SetValue(self->math->motors[A6], - pCon, - angles.analyzer_two_theta); - if(status != OKOK){ - return status; - } - } - writeMotPos(pCon,silent,"a6",val, angles.analyzer_two_theta); + status = startTASMotor(self->math->motors[A5],pCon, "a5", + angles.analyzer_two_theta/2.0,silent); + if(status != OKOK){ + return status; + } + status = startTASMotor(self->math->motors[A6],pCon, "a6", + angles.analyzer_two_theta,silent); + if(status != OKOK){ + return status; + } if(self->math->motors[ACV] != NULL){ curve = maCalcVerticalCurvature(self->math->machine.analyzer, angles.analyzer_two_theta); - val = getMotorValue(self->math->motors[ACV],pCon); - if(ABS(val - curve) > MOTPREC){ - status = self->math->motors[ACV]->pDrivInt->SetValue(self->math->motors[ACV], - pCon, - curve); - if(status != OKOK){ - return status; - } - } - writeMotPos(pCon,silent,"acv",val, curve); - } + status = startTASMotor(self->math->motors[ACV],pCon, "acv", + curve,silent); + if(status != OKOK){ + return status; + } + } if(self->math->motors[ACH] != NULL){ curve = maCalcHorizontalCurvature(self->math->machine.analyzer, angles.analyzer_two_theta); - val = getMotorValue(self->math->motors[ACH],pCon); - if(ABS(val - curve) > MOTPREC){ - status = self->math->motors[ACH]->pDrivInt->SetValue(self->math->motors[ACH], - pCon, - curve); - if(status != OKOK){ - return status; - } - } - writeMotPos(pCon,silent,"ach",val, curve); - } + status = startTASMotor(self->math->motors[ACH],pCon, "ach", + curve,silent); + if(status != OKOK){ + return status; + } + } } if(driveQ == 0){ @@ -347,50 +325,28 @@ static int startMotors(ptasMot self, tasAngles angles, /* crystal */ - val = getMotorValue(self->math->motors[A3],pCon); - if(ABS(val - angles.a3) > MOTPREC){ - status = self->math->motors[A3]->pDrivInt->SetValue(self->math->motors[A3], - pCon, - angles.a3); - if(status != OKOK){ - return status; - } + status = startTASMotor(self->math->motors[A3],pCon, "a3", + angles.a3,silent); + if(status != OKOK){ + return status; } - writeMotPos(pCon,silent,"a3",val, angles.a3); - - val = getMotorValue(self->math->motors[A4],pCon); - if(ABS(val - angles.sample_two_theta) > MOTPREC){ - status = self->math->motors[A4]->pDrivInt->SetValue(self->math->motors[A4], - pCon, - angles.sample_two_theta); - if(status != OKOK){ - return status; - } + status = startTASMotor(self->math->motors[A4],pCon, "a4", + angles.sample_two_theta,silent); + if(status != OKOK){ + return status; } - writeMotPos(pCon,silent,"a4",val, angles.sample_two_theta); - + if(driveTilt == 1){ - val = getMotorValue(self->math->motors[SGL],pCon); - if(ABS(val - angles.sgl) > MOTPREC){ - status = self->math->motors[SGL]->pDrivInt->SetValue(self->math->motors[SGL], - pCon, - angles.sgl); - if(status != OKOK){ - return status; - } - } - writeMotPos(pCon,silent,"sgl",val, angles.sgl); - - val = getMotorValue(self->math->motors[SGU],pCon); - if(ABS(val - angles.sgu) > MOTPREC){ - status = self->math->motors[SGU]->pDrivInt->SetValue(self->math->motors[SGU], - pCon, - angles.sgu); - if(status != OKOK){ - return status; - } - } - writeMotPos(pCon,silent,"sgu",val, angles.sgu); + status = startTASMotor(self->math->motors[SGL],pCon, "sgl", + angles.sgl,silent); + if(status != OKOK){ + return status; + } + status = startTASMotor(self->math->motors[SGU],pCon, "sgu", + angles.sgu,silent); + if(status != OKOK){ + return status; + } } self->math->mustDrive = 0; return OKOK; @@ -401,17 +357,21 @@ static int checkQMotorLimits(ptasMot self, SConnection *pCon, int status, retVal = 1; char error[131]; char pBueffel[256]; + float val; - status = self->math->motors[A3]->pDrivInt->CheckLimits(self->math->motors[A3], - angles.a3, - error, - 131); - if(status != 1) { - retVal = 0; - snprintf(pBueffel,256,"ERROR: limit violation an a3: %s", error); - SCWrite(pCon,pBueffel,eError); + MotorGetPar(self->math->motors[A3],"fixed",&val); + if((int)val != 1){ + status = self->math->motors[A3]->pDrivInt->CheckLimits(self->math->motors[A3], + angles.a3, + error, + 131); + if(status != 1) { + retVal = 0; + snprintf(pBueffel,256,"ERROR: limit violation an a3: %s", error); + SCWrite(pCon,pBueffel,eError); + } } - + status = self->math->motors[A4]->pDrivInt->CheckLimits(self->math->motors[A4], angles.sample_two_theta, error, @@ -550,117 +510,86 @@ static int startQMMotors(ptasMot self, tasAngles angles, SConnection *pCon){ float val; double curve; - int status; + int status, silent; + silent = self->math->silent; /* monochromator */ - val = self->math->motors[A1]->pDrivInt->GetValue(self->math->motors[A1],pCon); - if(ABS(val - angles.monochromator_two_theta/2.) > MOTPREC){ - status = self->math->motors[A1]->pDrivInt->SetValue(self->math->motors[A1], - pCon, - angles.monochromator_two_theta/2.); - if(status != OKOK){ - return status; - } + status = startTASMotor(self->math->motors[A1],pCon, "a1", + angles.monochromator_two_theta/2.,silent); + if(status != OKOK){ + return status; } - val = self->math->motors[A2]->pDrivInt->GetValue(self->math->motors[A2],pCon); - if(ABS(val - angles.monochromator_two_theta) > MOTPREC){ - status = self->math->motors[A2]->pDrivInt->SetValue(self->math->motors[A2], - pCon, - angles.monochromator_two_theta); - if(status != OKOK){ - return status; - } + status = startTASMotor(self->math->motors[A2],pCon, "a2", + angles.monochromator_two_theta,silent); + if(status != OKOK){ + return status; } + if(self->math->motors[MCV] != NULL){ curve = maCalcVerticalCurvature(self->math->machine.monochromator, - angles.monochromator_two_theta); - val = self->math->motors[MCV]->pDrivInt->GetValue(self->math->motors[MCV],pCon); - if(ABS(val - curve) > MOTPREC){ - status = self->math->motors[MCV]->pDrivInt->SetValue(self->math->motors[MCV], - pCon, - curve); - if(status != OKOK){ - return status; - } + angles.monochromator_two_theta); + status = startTASMotor(self->math->motors[MCV],pCon, "mcv", + curve,silent); + if(status != OKOK){ + return status; } } + if(self->math->motors[MCH] != NULL){ curve = maCalcHorizontalCurvature(self->math->machine.monochromator, - angles.monochromator_two_theta); - val = self->math->motors[MCH]->pDrivInt->GetValue(self->math->motors[MCH],pCon); - if(ABS(val - curve) > MOTPREC){ - status = self->math->motors[MCH]->pDrivInt->SetValue(self->math->motors[MCH], - pCon, - curve); - if(status != OKOK){ - return status; - } + angles.monochromator_two_theta); + status = startTASMotor(self->math->motors[MCH],pCon, "mch", + curve,silent); + if(status != OKOK){ + return status; } } + /* analyzer */ - val = self->math->motors[A5]->pDrivInt->GetValue(self->math->motors[A5],pCon); - if(ABS(val - angles.analyzer_two_theta/2.) > MOTPREC){ - status = self->math->motors[A5]->pDrivInt->SetValue(self->math->motors[A5], - pCon, - angles.analyzer_two_theta/2.); + status = startTASMotor(self->math->motors[A5],pCon, "a5", + angles.analyzer_two_theta/2.0,silent); if(status != OKOK){ - return status; + return status; } - } - val = self->math->motors[A6]->pDrivInt->GetValue(self->math->motors[A6],pCon); - if(ABS(val - angles.analyzer_two_theta) > MOTPREC){ - status = self->math->motors[A6]->pDrivInt->SetValue(self->math->motors[A6], - pCon, - angles.analyzer_two_theta); + status = startTASMotor(self->math->motors[A6],pCon, "a6", + angles.analyzer_two_theta,silent); if(status != OKOK){ - return status; + return status; } - } - if(self->math->motors[ACV] != NULL){ - curve = maCalcVerticalCurvature(self->math->machine.analyzer, - angles.analyzer_two_theta); - val = self->math->motors[ACV]->pDrivInt->GetValue(self->math->motors[ACV],pCon); - if(ABS(val - curve) > MOTPREC){ - status = self->math->motors[ACV]->pDrivInt->SetValue(self->math->motors[ACV], - pCon, - curve); - if(status != OKOK){ - return status; - } + + if(self->math->motors[ACV] != NULL){ + curve = maCalcVerticalCurvature(self->math->machine.analyzer, + angles.analyzer_two_theta); + status = startTASMotor(self->math->motors[ACV],pCon, "acv", + curve,silent); + if(status != OKOK){ + return status; + } } - } - if(self->math->motors[ACH] != NULL){ - curve = maCalcHorizontalCurvature(self->math->machine.analyzer, - angles.analyzer_two_theta); - val = self->math->motors[ACH]->pDrivInt->GetValue(self->math->motors[ACH],pCon); - if(ABS(val - curve) > MOTPREC){ - status = self->math->motors[ACH]->pDrivInt->SetValue(self->math->motors[ACH], - pCon, - curve); - if(status != OKOK){ - return status; - } + if(self->math->motors[ACH] != NULL){ + curve = maCalcHorizontalCurvature(self->math->machine.analyzer, + angles.analyzer_two_theta); + status = startTASMotor(self->math->motors[ACH],pCon, "ach", + curve,silent); + if(status != OKOK){ + return status; + } } - } /* crystal */ - val = self->math->motors[A4]->pDrivInt->GetValue(self->math->motors[A4],pCon); - if(ABS(val - angles.sample_two_theta) > MOTPREC){ - status = self->math->motors[A4]->pDrivInt->SetValue(self->math->motors[A4], - pCon, - angles.sample_two_theta); - if(status != OKOK){ - return status; - } + status = startTASMotor(self->math->motors[A4],pCon, "a4", + angles.sample_two_theta,silent); + if(status != OKOK){ + return status; } - + self->math->mustDrive = 0; return OKOK; }