Cleaned up ANSTO code to merge with sinqdev.sics
This is our new RELEASE-4_0 branch which was taken from ansto/93d9a7c Conflicts: .gitignore SICSmain.c asynnet.c confvirtualmot.c counter.c devexec.c drive.c event.h exebuf.c exeman.c histmem.c interface.h motor.c motorlist.c motorsec.c multicounter.c napi.c napi.h napi4.c network.c nwatch.c nxscript.c nxxml.c nxxml.h ofac.c reflist.c scan.c sicshipadaba.c sicsobj.c site_ansto/docs/Copyright.txt site_ansto/instrument/lyrebird/config/tasmad/sicscommon/nxsupport.tcl site_ansto/instrument/lyrebird/config/tasmad/taspub_sics/tasscript.tcl statusfile.c tasdrive.c tasub.c tasub.h tasublib.c tasublib.h
This commit is contained in:
153
tasub.c
153
tasub.c
@ -15,6 +15,7 @@
|
||||
Mark Koennecke, September 2011
|
||||
----------------------------------------------------------------------*/
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include "sics.h"
|
||||
#include "lld.h"
|
||||
#include "SCinter.h"
|
||||
@ -22,6 +23,7 @@
|
||||
#include "tasub.h"
|
||||
#include "tasdrive.h"
|
||||
#include "vector.h"
|
||||
#include "tasmono.h"
|
||||
/*------------------- motor indexes in motor data structure ---------*/
|
||||
#define A1 0
|
||||
#define A2 1
|
||||
@ -173,8 +175,8 @@ static ptasUB MakeTasUB()
|
||||
pNew->actualEn = .0;
|
||||
pNew->outOfPlaneAllowed = 1;
|
||||
pNew->mustRecalculate = 1;
|
||||
pNew->autofocus = 0;
|
||||
pNew->focusfn = THETA_FN;
|
||||
pNew->mono = MakeTasMono();
|
||||
pNew->monoData = pNew;
|
||||
|
||||
return pNew;
|
||||
}
|
||||
@ -200,63 +202,12 @@ static void KillTasUB(void *pData)
|
||||
if(self->updater != NULL){
|
||||
free(self->updater);
|
||||
}
|
||||
if(self->mono != NULL){
|
||||
free(self->mono);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
|
||||
/*===================== computation section =========================*/
|
||||
static int readTASAngles(ptasUB self, SConnection * pCon, ptasAngles ang)
|
||||
{
|
||||
int status;
|
||||
float val;
|
||||
|
||||
/*
|
||||
Monochromator
|
||||
*/
|
||||
status = GetDrivablePosition(self->motors[A2], pCon, &val);
|
||||
if (status == 0) {
|
||||
return status;
|
||||
}
|
||||
ang->monochromator_two_theta = val;
|
||||
|
||||
/*
|
||||
Analyzer
|
||||
*/
|
||||
if (self->tasMode != ELASTIC) {
|
||||
status = GetDrivablePosition(self->motors[A6], pCon, &val);
|
||||
if (status == 0) {
|
||||
return status;
|
||||
}
|
||||
ang->analyzer_two_theta = val;
|
||||
} else {
|
||||
ang->analyzer_two_theta = ang->monochromator_two_theta;
|
||||
}
|
||||
|
||||
/*
|
||||
crystal
|
||||
*/
|
||||
status = GetDrivablePosition(self->motors[A3], pCon, &val);
|
||||
if (status == 0) {
|
||||
return status;
|
||||
}
|
||||
ang->a3 = val;
|
||||
status = GetDrivablePosition(self->motors[A4], pCon, &val);
|
||||
if (status == 0) {
|
||||
return status;
|
||||
}
|
||||
ang->sample_two_theta = val;
|
||||
status = GetDrivablePosition(self->motors[SGU], pCon, &val);
|
||||
if (status == 0) {
|
||||
return status;
|
||||
}
|
||||
ang->sgu = val;
|
||||
status = GetDrivablePosition(self->motors[SGL], pCon, &val);
|
||||
if (status == 0) {
|
||||
return status;
|
||||
}
|
||||
ang->sgl = val;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*==================== interpreter interface section =================*/
|
||||
static int testMotor(ptasUB pNew, SConnection * pCon, char *name, int idx)
|
||||
{
|
||||
@ -276,7 +227,7 @@ static void updateTargets(ptasUB pNew, SConnection * pCon)
|
||||
{
|
||||
tasAngles ang;
|
||||
|
||||
readTASAngles(pNew, pCon, &ang);
|
||||
readTASMotAngles(pNew, pCon, &ang);
|
||||
calcTasQEPosition(&pNew->machine, ang, &pNew->target);
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
@ -322,7 +273,6 @@ int TasUBFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCWrite(pCon, "ERROR: out of memory creating tasUB", eError);
|
||||
return 0;
|
||||
}
|
||||
memset(pNew->busy, 0, 12 * sizeof(int));
|
||||
|
||||
/*
|
||||
assign motors
|
||||
@ -383,10 +333,6 @@ int TasUBFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
if (pNew->motors[MCV] != NULL && pNew->motors[MCH] != NULL &&
|
||||
pNew->motors[ACV] != NULL && pNew->motors[ACH] != NULL) {
|
||||
pNew->autofocus = 1;
|
||||
}
|
||||
|
||||
status = AddCommand(pSics, argv[1], TasUBWrapper, KillTasUB, pNew);
|
||||
if (status != 1) {
|
||||
@ -441,10 +387,15 @@ static int setCrystalParameters(pmaCrystal crystal, SConnection * pCon,
|
||||
SCparChange(pCon);
|
||||
return 1;
|
||||
} else if (strcmp(argv[2], "ss") == 0) {
|
||||
if (d > .0) {
|
||||
status = (int)d;
|
||||
if (status == 1) {
|
||||
crystal->ss = 1;
|
||||
} else {
|
||||
} else if(status == -1) {
|
||||
crystal->ss = -1;
|
||||
} else {
|
||||
SCPrintf(pCon,eError,
|
||||
"ERROR: %f not allowed for scattering sense, only 1,-1", d);
|
||||
return 0;
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
SCparChange(pCon);
|
||||
@ -459,11 +410,6 @@ static int setCrystalParameters(pmaCrystal crystal, SConnection * pCon,
|
||||
SCSendOK(pCon);
|
||||
SCparChange(pCon);
|
||||
return 1;
|
||||
} else if (strcmp(argv[2], "hb3") == 0) {
|
||||
crystal->HB3 = d;
|
||||
SCSendOK(pCon);
|
||||
SCparChange(pCon);
|
||||
return 1;
|
||||
} else if (strcmp(argv[2], "vb1") == 0) {
|
||||
crystal->VB1 = d;
|
||||
SCSendOK(pCon);
|
||||
@ -504,11 +450,6 @@ static int getCrystalParameters(pmaCrystal crystal, SConnection * pCon,
|
||||
crystal->HB2);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
} else if (strcmp(argv[2], "hb3") == 0) {
|
||||
snprintf(pBueffel, 131, "%s.%s.hb3 = %f", argv[0], argv[1],
|
||||
crystal->HB3);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
} else if (strcmp(argv[2], "vb1") == 0) {
|
||||
snprintf(pBueffel, 131, "%s.%s.vb1 = %f", argv[0], argv[1],
|
||||
crystal->VB1);
|
||||
@ -633,13 +574,8 @@ static void tasListCell(SConnection * pCon, char *name, lattice direct)
|
||||
/*--------------------------------------------------------------------*/
|
||||
static void clearReflections(ptasUB self)
|
||||
{
|
||||
int status;
|
||||
|
||||
status = LLDnodePtr2First(self->reflectionList);
|
||||
while (status != 0) {
|
||||
LLDnodeDelete(self->reflectionList);
|
||||
status = LLDnodePtr2Next(self->reflectionList);
|
||||
}
|
||||
LLDdelete(self->reflectionList);
|
||||
self->reflectionList = LLDcreate(sizeof(tasReflection));
|
||||
self->ubValid = 0;
|
||||
}
|
||||
|
||||
@ -782,7 +718,7 @@ static int addReflection(ptasUB self, SicsInterp * pSics,
|
||||
"WARNING: not all angles given on command line, using positions instead",
|
||||
eWarning);
|
||||
}
|
||||
status = readTASAngles(self, pCon, &r.angles);
|
||||
status = readTASMotAngles(self, pCon, &r.angles);
|
||||
if (status != 1) {
|
||||
return status;
|
||||
}
|
||||
@ -1052,7 +988,7 @@ static void listDiagnostik(ptasUB self, SConnection * pCon)
|
||||
static int addAuxReflection(ptasUB self, SConnection * pCon,
|
||||
SicsInterp * pSics, int argc, char *argv[])
|
||||
{
|
||||
int status;
|
||||
int status, ss;
|
||||
tasReflection r1, r2;
|
||||
float value = -999.99;
|
||||
char pBueffel[256];
|
||||
@ -1108,7 +1044,8 @@ static int addAuxReflection(ptasUB self, SConnection * pCon,
|
||||
r2.qe.kf = self->current.kf;
|
||||
r2.qe.ki = self->current.ki;
|
||||
GetDrivablePosition(self->motors[A3], pCon, &value);
|
||||
r2.angles.a3 = value + 180.;
|
||||
ss = self->machine.ss_sample;
|
||||
r2.angles.a3 = fmod(value + ss*180.,360.) - ss*180.;
|
||||
r2.angles.sgu = .0;
|
||||
r2.angles.sgl = .0;
|
||||
calcTwoTheta(B, r2.qe, self->machine.ss_sample,
|
||||
@ -1280,6 +1217,13 @@ static int calcUB(ptasUB self, SConnection * pCon, SicsInterp * pSics,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!self->outOfPlaneAllowed){
|
||||
r1.angles.sgu = .0;
|
||||
r1.angles.sgl = .0;
|
||||
r2.angles.sgu = .0;
|
||||
r2.angles.sgl = .0;
|
||||
}
|
||||
|
||||
UB = calcTasUBFromTwoReflections(self->cell, r1, r2, &status);
|
||||
if (UB == NULL) {
|
||||
switch (status) {
|
||||
@ -1875,7 +1819,7 @@ int tasUpdate(SConnection * pCon, ptasUB self)
|
||||
int status;
|
||||
tasAngles angles;
|
||||
|
||||
status = readTASAngles(self, pCon, &angles);
|
||||
status = readTASMotAngles(self, pCon, &angles);
|
||||
if (status != 1) {
|
||||
return status;
|
||||
}
|
||||
@ -2153,6 +2097,8 @@ int TasUBWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
self->outOfPlaneAllowed = newSS;
|
||||
invokeUpdate(self,pCon,"main");
|
||||
SCWrite(pCon,"WARNING: You have to recalculate the UB matrix after swapping outofplane mode",
|
||||
eWarning);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else {
|
||||
@ -2216,42 +2162,7 @@ int TasUBWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
}
|
||||
} else if (strcmp(argv[1], "autofocus") == 0) {
|
||||
if (argc > 2) {
|
||||
status = Tcl_GetInt(InterpGetTcl(pSics), argv[2], &(self->autofocus));
|
||||
if (status != TCL_OK) {
|
||||
SCWrite(pCon, "ERROR: failed to convert argument to number",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
snprintf(pBueffel, 131, "%s.autofocus = %d", argv[0], self->autofocus);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
}
|
||||
} else if (strcmp(argv[1], "focusfn") == 0) {
|
||||
if (argc > 2) {
|
||||
strtolower(argv[2]);
|
||||
if (strcmp(argv[2], "theta") == 0) {
|
||||
self->focusfn = THETA_FN;
|
||||
} else if (strcmp(argv[2], "energy") == 0) {
|
||||
self->focusfn = ENERGY_FN;
|
||||
} else {
|
||||
SCWrite(pCon, "ERROR: Arguments should be theta or energy", eError);
|
||||
}
|
||||
} else {
|
||||
switch (self->focusfn) {
|
||||
case ENERGY_FN:
|
||||
snprintf(pBueffel, 131, "%s.focusfn = %s", argv[0], "energy");
|
||||
break;
|
||||
case THETA_FN:
|
||||
snprintf(pBueffel, 131, "%s.focusfn = %s", argv[0], "theta");
|
||||
break;
|
||||
}
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
snprintf(pBueffel, 131, "ERROR: subcommand %s to %s not defined",
|
||||
argv[1], argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
|
Reference in New Issue
Block a user