- First commit of the new UB based TAS calculation. A milestone has been

reached: it handles one test case correctly back and forth
- Fixed oscillation code
- Added a feature for switching off automatic updates in nxupdate
  Autoamtic updates cause problems when scanning...
This commit is contained in:
koennecke
2005-04-22 14:07:06 +00:00
parent 288c65e0bb
commit 6387994017
17 changed files with 1897 additions and 34 deletions

View File

@ -11,23 +11,52 @@
#include "fortify.h"
#include "sics.h"
#include "task.h"
#include "commandlog.h"
#include "oscillate.h"
#define ABS(x) (x < 0 ? -(x) : (x))
/*================== real work =========================================*/
static void StopOscillation(pOscillator self){
assert(self != NULL);
if(self->taskID > 0){
self->pMot->pDriver->Halt(self->pMot->pDriver);
self->stopFlag = 1;
MotorSetPar(self->pMot,self->pCon,"accesscode",(float)self->oldRights);
self->taskID = -1;
}
MotorSetPar(self->pMot,self->pCon,"accesscode",usUser);
if(self->debug > 0){
WriteToCommandLog("oscillator>> ","Stopping");
}
}
/*-------------------------------------------------------------------*/
static float getNextPos(pOscillator self){
float pos;
if(self->nextTargetFlag == 1){
pos = self->upperLimit;
self->nextTargetFlag = 0;
} else {
pos = self->lowerLimit;
self->nextTargetFlag = 1;
}
return pos;
}
/*-------------------------------------------------------------------*/
static float getCurrentTarget(pOscillator self){
float pos;
if(self->nextTargetFlag == 1){
pos = self->lowerLimit;
} else {
pos = self->upperLimit;
}
return pos;
}
/*---------------------------------------------------------------------*/
static int OscillationTask(void *data){
pOscillator self = (pOscillator)data;
int status, code, errStatus;
char error[256];
float pos;
char error[256], message[132];
float pos, curPos;
assert(self);
@ -40,39 +69,43 @@ static int OscillationTask(void *data){
case HWFault:
case HWPosFault:
self->pMot->pDriver->GetError(self->pMot->pDriver,&code,error,255);
SCWrite(self->pCon,error,eError);
if(self->nextTargetFlag == 1){
pos = self->lowerLimit;
} else {
pos = self->upperLimit;
}
WriteToCommandLog("oscillator>> ",error);
pos = getCurrentTarget(self);
errStatus = self->pMot->pDriver->TryAndFixIt(self->pMot->pDriver,code,pos);
self->errorCount++;
if(errStatus == MOTFAIL){
/*
try driving the other way on a serious error
*/
if(self->nextTargetFlag == 1){
pos = self->upperLimit;
self->nextTargetFlag = 0;
} else {
pos = self->lowerLimit;
self->nextTargetFlag = 1;
pos = getNextPos(self);
status = MotorRun(self->pMot,self->pCon,pos);
if(self->debug > 0){
snprintf(message,131,"Started oscillation to %f, ret code = %d",
pos,status);
WriteToCommandLog("oscillator>>",message);
}
MotorRun(self->pMot,self->pCon,pos);
}
break;
case HWWarn:
MotorGetSoftPosition(self->pMot,self->pCon,&curPos);
pos = getCurrentTarget(self);
if(ABS(curPos - pos) < .5){
status = MotorRun(self->pMot,self->pCon,getNextPos(self));
}
break;
case HWBusy:
break;
case HWIdle:
if(self->nextTargetFlag == 1){
pos = self->upperLimit;
self->nextTargetFlag = 0;
} else {
pos = self->lowerLimit;
self->nextTargetFlag = 1;
pos = getNextPos(self);
status = MotorRun(self->pMot,self->pCon,pos);
if(status == OKOK){
self->pMot->pDrivInt->iErrorCount = 0;
}
if(self->debug > 0){
snprintf(message,131,"Started oscillation to %f, ret code = %d",
pos,status);
WriteToCommandLog("oscillator>>",message);
}
MotorRun(self->pMot,self->pCon,pos);
}
return 1;
}
@ -85,16 +118,16 @@ static int StartOscillation(pOscillator self, SConnection *pCon){
assert(self);
if(self->taskID > 0){
SCWrite(pCon,"ERROR: oscillation already running",eError);
return 1;
SCWrite(pCon,"WARNING: oscillation already running",eWarning);
SCWrite(pCon,"WARNING: restarting .. ",eWarning);
StopOscillation(self);
SicsWait(2);
}
MotorGetPar(self->pMot,"softlowerlim",&self->lowerLimit);
self->lowerLimit += .5;
MotorGetPar(self->pMot,"softupperlim",&self->upperLimit);
self->upperLimit -= .5;
MotorGetPar(self->pMot,"accesscode",&fval);
self->oldRights = (int)fval;
MotorSetPar(self->pMot,self->pCon,"accesscode",(float)usInternal);
self->nextTargetFlag = 0;
self->errorCount = 0;
@ -221,6 +254,15 @@ int OscillatorWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
"see commandlog for details");
SCWrite(pCon,pBueffel,eValue);
return 1;
} else if(strcmp(argv[1],"debug") == 0) {
if(argc >= 3){
self->debug = atoi(argv[2]);
SCSendOK(pCon);
return 1;
}
snprintf(pBueffel,255,"%s.debug = %d", argv[0],self->debug);
SCWrite(pCon,pBueffel,eValue);
return 1;
} else if(strcmp(argv[1],"status") == 0) {
if(self->taskID > 0){
snprintf(pBueffel,255,"Oscillation running, %d errors so far, %s",