Fixed addauxref for the triple axis code

Added a writing state to status
This commit is contained in:
boa
2014-08-15 13:36:36 +02:00
parent 1d1f102b08
commit 9e898d1476
10 changed files with 142 additions and 30 deletions

View File

@ -1509,7 +1509,7 @@ static int SPutPadding(void *message, void *userData)
*pEnd = '\0';
len = atoi(pPtr);
}
pPtr = malloc(len*sizeof(char));
pPtr = malloc((len+5)*sizeof(char));
if(pPtr != NULL){
memset(pPtr,0,len*sizeof(char));
strncpy(pPtr,pEnd+1,len);
@ -2156,3 +2156,20 @@ int MakeNXScript(SConnection * pCon, SicsInterp * pSics, void *pData,
}
return 1;
}
static pNXScript sysScript= NULL;
/*-----------------------------------------------------------------------------------*/
int isNXScriptWriting(void)
{
if(sysScript == NULL){
sysScript = FindCommandData(pServ->pSics,"nxscript","NXScript");
}
if(sysScript != NULL && sysScript->fileHandle != NULL){
return 1;
} else {
return 0;
}
}

View File

@ -21,6 +21,7 @@ int NXScriptAction(SConnection * pCon, SicsInterp * pSics, void *pData,
char *makeFilename(SicsInterp * pSics, SConnection * pCon);
void changeExtension(char *filename, char *newExtension);
int isNXScriptWriting(void);
/*============== a personal data structure ============================*/
typedef struct {
pObjectDescriptor pDes;

View File

@ -13,4 +13,4 @@ HDFROOT=/afs/psi.ch/project/sinq/sl6
TCLINC=.
#DBG= -g -fstack-protector-all
DBG= -g
DBG= -g

View File

@ -58,7 +58,8 @@
#include "sicshipadaba.h"
#include "messagepipe.h"
#include "scan.h"
#include "exeman.h"
#include "exeman.h"
#include "nxscript.h"
#undef VALUECHANGE
#define VALUECHANGE 2
@ -461,6 +462,18 @@ static int CheckUserWait(void *message, void *userData)
return MPCONTINUE;
}
/*--------------------------------------------------------------------------------*/
static int CheckNXScript(void *message, void *userData)
{
int *status = (int *)message;
if(*status == eEager){
if(isNXScriptWriting()){
*status = eWriting;
}
}
return MPCONTINUE;
}
/*--------------------------------------------------------------------------------*/
static pMP statusPipe = NULL;
static void BuildStatusChain(void)
@ -471,6 +484,7 @@ static void BuildStatusChain(void)
AppendMPFilter(statusPipe,CheckScan,NULL,NULL);
AppendMPFilter(statusPipe,CheckExe,NULL,NULL);
AppendMPFilter(statusPipe,CheckUserWait,NULL,NULL);
AppendMPFilter(statusPipe,CheckNXScript,NULL,NULL);
}
/*-------------------------------------------------------------------------------*/
static int StatusTask(void *data)

12
task.c
View File

@ -26,8 +26,10 @@
#define YIELDING 3
#define IDUNDEFINED 0L
#define TASKMAGIC 777111999
/*--------------------------------------------------------------------------*/
typedef struct __TaskHead {
long magic;
long lID;
long groupID;
int iStatus;
@ -68,6 +70,7 @@ static pTaskHead MakeTaskHead(char *name, TaskFunc pTask, SignalFunc pSignal,
}
memset(pNew, 0, sizeof(TaskHead));
pNew->magic = TASKMAGIC;
pNew->name = strdup(name);
pNew->start_time = time(NULL);
pNew->pRun = pTask;
@ -106,6 +109,7 @@ static void DeleteTaskHead(pTaskHead self)
if (self->pNext != NULL) {
self->pNext->pPrevious = self->pPrevious;
}
memset(self,0,sizeof(TaskHead));
free(self);
}
@ -492,7 +496,7 @@ pTaskHead TaskIteratorStart(pTaskMan self)
/*-----------------------------------------------------------------------------*/
pTaskHead TaskIteratorNext(pTaskHead it)
{
if(it != NULL){
if(it != NULL && it->magic == TASKMAGIC){
return it->pNext;
}
return NULL;
@ -546,7 +550,11 @@ const char * GetTaskName(pTaskHead it)
/*------------------------------------------------------------------------------*/
const void *GetTaskData(pTaskHead it)
{
return (const void*)it->pData;
if(it->magic == TASKMAGIC){
return (const void*)it->pData;
} else {
return NULL;
}
}
/*------------------------------------------------------------------------------*/
long GetTaskGroupID(pTaskMan self)

View File

@ -15,6 +15,7 @@
Mark Koennecke, September 2011
----------------------------------------------------------------------*/
#include <assert.h>
#include <math.h>
#include "sics.h"
#include "lld.h"
#include "SCinter.h"
@ -971,7 +972,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];
@ -1027,7 +1028,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,

View File

@ -184,7 +184,7 @@ double tasAngleBetweenReflections(MATRIX B, tasReflection r1,
chi1 = mat_mul(B, h1);
chi2 = mat_mul(B, h2);
if (chi1 != NULL && chi2 != NULL) {
angle = angleBetween(chi1, chi2);
angle = tasAngleBetween(chi1, chi2);
killVector(chi1);
killVector(chi2);
}
@ -271,8 +271,9 @@ int makeAuxReflection(MATRIX B, tasReflection r1, tasReflection * r2,
r2->qe.ki = r1.qe.ki;
r2->qe.kf = r1.qe.kf;
theta = calcTheta(r1.qe.ki, r1.qe.kf, r1.angles.sample_two_theta);
om = r1.angles.a3 - theta;
theta = calcTheta(r1.qe.ki, r1.qe.kf,
ss*r1.angles.sample_two_theta);
om = r1.angles.a3 - ss*theta;
om += tasAngleBetweenReflections(B, r1, *r2);
QC = tasReflectionToHC(r2->qe, B);
@ -289,12 +290,17 @@ int makeAuxReflection(MATRIX B, tasReflection r1, tasReflection * r2,
return TRIANGLENOTCLOSED;
}
r2->angles.sample_two_theta = ss * Acosd(cos2t);
theta = calcTheta(r1.qe.ki, r1.qe.kf, r2->angles.sample_two_theta);
r2->angles.a3 = om + theta;
theta = calcTheta(r1.qe.ki, r1.qe.kf, ss*r2->angles.sample_two_theta);
r2->angles.a3 = om + ss*theta;
r2->angles.a3 = fmod(r2->angles.a3 + ss*180.,360.) - ss*180.;
/*
r2->angles.a3 -= 180.;
if (r2->angles.a3 < -180.) {
r2->angles.a3 += 360.;
}
*/
mat_free(QC);
return 1;
@ -415,22 +421,16 @@ MATRIX calcPlaneNormalQ(MATRIX UB, tasReflection r1, tasReflection r2)
return planeNormal;
}
/*--------------------------------------------------------------------*/
MATRIX calcTestUB(lattice cell, double om, double sgu, double sgl)
/*--------------------------------------------------------------------
This is shot. The resulting UB is invalid. This needs more throught.
*/
MATRIX calcUBFromAngles(MATRIX B, double om, double sgu, double sgl)
{
MATRIX B, M, N, OM, UB;
MATRIX M, N, OM, UB;
int status;
/*
* create matrices
*/
B = mat_creat(3, 3, ZERO_MATRIX);
status = calculateBMatrix(cell, B);
if (status < 0) {
return NULL;
}
M = mat_creat(3, 3, ZERO_MATRIX);
N = mat_creat(3, 3, ZERO_MATRIX);
OM = mat_creat(3, 3, ZERO_MATRIX);
@ -468,11 +468,30 @@ MATRIX calcTestUB(lattice cell, double om, double sgu, double sgl)
mat_free(OM);
mat_free(N);
mat_free(M);
mat_free(B);
return UB;
}
/*--------------------------------------------------------------------*/
MATRIX calcTestUB(lattice cell, double om, double sgu, double sgl)
{
MATRIX B, UB;
int status;
/*
* create matrices
*/
B = mat_creat(3, 3, ZERO_MATRIX);
status = calculateBMatrix(cell, B);
if (status < 0) {
return NULL;
}
UB = calcUBFromAngles(B,om,sgu,sgl);
mat_free(B);
return UB;
}
/*--------------------------------------------------------------------*/
MATRIX calcTestNormal(double sgu, double sgl)
{
MATRIX M, N, Z, NORM;

View File

@ -186,21 +186,33 @@ MATRIX calcTasUBFromTwoReflections(lattice cell, tasReflection r1,
*/
MATRIX calcTestNormal(double sgu, double sgl);
/**
* calculate a test UB
* @param cell The lattice constant of the crystal
* calculate a test UB from angles
* @param cell The B lattice constants
* @param om A theoretical om for the crystal
* @param sgu A theoretical plane tilt on upper
* @param sgl A theoretical plane tilt on lower
* @return a UB matix on sucess, or NULL on failure. This can only happen
* @return a UB matrix on sucess, or NULL on failure. This can only happen
* when out of memory or with a bad cell
*/
MATRIX calcTestUB(lattice cell, double om, double sgu, double sgl);
/**
* calculate a test UB
* @param B The B matrix as calculated from the cell constants
* @param om A theoretical om for the crystal
* @param sgu A theoretical plane tilt on upper
* @param sgl A theoretical plane tilt on lower
* @return a UB matrix on sucess, or NULL on failure. This can only happen
* when out of memory or with a bad cell
*/
MATRIX calcUBFromAngles(MATRIX B, double om, double sgu, double sgl);
/**
* calcluate the normal to the plane describe by the two reflections r1, r2
* @param r1 first reflection
* @param r2 second reflection
* @return a plane normal on success, NULL else
*/
MATRIX calcPlaneNormal(tasReflection r1, tasReflection r2);
/**
* calcluate the normal to the plane describe by the two reflections r1, r2

View File

@ -189,6 +189,37 @@ double angleBetween(MATRIX v1, MATRIX v2)
}
return angle;
}
/*-----------------------------------------------------------------------
angleBetween gives only angles between 0 - 180. This is also the
only thing there is; the direction of the rotation depends on the
viewpoint and thus is ill defined. This version determines the
sign of the rotation from v3[2]. I made a special version in order not
to trouble other uses of angleBetween.
-----------------------------------------------------------------------*/
double tasAngleBetween(MATRIX v1, MATRIX v2)
{
double angle, angles, sum;
MATRIX v3 = NULL;
int i;
angle = vectorDotProduct(v1, v2) / (vectorLength(v1) * vectorLength(v2));
v3 = vectorCrossProduct(v1, v2);
if (v3 != NULL) {
angles = vectorLength(v3) / (vectorLength(v1) * vectorLength(v2));
angle = Atan2d(angles, angle);
for(i = 0, sum = .0; i < 3; i++){
sum += v3[i][0];
}
if(sum < 0){
angle *= -1.;
}
} else {
angle = Acosd(angle);
}
return angle;
}
/*----------------------------------------------------------------------*/
void scaleVector(MATRIX v, double scale)

View File

@ -91,12 +91,20 @@ MATRIX vectorCrossProduct(MATRIX v1, MATRIX v2);
*/
MATRIX matFromTwoVectors(MATRIX v1, MATRIX v2);
/**
* calculate the nagle between two vectors
* calculate the angle between two vectors
* @param v1 first vector
* @param v2 second vector
* @return angle in degree
*/
double angleBetween(MATRIX v1, MATRIX v2);
/**
* calculate the angle between two vectors. Try to determine the
* sign of the rotation
* @param v1 first vector
* @param v2 second vector
* @return angle in degree
*/
double tasAngleBetween(MATRIX v1, MATRIX v2);
/**
* scale the vector v with scale