- modified and improved various env. drivers
- implemented string array object
This commit is contained in:
252
itcdriv.c
252
itcdriv.c
@ -47,7 +47,13 @@ typedef struct {
|
||||
float gas;
|
||||
float autoGasLimit;
|
||||
float setGas;
|
||||
float prop, integ, deriv;
|
||||
float travelTime; /* travel time for needle valve [sec/100%] */
|
||||
/* control parameters: for ITC / for TESLATRON */
|
||||
float prop; /* proportional value / for slow loop [mbar/K] */
|
||||
float integ; /* integration time / for slow loop [sec] */
|
||||
float deriv; /* deriv. time / int. for pressure [sec] */
|
||||
float prop2; /* TESLATRON only: prop. for pressure [%/mbar] */
|
||||
float lambdaTarget; /* TESLATRON only: lambda stage target temperature */
|
||||
int pidMode;
|
||||
int sampleChan;
|
||||
int controlChan;
|
||||
@ -56,6 +62,8 @@ typedef struct {
|
||||
int remote;
|
||||
int h; /* actual heater channel */
|
||||
int a; /* actual auto mode */
|
||||
time_t lastCtrl;
|
||||
float lastTdiff, lastPdiff;
|
||||
} Itc;
|
||||
|
||||
static ParClass itcClass = { "ITC", sizeof(Itc) };
|
||||
@ -69,6 +77,7 @@ static void ItcParDef(void *object) {
|
||||
int i;
|
||||
static char *ti[4] = {"setp","t1","t2","t3"};
|
||||
static char *modeList[]={"off", "manual", "auto", NULL };
|
||||
static char *progressList[]={"off", "cooling", "ok", NULL };
|
||||
static char *pidList[]={"default", "manual", "auto", NULL };
|
||||
|
||||
ParName("sampleChan");
|
||||
@ -97,6 +106,13 @@ static void ItcParDef(void *object) {
|
||||
} else {
|
||||
ParTail("K");
|
||||
}
|
||||
i = drv->sampleChan;
|
||||
if (drv->dig[i] < 0) {
|
||||
snprintf(fmt, sizeof fmt, "%s", "%.3f");
|
||||
} else {
|
||||
snprintf(fmt, sizeof fmt, "%s.%df", "%", drv->dig[i]);
|
||||
}
|
||||
ParFmt(fmt);
|
||||
ParFloat(&drv->t[drv->sampleChan], PAR_NAN);
|
||||
|
||||
ParName("dig1"); ParAccess(usUser); ParLogAs(NULL); ParInt(&drv->dig[1], -1);
|
||||
@ -145,14 +161,17 @@ static void ItcParDef(void *object) {
|
||||
ParSave(1);
|
||||
EaseUpdate(ITC_SETHTR);
|
||||
ParFloat(&drv->htr, PAR_NAN);
|
||||
}
|
||||
|
||||
ParName("gasMode");
|
||||
ParAccess(usUser); ParEnum(modeList);
|
||||
if (eab->syntax == TESLATRON) {
|
||||
|
||||
ParName("gasMode");
|
||||
ParAccess(usUser); ParEnum(modeList);
|
||||
ParList(NULL);
|
||||
ParInt(&drv->gasMode, 1);
|
||||
|
||||
} else {
|
||||
ParList(""); ParInt(&drv->gasMode, 1);
|
||||
ParName("progress");
|
||||
ParAccess(usUser); ParEnum(progressList);
|
||||
ParList(NULL); ParSave(1);
|
||||
ParInt(&drv->gasMode, 0);
|
||||
}
|
||||
|
||||
ParName("gas");
|
||||
@ -170,6 +189,11 @@ static void ItcParDef(void *object) {
|
||||
EaseUpdate(ITC_SETGAS); ParSave(1);
|
||||
ParFloat(&drv->setGas, 20.0);
|
||||
|
||||
ParName("travelTime"); ParFmt("%.0f"); ParTail("sec");
|
||||
ParList("");
|
||||
ParAccess(usUser); ParSave(1);
|
||||
ParFloat(&drv->travelTime, 100.0);
|
||||
|
||||
if (eab->syntax != TESLATRON) {
|
||||
ParName("autoGasLimit");
|
||||
ParAccess(usUser); ParFmt("%.1f"); ParTail("K"); ParSave(1);
|
||||
@ -195,28 +219,62 @@ static void ItcParDef(void *object) {
|
||||
if (drv->pidMode == 1) ParList("");
|
||||
EaseUpdate(ITC_DERIV);
|
||||
ParFloat(&drv->deriv, PAR_NAN);
|
||||
} else {
|
||||
ParName("lambdaTarget"); ParFmt("%.2f"); ParTail("K");
|
||||
if (drv->gasMode == 0) ParList("");
|
||||
ParAccess(usUser); ParSave(1);
|
||||
ParFloat(&drv->lambdaTarget, 2.2);
|
||||
|
||||
ParName("prop"); ParFmt("%.1f"); ParTail("mbar/K");
|
||||
ParList("");
|
||||
ParAccess(usUser); ParSave(1);
|
||||
ParFloat(&drv->prop, 300);
|
||||
|
||||
ParName("int"); ParFmt("%.1f"); ParTail("mbar/K/min");
|
||||
ParList("");
|
||||
ParAccess(usUser); ParSave(1);
|
||||
ParFloat(&drv->integ, 3.0);
|
||||
|
||||
ParName("prop2"); ParFmt("%.1f"); ParTail("%/mbar");
|
||||
ParList("");
|
||||
ParAccess(usUser); ParSave(1);
|
||||
ParFloat(&drv->prop2, 1.0);
|
||||
|
||||
ParName("int2"); ParFmt("%.1f"); ParTail("%/mbar/min");
|
||||
ParList("");
|
||||
ParAccess(usUser); ParSave(1);
|
||||
ParFloat(&drv->deriv, 2.0);
|
||||
}
|
||||
|
||||
if (drv->controlChan == 0) {
|
||||
i = drv->sampleChan;
|
||||
i = drv->dig[drv->sampleChan];
|
||||
} else {
|
||||
i = drv->controlChan;
|
||||
i = drv->dig[drv->controlChan];
|
||||
}
|
||||
if (drv->dig[i] < 0) {
|
||||
if (i < 0) {
|
||||
snprintf(fmt, sizeof fmt, "%s", "%.3f");
|
||||
} else {
|
||||
snprintf(fmt, sizeof fmt, "%s.%df", "%", drv->dig[i]);
|
||||
if (eab->syntax == TESLATRON) i+=2;
|
||||
snprintf(fmt, sizeof fmt, "%s.%df", "%", i);
|
||||
}
|
||||
|
||||
EaseBasePar(drv);
|
||||
EaseSendPar(drv);
|
||||
if (eab->syntax != TESLATRON) {
|
||||
EaseDrivPar(drv, fmt, "K");
|
||||
} else {
|
||||
EaseDrivPar(drv, fmt, "mbar");
|
||||
}
|
||||
ParStdDef();
|
||||
EaseMsgPar(drv);
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void ItcLcParDef(void *object) {
|
||||
EaseBase *eab = object;
|
||||
eab->syntax = TESLATRON;
|
||||
ItcParDef(object);
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void ItcStatus(Itc *drv) {
|
||||
char *ans;
|
||||
int *code;
|
||||
@ -241,7 +299,7 @@ void ItcStatus(Itc *drv) {
|
||||
} else {
|
||||
drv->h = drv->controlChan;
|
||||
}
|
||||
if (ans[6] != '3' && drv->remote == 2) {
|
||||
if (ans[5] != '3' && drv->remote == 2) {
|
||||
ParPrintf(drv, eError, "ITC switched to local");
|
||||
*code = EASE_FAULT;
|
||||
drv->remote = 1;
|
||||
@ -249,12 +307,48 @@ void ItcStatus(Itc *drv) {
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
float controlPropInt(
|
||||
float diff, /* input (soll-ist for negative loop, ist-soll for positive) */
|
||||
float prop, /* prop (gain) units: [out]/[inp] */
|
||||
float intd, /* int*delta (reset) units: [out]/[inp] */
|
||||
float bandP, /* prop deadband units: [inp] */
|
||||
float bandi, /* integral deadband units: [inp] */
|
||||
float *buffer) /* a buffer to store last diff */ {
|
||||
|
||||
float d, d0;
|
||||
|
||||
bandP = bandP * 0.5;
|
||||
d0 = *buffer;
|
||||
if (fabs(diff) < bandi * 1.01) {
|
||||
intd = 0;
|
||||
}
|
||||
if (diff > d0 + bandP) {
|
||||
d = diff - bandP;
|
||||
} else if (diff < d0 - bandP) {
|
||||
d = diff + bandP;
|
||||
} else {
|
||||
d = d0;
|
||||
}
|
||||
*buffer = d;
|
||||
return prop * (d - d0) + intd * diff;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void controlLimits(float *inp, float min, float max) {
|
||||
if (*inp > max) {
|
||||
*inp = max;
|
||||
} else if (*inp < min) {
|
||||
*inp = min;
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static long ItcRead(long pc, void *object) {
|
||||
Itc *drv = ParCast(&itcClass, object);
|
||||
EaseBase *eab = object;
|
||||
char *p;
|
||||
int l;
|
||||
time_t now, delta;
|
||||
char buf[4];
|
||||
float gas, band;
|
||||
|
||||
switch (pc) { default: /* FSM BEGIN *******************************/
|
||||
EaseWrite(eab, "X");
|
||||
@ -286,7 +380,7 @@ static long ItcRead(long pc, void *object) {
|
||||
EaseWrite(eab, "R0"); /* read control T */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
drv->t[0] = OxiGet(eab, drv->dig[drv->controlChan], NULL, drv->t[0]);
|
||||
if (drv->gasMode == 2) {
|
||||
if (drv->gasMode == 2 && eab->syntax != TESLATRON) {
|
||||
if (drv->t[drv->controlChan] > drv->autoGasLimit + 1.0) {
|
||||
if (drv->a < 2) {
|
||||
drv->a |= 2; /* switch gas to auto */
|
||||
@ -303,9 +397,14 @@ static long ItcRead(long pc, void *object) {
|
||||
} else {
|
||||
goto skip0;
|
||||
}
|
||||
}
|
||||
if (drv->setGas != drv->gas) {
|
||||
EaseSetUpdate(drv, ITC_SETGAS, 1);
|
||||
if (drv->setGas != drv->gas) {
|
||||
EaseSetUpdate(drv, ITC_SETGAS, 1);
|
||||
}
|
||||
} else {
|
||||
if (drv->setGas != drv->gas) {
|
||||
EaseSetUpdate(drv, ITC_SETGAS, 1);
|
||||
}
|
||||
goto skip0;
|
||||
}
|
||||
}
|
||||
} else if (drv->a < 2) {
|
||||
@ -321,13 +420,80 @@ static long ItcRead(long pc, void *object) {
|
||||
EaseWrite(eab, buf);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
skip0:
|
||||
|
||||
EaseWrite(eab, "R7"); /* read gas flow */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
gas = OxiGet(eab, 1, NULL, drv->gas);
|
||||
|
||||
time(&now);
|
||||
delta = now - drv->lastCtrl;
|
||||
drv->lastCtrl = now;
|
||||
|
||||
if (drv->gas == PAR_NAN) {
|
||||
drv->gas = gas;
|
||||
} else {
|
||||
if (drv->travelTime < 1) drv->travelTime = 1;
|
||||
if (drv->gas < gas) {
|
||||
drv->gas += delta * 100.0 / drv->travelTime;
|
||||
if (drv->gas > gas) drv->gas = gas;
|
||||
} else {
|
||||
drv->gas -= delta * 100.0 / drv->travelTime;
|
||||
if (drv->gas < gas) drv->gas = gas;
|
||||
}
|
||||
}
|
||||
|
||||
if (eab->syntax != TESLATRON || drv->gasMode <= 0) goto skipFlow;
|
||||
if (delta > 10) delta=10;
|
||||
|
||||
if (drv->prop <= 0) {
|
||||
band = 0.1;
|
||||
} else {
|
||||
band = (drv->d.upperLimit - drv->d.lowerLimit) / drv->prop;
|
||||
}
|
||||
if (drv->t[2] - drv->lambdaTarget > band) {
|
||||
drv->gasMode = 1;
|
||||
}
|
||||
if (drv->gasMode == 1) {
|
||||
drv->d.targetValue = drv->d.upperLimit;
|
||||
if (drv->t[2] <= drv->lambdaTarget + 0.001) {
|
||||
drv->gasMode = 2;
|
||||
drv->d.targetValue = drv->d.lowerLimit;
|
||||
}
|
||||
} else {
|
||||
drv->d.targetValue +=
|
||||
controlPropInt(drv->t[2] - drv->lambdaTarget,
|
||||
drv->prop, drv->integ*delta/60.0, 0.01, 0.01, &drv->lastTdiff);
|
||||
band = 0.01 * drv->prop;
|
||||
controlLimits(&drv->d.targetValue,
|
||||
drv->d.lowerLimit - band, drv->d.upperLimit + band);
|
||||
}
|
||||
|
||||
drv->setGas +=
|
||||
controlPropInt(drv->d.targetValue - drv->t[1],
|
||||
drv->prop2, drv->deriv*delta/60.0, drv->d.tolerance, 0.1, &drv->lastPdiff);
|
||||
controlLimits(&drv->setGas, 0.0, 99.9);
|
||||
|
||||
if (fabsf(drv->setGas - gas) < 0.1) goto skipFlow;
|
||||
EaseParHasChanged();
|
||||
|
||||
if (drv->remote == 2) goto skipActive;
|
||||
EaseWrite(eab, "C3");
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
drv->remote = 2;
|
||||
skipActive:
|
||||
|
||||
if (!drv->remote) goto skiprmt;
|
||||
OxiSet(eab, "G", drv->setGas, 1); /* cold valve setting */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
skipFlow:
|
||||
|
||||
if (!drv->remote || eab->syntax == TESLATRON) goto skiprmt;
|
||||
EaseWrite(eab, "C0");
|
||||
drv->remote = 0;
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
skiprmt:
|
||||
|
||||
if (eab->syntax == TESLATRON) goto skipctrl;
|
||||
|
||||
if (EaseGetUpdate(drv, ITC_SETHTR)) goto skiphtr;
|
||||
EaseWrite(eab, "R5"); /* read heater */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
@ -335,11 +501,6 @@ static long ItcRead(long pc, void *object) {
|
||||
drv->htr = OxiGet(eab, 1, NULL, drv->htr);
|
||||
skiphtr:
|
||||
|
||||
EaseWrite(eab, "R7"); /* read gas flow */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
drv->gas = OxiGet(eab, 1, NULL, drv->gas);
|
||||
skipgas:
|
||||
|
||||
if (EaseGetUpdate(drv, ITC_PROP)) goto skipprop;
|
||||
EaseWrite(eab, "R9"); /* read prop */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
@ -360,7 +521,8 @@ static long ItcRead(long pc, void *object) {
|
||||
if (EaseGetUpdate(drv, ITC_DERIV)) goto skipderiv;
|
||||
drv->deriv = OxiGet(eab, 1, NULL, drv->deriv);
|
||||
skipderiv:
|
||||
|
||||
|
||||
skipctrl:
|
||||
ParLog(drv);
|
||||
fsm_quit: return 0; } /* FSM END *********************************/
|
||||
}
|
||||
@ -418,7 +580,6 @@ static long ItcSetTemp(long pc, void *object) {
|
||||
if (drv->h == drv->controlChan) goto skiph;
|
||||
EaseWrite(eab, "A0"); /* heater off */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
drv->remote = 2;
|
||||
snprintf(buf, sizeof buf, "H%d", drv->controlChan);
|
||||
EaseWrite(eab, buf); /* set heater to channel */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
@ -481,7 +642,7 @@ static long ItcSetGas(long pc, void *object) {
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
EaseWrite(eab, "R7"); /* read gas flow */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
drv->gas = OxiGet(eab, 1, NULL, drv->gas);
|
||||
drv->setGas = OxiGet(eab, 1, NULL, drv->setGas);
|
||||
if (drv->a < 2) goto quit;
|
||||
snprintf(buf, sizeof buf, "A%d", drv->a);
|
||||
EaseWrite(eab, buf);
|
||||
@ -519,24 +680,28 @@ static long ItcSet(long pc, void *object) {
|
||||
EaseWrite(eab, "C3");
|
||||
loop:
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
drv->remote = 2;
|
||||
upd = EaseNextUpdate(drv);
|
||||
switch (upd) {
|
||||
case EASE_RUN: FsmCall(ItcSetTemp); goto loop;
|
||||
case ITC_SETHTR: FsmCall(ItcSetHtr); goto loop;
|
||||
case ITC_SETGAS: FsmCall(ItcSetGas); goto loop;
|
||||
case ITC_PIDMODE:
|
||||
if (drv->pidMode == 1) {
|
||||
EaseWrite(eab, "L0");
|
||||
} else {
|
||||
EaseWrite(eab, "L1");
|
||||
drv->pidMode = 2;
|
||||
}
|
||||
goto loop;
|
||||
case ITC_PROP: OxiSet(eab, "P", drv->prop, 1); goto loop;
|
||||
case ITC_INTEG: OxiSet(eab, "I", drv->prop, 1); goto loop;
|
||||
case ITC_DERIV: OxiSet(eab, "D", drv->prop, 1); goto loop;
|
||||
default: break;
|
||||
if (eab->syntax != TESLATRON) {
|
||||
switch (upd) {
|
||||
case EASE_RUN: FsmCall(ItcSetTemp); goto loop;
|
||||
case ITC_SETHTR: FsmCall(ItcSetHtr); goto loop;
|
||||
case ITC_SETGAS: FsmCall(ItcSetGas); goto loop;
|
||||
case ITC_PIDMODE:
|
||||
if (drv->pidMode == 1) {
|
||||
EaseWrite(eab, "L0");
|
||||
} else {
|
||||
EaseWrite(eab, "L1");
|
||||
drv->pidMode = 2;
|
||||
}
|
||||
goto loop;
|
||||
case ITC_PROP: OxiSet(eab, "P", drv->prop, 1); goto loop;
|
||||
case ITC_INTEG: OxiSet(eab, "I", drv->prop, 1); goto loop;
|
||||
case ITC_DERIV: OxiSet(eab, "D", drv->prop, 1); goto loop;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (eab->syntax == TESLATRON && drv->gasMode > 0) goto quit;
|
||||
EaseWrite(eab, "C0");
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
drv->remote = 0;
|
||||
@ -568,10 +733,13 @@ static int ItcInitLc(SConnection *con, int argc, char *argv[], int dynamic) {
|
||||
Itc *drv;
|
||||
|
||||
drv = EaseMakeDriv(con, &itcClass, argc, argv, dynamic, 7,
|
||||
ItcParDef, OxiHandler, ItcStart, NULL, ItcRead,
|
||||
ItcLcParDef, OxiHandler, ItcStart, NULL, ItcRead,
|
||||
ItcSet);
|
||||
if (drv == NULL) return 0;
|
||||
drv->d.b.syntax = TESLATRON;
|
||||
drv->lastCtrl = 0;
|
||||
drv->lastTdiff = 0;
|
||||
drv->lastPdiff = 0;
|
||||
ParPrintf(drv, eValue, "OI Lambda Controller");
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user