From 50a2545f97b312882545a88ac46cdd5d049310b2 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Sun, 28 Apr 2013 16:28:02 +1000 Subject: [PATCH] tasdrive now only monitors motors which are driving. Fixes SICS-568 Because tasdrive now stops calling status checking on a motor which has terminated for any reason. SICS-570: The correct motor names are now reported by tasdrive. SICS-575: Use ANSTO motor names when reporting limit violations. --- tasdrive.c | 108 +++++++++++++++++++++++++++++++++++------------------ tasub.c | 9 +++++ tasub.h | 2 + 3 files changed, 82 insertions(+), 37 deletions(-) diff --git a/tasdrive.c b/tasdrive.c index 0d5cdd54..d4d6b96b 100644 --- a/tasdrive.c +++ b/tasdrive.c @@ -313,36 +313,44 @@ static int startMotors(ptasMot self, tasAngles angles, /* monochromator */ - status = startTASMotor(self->math->motors[A1], pCon, "a1", + status = startTASMotor(self->math->motors[A1], pCon, self->math->motname[A1], angles.monochromator_two_theta / 2., silent, stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A1] = 1; } - status = startTASMotor(self->math->motors[A2], pCon, "a2", + status = startTASMotor(self->math->motors[A2], pCon, self->math->motname[A2], angles.monochromator_two_theta, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A2] = 1; } if (self->math->motors[MCV] != NULL) { curve = maCalcVerticalCurvature(self->math->machine.monochromator, angles.monochromator_two_theta); - status = startTASMotor(self->math->motors[MCV], pCon, "mcv", + status = startTASMotor(self->math->motors[MCV], pCon, self->math->motname[MCV], curve, silent,stopFixed); if (status != OKOK) { SCWrite(pCon,"WARNING: monochromator vertical curvature motor failed to start", eLog); SCSetInterrupt(pCon,eContinue); + } else { + self->math->busy[MCV] = 1; } } if (self->math->motors[MCH] != NULL) { curve = maCalcHorizontalCurvature(self->math->machine.monochromator, angles.monochromator_two_theta); - status = startTASMotor(self->math->motors[MCH], pCon, "mch", + status = startTASMotor(self->math->motors[MCH], pCon, self->math->motname[MCH], curve, silent,stopFixed); if (status != OKOK) { SCWrite(pCon,"WARNING: monochromator horizontal curvature motor failed to start", eLog); SCSetInterrupt(pCon,eContinue); + } else { + self->math->busy[MCH] = 1; } } @@ -351,35 +359,43 @@ static int startMotors(ptasMot self, tasAngles angles, analyzer */ if (self->math->tasMode != ELASTIC) { - status = startTASMotor(self->math->motors[A5], pCon, "a5", + status = startTASMotor(self->math->motors[A5], pCon, self->math->motname[A5], angles.analyzer_two_theta / 2.0, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A5] = 1; } - status = startTASMotor(self->math->motors[A6], pCon, "a6", + status = startTASMotor(self->math->motors[A6], pCon, self->math->motname[A6], angles.analyzer_two_theta, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A6] = 1; } if (self->math->motors[ACV] != NULL) { curve = maCalcVerticalCurvature(self->math->machine.analyzer, angles.analyzer_two_theta); - status = startTASMotor(self->math->motors[ACV], pCon, "acv", + status = startTASMotor(self->math->motors[ACV], pCon, self->math->motname[ACV], curve, silent,stopFixed); if (status != OKOK) { SCWrite(pCon,"WARNING: analyzer vertical curvature motor failed to start", eLog); SCSetInterrupt(pCon,eContinue); + } else { + self->math->busy[ACV] = 1; } } if (self->math->motors[ACH] != NULL) { curve = maCalcHorizontalCurvature(self->math->machine.analyzer, angles.analyzer_two_theta); - status = startTASMotor(self->math->motors[ACH], pCon, "ach", + status = startTASMotor(self->math->motors[ACH], pCon, self->math->motname[ACH], curve, silent,stopFixed); if (status != OKOK) { SCWrite(pCon,"WARNING: analyzer horizontal curvature motor failed to start", eLog); SCSetInterrupt(pCon,eContinue); + } else { + self->math->busy[ACH] = 1; } } } @@ -391,27 +407,35 @@ static int startMotors(ptasMot self, tasAngles angles, /* crystal */ - status = startTASMotor(self->math->motors[A3], pCon, "a3", + status = startTASMotor(self->math->motors[A3], pCon, self->math->motname[A3], angles.a3, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A3] = 1; } - status = startTASMotor(self->math->motors[A4], pCon, "a4", + status = startTASMotor(self->math->motors[A4], pCon, self->math->motname[A4], angles.sample_two_theta, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A4] = 1; } if (driveTilt == 1) { - status = startTASMotor(self->math->motors[SGL], pCon, "sgl", + status = startTASMotor(self->math->motors[SGL], pCon, self->math->motname[SGL], angles.sgl, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[SGL] = 1; } - status = startTASMotor(self->math->motors[SGU], pCon, "sgu", + status = startTASMotor(self->math->motors[SGU], pCon, self->math->motname[SGU], angles.sgu, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[SGU] = 1; } } self->math->mustDrive = 0; @@ -435,7 +459,7 @@ static int checkQMotorLimits(ptasMot self, SConnection * pCon, angles.a3, error,131); if (status != 1) { retVal = 0; - snprintf(pBueffel, 256, "ERROR: limit violation an a3: %s", error); + snprintf(pBueffel, 256, "ERROR: limit violation an %s: %s", self->math->motname[A3], error); SCWrite(pCon, pBueffel, eLogError); } } @@ -447,7 +471,7 @@ static int checkQMotorLimits(ptasMot self, SConnection * pCon, error, 131); if (status != 1) { retVal = 0; - snprintf(pBueffel, 256, "ERROR: limit violation an a4: %s", error); + snprintf(pBueffel, 256, "ERROR: limit violation an %s: %s", self->math->motname[A4], error); SCWrite(pCon, pBueffel, eLogError); } @@ -458,7 +482,7 @@ static int checkQMotorLimits(ptasMot self, SConnection * pCon, 131); if (status != 1) { retVal = 0; - snprintf(pBueffel, 256, "ERROR: limit violation an SGU: %s", error); + snprintf(pBueffel, 256, "ERROR: limit violation an %s: %s", self->math->motname[SGU], error); SCWrite(pCon, pBueffel, eLogError); } @@ -468,7 +492,7 @@ static int checkQMotorLimits(ptasMot self, SConnection * pCon, 131); if (status != 1) { retVal = 0; - snprintf(pBueffel, 256, "ERROR: limit violation an SGL: %s", error); + snprintf(pBueffel, 256, "ERROR: limit violation an %s: %s", self->math->motname[SGU], error); SCWrite(pCon, pBueffel, eLogError); } } @@ -559,7 +583,7 @@ static int calculateAndDrive(ptasMot self, SConnection * pCon) static int checkMotors(ptasMot self, SConnection * pCon) { int i, status, length = 12, count; - int mask[12], busy[12]; + int mask[12]; pIDrivable pDrivInt = NULL; self->math->mustRecalculate = 1; @@ -567,10 +591,8 @@ static int checkMotors(ptasMot self, SConnection * pCon) length = 8; } memset(mask, 0, 12 * sizeof(int)); - memset(busy, 0, 12 * sizeof(int)); for (i = 0; i < length; i++) { mask[i] = 1; - busy[i] = 1; } if (self->math->outOfPlaneAllowed == 0) { mask[SGU] = 0; @@ -578,22 +600,16 @@ static int checkMotors(ptasMot self, SConnection * pCon) } for (i = 0; i < 12; i++) { - if(self->math->motors[i] == NULL){ - busy[i] = 0; - } else { - if(mask[i] != 0) { + if(mask[i] != 0 && self->math->busy[i] != 0) { pDrivInt = GetDrivableInterface(self->math->motors[i]); status = pDrivInt->CheckStatus(self->math->motors[i], pCon); if(status == HWIdle || status == OKOK || status == HWFault || status == HWPosFault){ - busy[i] = 0; - } - } else { - busy[i] = 0; + self->math->busy[i] = 0; } } } for(i = 0, count = 0; i < 12; i++){ - count += busy[i]; + count += self->math->busy[i]; } if(count == 0) { return HWIdle; @@ -635,34 +651,42 @@ static int startQMMotors(ptasMot self, tasAngles angles, /* monochromator */ - status = startTASMotor(self->math->motors[A1], pCon, "a1", + status = startTASMotor(self->math->motors[A1], pCon, self->math->motname[A1], angles.monochromator_two_theta / 2., silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A1] = 1; } - status = startTASMotor(self->math->motors[A2], pCon, "a2", + status = startTASMotor(self->math->motors[A2], pCon, self->math->motname[A2], angles.monochromator_two_theta, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A2] = 1; } if (self->math->motors[MCV] != NULL) { curve = maCalcVerticalCurvature(self->math->machine.monochromator, angles.monochromator_two_theta); - status = startTASMotor(self->math->motors[MCV], pCon, "mcv", + status = startTASMotor(self->math->motors[MCV], pCon, self->math->motname[MCV], curve, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[MCV] = 1; } } if (self->math->motors[MCH] != NULL) { curve = maCalcHorizontalCurvature(self->math->machine.monochromator, angles.monochromator_two_theta); - status = startTASMotor(self->math->motors[MCH], pCon, "mch", + status = startTASMotor(self->math->motors[MCH], pCon, self->math->motname[MCH], curve, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[MCH] = 1; } } @@ -670,43 +694,53 @@ static int startQMMotors(ptasMot self, tasAngles angles, /* analyzer */ - status = startTASMotor(self->math->motors[A5], pCon, "a5", + status = startTASMotor(self->math->motors[A5], pCon, self->math->motname[A5], angles.analyzer_two_theta / 2.0, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A5] = 1; } - status = startTASMotor(self->math->motors[A6], pCon, "a6", + status = startTASMotor(self->math->motors[A6], pCon, self->math->motname[A6], angles.analyzer_two_theta, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A6] = 1; } if (self->math->motors[ACV] != NULL) { curve = maCalcVerticalCurvature(self->math->machine.analyzer, angles.analyzer_two_theta); - status = startTASMotor(self->math->motors[ACV], pCon, "acv", + status = startTASMotor(self->math->motors[ACV], pCon, self->math->motname[ACV], curve, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[ACV] = 1; } } if (self->math->motors[ACH] != NULL) { curve = maCalcHorizontalCurvature(self->math->machine.analyzer, angles.analyzer_two_theta); - status = startTASMotor(self->math->motors[ACH], pCon, "ach", + status = startTASMotor(self->math->motors[ACH], pCon, self->math->motname[ACH], curve, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[ACH] = 1; } } /* crystal */ - status = startTASMotor(self->math->motors[A4], pCon, "a4", + status = startTASMotor(self->math->motors[A4], pCon, self->math->motname[A4], angles.sample_two_theta, silent,stopFixed); if (status != OKOK) { return status; + } else { + self->math->busy[A4] = 1; } self->math->mustDrive = 0; diff --git a/tasub.c b/tasub.c index 0d046f83..3e15c722 100644 --- a/tasub.c +++ b/tasub.c @@ -304,6 +304,7 @@ int TasUBFactory(SConnection * pCon, SicsInterp * pSics, void *pData, "ef", "kf", "en" }; + char *defltMot[] = {"a1", "a2", "mcv", "mch", "a3", "a4", "sgu", "sgl", "a5", "a6", "acv", "ach"}; if (argc < 2) { SCWrite(pCon, "ERROR: need name to install tasUB", eError); @@ -319,6 +320,7 @@ 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 @@ -339,6 +341,10 @@ int TasUBFactory(SConnection * pCon, SicsInterp * pSics, void *pData, pNew->motors[9] = TasFindMotor(pSics, "a6"); pNew->motors[10] = TasFindMotor(pSics, "acv"); pNew->motors[11] = TasFindMotor(pSics, "ach"); + for (i=0; i < 12; i++) { + strcpy(pNew->motname[i], defltMot[i]); + } + } else { /* * user defined names @@ -355,6 +361,9 @@ int TasUBFactory(SConnection * pCon, SicsInterp * pSics, void *pData, pNew->motors[9] = TasFindMotor(pSics, argv[11]); pNew->motors[10] = TasFindMotor(pSics, argv[12]); pNew->motors[11] = TasFindMotor(pSics, argv[13]); + for (i=0; i < 12; i++) { + strcpy(pNew->motname[i], argv[i+2]); + } } /* curvature motors may be missing, anything else is a serious problem diff --git a/tasub.h b/tasub.h index a60af51f..0d4ba3e5 100644 --- a/tasub.h +++ b/tasub.h @@ -29,6 +29,8 @@ int mustDrive; int mustDriveQ; pMotor motors[12]; + char motname[12][32]; + int busy[12]; tasReflection r1, r2; int ubValid; int silent;