- 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
This commit is contained in:
koennecke
2007-04-26 14:33:36 +00:00
parent 82be2f1f85
commit 6c71e32f4b
6 changed files with 190 additions and 230 deletions

View File

@ -255,6 +255,8 @@ static void finishDriving(pMotor self, SConnection *pCon)
MotCallback sCall; MotCallback sCall;
MotorGetSoftPosition(self,pCon,&sCall.fVal); MotorGetSoftPosition(self,pCon,&sCall.fVal);
sCall.pName = self->name; 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, MOTDRIVE, &sCall); /* send also very last position */
InvokeCallBack(self->pCall, MOTEND, &sCall); InvokeCallBack(self->pCall, MOTEND, &sCall);
} }
@ -329,7 +331,7 @@ static int evaluateStatus(pMotor self, SConnection *pCon)
newStatus = checkPosition(self,pCon); newStatus = checkPosition(self,pCon);
if(newStatus != HWBusy) if(newStatus != HWBusy)
{ {
finishDriving(self,pCon); finishDriving(self,pCon);
} }
} }
break; break;
@ -350,6 +352,7 @@ static int evaluateStatus(pMotor self, SConnection *pCon)
} }
if(newStatus == HWFault) if(newStatus == HWFault)
{ {
finishDriving(self,pCon);
MotorInterrupt(pCon,ObVal(self->ParArray,INT)); MotorInterrupt(pCon,ObVal(self->ParArray,INT));
self->retryCount = 0; self->retryCount = 0;
} }

View File

@ -282,13 +282,11 @@ static int MultiCounterSend(struct __COUNTER *self, char *pText,
return 0; return 0;
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
static int MultiCounterError(struct __COUNTER *pData, int *iCode, static int MultiCounterError(struct __COUNTER *pDriv, int *iCode,
char *error, int errlen){ char *error, int errlen){
pCounter pCount = NULL;
pCount = (pCounter)pData; if(pDriv->iErrorCode == NOCOUNTERS){
if(pCount->pDriv->iErrorCode == NOCOUNTERS){
strncpy(error,"NO counters configured!",errlen); strncpy(error,"NO counters configured!",errlen);
} else { } else {
strncpy(error,"Not Implemented", errlen); strncpy(error,"Not Implemented", errlen);

View File

@ -115,7 +115,9 @@
VarGetText(pVar,&pText); VarGetText(pVar,&pText);
if(pText != NULL) 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); free(pText);
return iRet; return iRet;
} }

View File

@ -13,6 +13,7 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <tcl.h> #include <tcl.h>
#include <math.h>
#include "fortify.h" #include "fortify.h"
#include "sics.h" #include "sics.h"
#include "splitter.h" #include "splitter.h"
@ -375,6 +376,23 @@ static int divideSicsData(pSICSData self, SicsInterp *pSics,
} }
return 1; 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[], static int copyScanCounts(pSICSData self, int argc, char *argv[],
SConnection *pCon, SicsInterp *pSics){ SConnection *pCon, SicsInterp *pSics){
@ -703,6 +721,7 @@ int SICSDataAction(SConnection *pCon, SicsInterp *pSics, void *pData,
pSICSData self = NULL; pSICSData self = NULL;
char pBueffel[132]; char pBueffel[132];
int pos; int pos;
float scale;
self = (pSICSData)pData; self = (pSICSData)pData;
assert(self); assert(self);
@ -750,6 +769,12 @@ int SICSDataAction(SConnection *pCon, SicsInterp *pSics, void *pData,
return 0; return 0;
} }
return divideSicsData(self,pSics,pCon,argv[2]); 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){ } else if(strcmp(argv[1],"copydata") == 0){
return copyData(self,pSics,pCon,argc, argv); return copyData(self,pSics,pCon,argc, argv);
} else if(strcmp(argv[1],"putint") == 0){ } else if(strcmp(argv[1],"putint") == 0){

View File

@ -610,7 +610,7 @@ int prepareDataFile(pScanData self){
char pBueffel[512]; char pBueffel[512];
/* allocate a new data file */ /* allocate a new data file */
pPtr = ScanMakeFileName(self->pSics,self->pCon); pPtr = ScanMakeFileName(pServ->pSics,self->pCon);
if(!pPtr) if(!pPtr)
{ {
SCWrite(self->pCon, SCWrite(self->pCon,
@ -637,7 +637,6 @@ int prepareDataFile(pScanData self){
char pMessage[1024]; char pMessage[1024];
assert(self); assert(self);
assert(self->iNP > 0);
assert(self->pCon); assert(self->pCon);
/* check boundaries of scan variables and allocate storage */ /* check boundaries of scan variables and allocate storage */
@ -1124,6 +1123,10 @@ int StandardScanWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
return 0; return 0;
} }
if(self->pCon == NULL){
self->pCon = pCon;
}
if(strcmp(argv[1],"writeheader") == 0){ if(strcmp(argv[1],"writeheader") == 0){
return WriteHeader(self); return WriteHeader(self);
} else if(strcmp(argv[1],"prepare") == 0){ } else if(strcmp(argv[1],"prepare") == 0){

View File

@ -217,11 +217,33 @@ static float getMotorValue(pMotor mot, SConnection *pCon){
MotorGetSoftPosition(mot,pCon,&val); MotorGetSoftPosition(mot,pCon,&val);
return 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, static int startMotors(ptasMot self, tasAngles angles,
SConnection *pCon, int driveQ, int driveTilt){ SConnection *pCon, int driveQ, int driveTilt){
float val;
double curve; double curve;
int status, silent; int status, silent;
@ -229,115 +251,71 @@ static int startMotors(ptasMot self, tasAngles angles,
/* /*
monochromator monochromator
*/ */
val = getMotorValue(self->math->motors[A1],pCon); status = startTASMotor(self->math->motors[A1],pCon, "a1",
if(ABS(val - angles.monochromator_two_theta/2.) > MOTPREC){ angles.monochromator_two_theta/2.,silent);
status = self->math->motors[A1]->pDrivInt->SetValue(self->math->motors[A1], if(status != OKOK){
pCon, return status;
angles.monochromator_two_theta/2.);
if(status != OKOK){
return status;
}
} }
writeMotPos(pCon,silent,"a1",val, angles.monochromator_two_theta/2.); status = startTASMotor(self->math->motors[A2],pCon, "a2",
angles.monochromator_two_theta,silent);
val = getMotorValue(self->math->motors[A2],pCon); if(status != OKOK){
if(ABS(val - angles.monochromator_two_theta) > MOTPREC){ return status;
status = self->math->motors[A2]->pDrivInt->SetValue(self->math->motors[A2],
pCon,
angles.monochromator_two_theta);
if(status != OKOK){
return status;
}
} }
writeMotPos(pCon,silent,"a2",val, angles.monochromator_two_theta);
if(self->math->motors[MCV] != NULL){ if(self->math->motors[MCV] != NULL){
curve = maCalcVerticalCurvature(self->math->machine.monochromator, curve = maCalcVerticalCurvature(self->math->machine.monochromator,
angles.monochromator_two_theta); angles.monochromator_two_theta);
status = startTASMotor(self->math->motors[MCV],pCon, "mcv",
val = getMotorValue(self->math->motors[MCV],pCon); curve,silent);
if(ABS(val - curve) > MOTPREC){ if(status != OKOK){
status = self->math->motors[MCV]->pDrivInt->SetValue(self->math->motors[MCV], return status;
pCon,
curve);
if(status != OKOK){
return status;
}
} }
writeMotPos(pCon,silent,"mcv",val, curve); }
}
if(self->math->motors[MCH] != NULL){ if(self->math->motors[MCH] != NULL){
curve = maCalcHorizontalCurvature(self->math->machine.monochromator, curve = maCalcHorizontalCurvature(self->math->machine.monochromator,
angles.monochromator_two_theta); angles.monochromator_two_theta);
status = startTASMotor(self->math->motors[MCH],pCon, "mch",
val = getMotorValue(self->math->motors[MCH],pCon); curve,silent);
if(ABS(val - curve) > MOTPREC){ if(status != OKOK){
status = self->math->motors[MCH]->pDrivInt->SetValue(self->math->motors[MCH], return status;
pCon,
curve);
if(status != OKOK){
return status;
}
} }
writeMotPos(pCon,silent,"mch",val, curve);
} }
/* /*
analyzer analyzer
*/ */
if(self->math->tasMode != ELASTIC){ if(self->math->tasMode != ELASTIC){
val = getMotorValue(self->math->motors[A5],pCon); status = startTASMotor(self->math->motors[A5],pCon, "a5",
if(ABS(val - angles.analyzer_two_theta/2.) > MOTPREC){ angles.analyzer_two_theta/2.0,silent);
status = self->math->motors[A5]->pDrivInt->SetValue(self->math->motors[A5], if(status != OKOK){
pCon, return status;
angles.analyzer_two_theta/2.); }
if(status != OKOK){ status = startTASMotor(self->math->motors[A6],pCon, "a6",
return status; angles.analyzer_two_theta,silent);
} 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);
if(self->math->motors[ACV] != NULL){ if(self->math->motors[ACV] != NULL){
curve = maCalcVerticalCurvature(self->math->machine.analyzer, curve = maCalcVerticalCurvature(self->math->machine.analyzer,
angles.analyzer_two_theta); angles.analyzer_two_theta);
val = getMotorValue(self->math->motors[ACV],pCon); status = startTASMotor(self->math->motors[ACV],pCon, "acv",
if(ABS(val - curve) > MOTPREC){ curve,silent);
status = self->math->motors[ACV]->pDrivInt->SetValue(self->math->motors[ACV], if(status != OKOK){
pCon, return status;
curve); }
if(status != OKOK){ }
return status;
}
}
writeMotPos(pCon,silent,"acv",val, curve);
}
if(self->math->motors[ACH] != NULL){ if(self->math->motors[ACH] != NULL){
curve = maCalcHorizontalCurvature(self->math->machine.analyzer, curve = maCalcHorizontalCurvature(self->math->machine.analyzer,
angles.analyzer_two_theta); angles.analyzer_two_theta);
val = getMotorValue(self->math->motors[ACH],pCon); status = startTASMotor(self->math->motors[ACH],pCon, "ach",
if(ABS(val - curve) > MOTPREC){ curve,silent);
status = self->math->motors[ACH]->pDrivInt->SetValue(self->math->motors[ACH], if(status != OKOK){
pCon, return status;
curve); }
if(status != OKOK){ }
return status;
}
}
writeMotPos(pCon,silent,"ach",val, curve);
}
} }
if(driveQ == 0){ if(driveQ == 0){
@ -347,50 +325,28 @@ static int startMotors(ptasMot self, tasAngles angles,
/* /*
crystal crystal
*/ */
val = getMotorValue(self->math->motors[A3],pCon); status = startTASMotor(self->math->motors[A3],pCon, "a3",
if(ABS(val - angles.a3) > MOTPREC){ angles.a3,silent);
status = self->math->motors[A3]->pDrivInt->SetValue(self->math->motors[A3], if(status != OKOK){
pCon, return status;
angles.a3);
if(status != OKOK){
return status;
}
} }
writeMotPos(pCon,silent,"a3",val, angles.a3); status = startTASMotor(self->math->motors[A4],pCon, "a4",
angles.sample_two_theta,silent);
val = getMotorValue(self->math->motors[A4],pCon); if(status != OKOK){
if(ABS(val - angles.sample_two_theta) > MOTPREC){ return status;
status = self->math->motors[A4]->pDrivInt->SetValue(self->math->motors[A4],
pCon,
angles.sample_two_theta);
if(status != OKOK){
return status;
}
} }
writeMotPos(pCon,silent,"a4",val, angles.sample_two_theta);
if(driveTilt == 1){ if(driveTilt == 1){
val = getMotorValue(self->math->motors[SGL],pCon); status = startTASMotor(self->math->motors[SGL],pCon, "sgl",
if(ABS(val - angles.sgl) > MOTPREC){ angles.sgl,silent);
status = self->math->motors[SGL]->pDrivInt->SetValue(self->math->motors[SGL], if(status != OKOK){
pCon, return status;
angles.sgl); }
if(status != OKOK){ status = startTASMotor(self->math->motors[SGU],pCon, "sgu",
return status; angles.sgu,silent);
} 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);
} }
self->math->mustDrive = 0; self->math->mustDrive = 0;
return OKOK; return OKOK;
@ -401,17 +357,21 @@ static int checkQMotorLimits(ptasMot self, SConnection *pCon,
int status, retVal = 1; int status, retVal = 1;
char error[131]; char error[131];
char pBueffel[256]; char pBueffel[256];
float val;
status = self->math->motors[A3]->pDrivInt->CheckLimits(self->math->motors[A3], MotorGetPar(self->math->motors[A3],"fixed",&val);
angles.a3, if((int)val != 1){
error, status = self->math->motors[A3]->pDrivInt->CheckLimits(self->math->motors[A3],
131); angles.a3,
if(status != 1) { error,
retVal = 0; 131);
snprintf(pBueffel,256,"ERROR: limit violation an a3: %s", error); if(status != 1) {
SCWrite(pCon,pBueffel,eError); 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], status = self->math->motors[A4]->pDrivInt->CheckLimits(self->math->motors[A4],
angles.sample_two_theta, angles.sample_two_theta,
error, error,
@ -550,117 +510,86 @@ static int startQMMotors(ptasMot self, tasAngles angles,
SConnection *pCon){ SConnection *pCon){
float val; float val;
double curve; double curve;
int status; int status, silent;
silent = self->math->silent;
/* /*
monochromator monochromator
*/ */
val = self->math->motors[A1]->pDrivInt->GetValue(self->math->motors[A1],pCon); status = startTASMotor(self->math->motors[A1],pCon, "a1",
if(ABS(val - angles.monochromator_two_theta/2.) > MOTPREC){ angles.monochromator_two_theta/2.,silent);
status = self->math->motors[A1]->pDrivInt->SetValue(self->math->motors[A1], if(status != OKOK){
pCon, return status;
angles.monochromator_two_theta/2.);
if(status != OKOK){
return status;
}
} }
val = self->math->motors[A2]->pDrivInt->GetValue(self->math->motors[A2],pCon); status = startTASMotor(self->math->motors[A2],pCon, "a2",
if(ABS(val - angles.monochromator_two_theta) > MOTPREC){ angles.monochromator_two_theta,silent);
status = self->math->motors[A2]->pDrivInt->SetValue(self->math->motors[A2], if(status != OKOK){
pCon, return status;
angles.monochromator_two_theta);
if(status != OKOK){
return status;
}
} }
if(self->math->motors[MCV] != NULL){ if(self->math->motors[MCV] != NULL){
curve = maCalcVerticalCurvature(self->math->machine.monochromator, curve = maCalcVerticalCurvature(self->math->machine.monochromator,
angles.monochromator_two_theta); angles.monochromator_two_theta);
val = self->math->motors[MCV]->pDrivInt->GetValue(self->math->motors[MCV],pCon); status = startTASMotor(self->math->motors[MCV],pCon, "mcv",
if(ABS(val - curve) > MOTPREC){ curve,silent);
status = self->math->motors[MCV]->pDrivInt->SetValue(self->math->motors[MCV], if(status != OKOK){
pCon, return status;
curve);
if(status != OKOK){
return status;
}
} }
} }
if(self->math->motors[MCH] != NULL){ if(self->math->motors[MCH] != NULL){
curve = maCalcHorizontalCurvature(self->math->machine.monochromator, curve = maCalcHorizontalCurvature(self->math->machine.monochromator,
angles.monochromator_two_theta); angles.monochromator_two_theta);
val = self->math->motors[MCH]->pDrivInt->GetValue(self->math->motors[MCH],pCon); status = startTASMotor(self->math->motors[MCH],pCon, "mch",
if(ABS(val - curve) > MOTPREC){ curve,silent);
status = self->math->motors[MCH]->pDrivInt->SetValue(self->math->motors[MCH], if(status != OKOK){
pCon, return status;
curve);
if(status != OKOK){
return status;
}
} }
} }
/* /*
analyzer analyzer
*/ */
val = self->math->motors[A5]->pDrivInt->GetValue(self->math->motors[A5],pCon); status = startTASMotor(self->math->motors[A5],pCon, "a5",
if(ABS(val - angles.analyzer_two_theta/2.) > MOTPREC){ angles.analyzer_two_theta/2.0,silent);
status = self->math->motors[A5]->pDrivInt->SetValue(self->math->motors[A5],
pCon,
angles.analyzer_two_theta/2.);
if(status != OKOK){ if(status != OKOK){
return status; return status;
} }
} status = startTASMotor(self->math->motors[A6],pCon, "a6",
val = self->math->motors[A6]->pDrivInt->GetValue(self->math->motors[A6],pCon); angles.analyzer_two_theta,silent);
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){ if(status != OKOK){
return status; return status;
} }
}
if(self->math->motors[ACV] != NULL){ if(self->math->motors[ACV] != NULL){
curve = maCalcVerticalCurvature(self->math->machine.analyzer, curve = maCalcVerticalCurvature(self->math->machine.analyzer,
angles.analyzer_two_theta); angles.analyzer_two_theta);
val = self->math->motors[ACV]->pDrivInt->GetValue(self->math->motors[ACV],pCon); status = startTASMotor(self->math->motors[ACV],pCon, "acv",
if(ABS(val - curve) > MOTPREC){ curve,silent);
status = self->math->motors[ACV]->pDrivInt->SetValue(self->math->motors[ACV], if(status != OKOK){
pCon, return status;
curve); }
if(status != OKOK){
return status;
}
} }
} if(self->math->motors[ACH] != NULL){
if(self->math->motors[ACH] != NULL){ curve = maCalcHorizontalCurvature(self->math->machine.analyzer,
curve = maCalcHorizontalCurvature(self->math->machine.analyzer, angles.analyzer_two_theta);
angles.analyzer_two_theta); status = startTASMotor(self->math->motors[ACH],pCon, "ach",
val = self->math->motors[ACH]->pDrivInt->GetValue(self->math->motors[ACH],pCon); curve,silent);
if(ABS(val - curve) > MOTPREC){ if(status != OKOK){
status = self->math->motors[ACH]->pDrivInt->SetValue(self->math->motors[ACH], return status;
pCon, }
curve);
if(status != OKOK){
return status;
}
} }
}
/* /*
crystal crystal
*/ */
val = self->math->motors[A4]->pDrivInt->GetValue(self->math->motors[A4],pCon); status = startTASMotor(self->math->motors[A4],pCon, "a4",
if(ABS(val - angles.sample_two_theta) > MOTPREC){ angles.sample_two_theta,silent);
status = self->math->motors[A4]->pDrivInt->SetValue(self->math->motors[A4], if(status != OKOK){
pCon, return status;
angles.sample_two_theta);
if(status != OKOK){
return status;
}
} }
self->math->mustDrive = 0; self->math->mustDrive = 0;
return OKOK; return OKOK;
} }