PID&Relays field tests & debug

This commit is contained in:
2021-12-29 20:25:49 +03:00
parent bc867d0de0
commit 1316835cad
7 changed files with 56 additions and 18 deletions

View File

@@ -336,6 +336,28 @@ int Item::getArg(short n) //Return arg int or first array element if Arg is arra
else return 0;//-2; else return 0;//-2;
} }
float Item::getFloatArg(short n) //Return arg float or first array element if Arg is array
{
if (!itemArg) return 0;//-1;
if (!n)
{
if (itemArg->type == aJson_Int) return itemArg->valueint;
else if (itemArg->type == aJson_Float) return itemArg->valuefloat;
else return 0;
}
if ((itemArg->type == aJson_Array) && ( n < aJson.getArraySize(itemArg)))
{
aJsonObject * obj = aJson.getArrayItem(itemArg, n);
if (obj->type == aJson_Int) return obj->valueint;
if (obj->type == aJson_Float) return obj->valuefloat;
return 0;
}
else return 0;//-2;
}
short Item::getArgCount() short Item::getArgCount()
{ {
if (!itemArg) return 0; if (!itemArg) return 0;

View File

@@ -119,6 +119,7 @@ class Item
int Ctrl(char * payload, char * subItem=NULL); int Ctrl(char * payload, char * subItem=NULL);
int getArg(short n=0); int getArg(short n=0);
float getFloatArg(short n=0);
short getArgCount(); short getArgCount();
//int getVal(short n); //From VAL array. Negative if no array //int getVal(short n); //From VAL array. Negative if no array
long int getVal(); //From int val OR array long int getVal(); //From int val OR array

View File

@@ -2573,7 +2573,7 @@ void thermoLoop(void) {
if (tStore.timestamp16) //Valid temperature if (tStore.timestamp16) //Valid temperature
{ {
if (isTimeOver(tStore.timestamp16,millisNZ(8) & 0xFFFF,PERIOD_THERMOSTAT_FAILED,0xFFFF)) if (isTimeOver(tStore.timestamp16,millisNZ(8) & 0xFFFF,PERIOD_THERMOSTAT_FAILED >> 8,0xFFFF))
{ {
errorSerial<<thermoItem->name<<F(" Alarm Expired\n"); errorSerial<<thermoItem->name<<F(" Alarm Expired\n");
mqttClient.publish("/alarm/snsr", thermoItem->name); mqttClient.publish("/alarm/snsr", thermoItem->name);

View File

@@ -423,6 +423,7 @@ int out_Modbus::getChanType()
int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute) int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
{ {
return 0;
//int chActive = item->isActive(); //int chActive = item->isActive();
//bool toExecute = (chActive>0); //bool toExecute = (chActive>0);
//itemCmd st(ST_UINT32,CMD_VOID); //itemCmd st(ST_UINT32,CMD_VOID);
@@ -431,9 +432,9 @@ aJsonObject *templateParamObj = NULL;
short mappedCmdVal = 0; short mappedCmdVal = 0;
// trying to find parameter in template with name == subItem (NB!! standard suffixes dint working here) // trying to find parameter in template with name == subItem (NB!! standard suffixes dint working here)
if (subItem && strlen (subItem)) templateParamObj = aJson.getObjectItem(store->parameters, subItem); if (subItem && strlen (subItem) && store) templateParamObj = aJson.getObjectItem(store->parameters, subItem);
if (!templateParamObj) if (!templateParamObj && store)
{ {
// Trying to find template parameter where id == suffixCode // Trying to find template parameter where id == suffixCode
templateParamObj = store->parameters->child; templateParamObj = store->parameters->child;

View File

@@ -30,24 +30,32 @@ bool out_pid::getConfig()
} }
double outMin=0.; //UNUSED double outMin=0.; //UNUSED
double outMax=255.;//UNUSED double outMax=255.;//UNUSED
unsigned int alarmTO=0; float dT=5.;
uint32_t alarmTO=PERIOD_THERMOSTAT_FAILED;
aJsonObject * param; aJsonObject * param;
switch (aJson.getArraySize(kPIDObj)) switch (aJson.getArraySize(kPIDObj))
{ case 7: //kP,kI,kD, alarmTO, alarmVal, outMin, outMax { case 8: //kP,kI,kD,dT, alarmTO, alarmVal, outMin, outMax
param = aJson.getArrayItem(kPIDObj, 6); param = aJson.getArrayItem(kPIDObj, 7);
if (param->type == aJson_Float) outMax=param->valuefloat; if (param->type == aJson_Float) outMax=param->valuefloat;
else if (param->type == aJson_Int) outMax=param->valueint; else if (param->type == aJson_Int) outMax=param->valueint;
case 6: //kP,kI,kD, alarmTO, alarmVal, outMin case 7: //kP,kI,kD,dT alarmTO, alarmVal, outMin
param = aJson.getArrayItem(kPIDObj, 5); param = aJson.getArrayItem(kPIDObj, 6);
if (param->type == aJson_Float) outMin=param->valuefloat; if (param->type == aJson_Float) outMin=param->valuefloat;
else if (param->type == aJson_Int) outMin=param->valueint; else if (param->type == aJson_Int) outMin=param->valueint;
case 5: //kP,kI,kD, alarmTO, alarmVal case 6: //kP,kI,kD,dT, alarmTO, alarmVal
case 4: //kP,kI,kD, alarmTO case 5: //kP,kI,kD,dT, alarmTO
param = aJson.getArrayItem(kPIDObj, 4);
if (param->type == aJson_Float) alarmTO=param->valuefloat;
else if (param->type == aJson_Int) alarmTO=param->valueint;
case 4: //kP,kI,kD,dT
param = aJson.getArrayItem(kPIDObj, 3); param = aJson.getArrayItem(kPIDObj, 3);
if (param->type == aJson_Int) alarmTO=param->valueint; if (param->type == aJson_Float) dT=param->valuefloat;
else if (param->type == aJson_Int) dT=param->valueint;
case 3: //kP,kI,kD case 3: //kP,kI,kD
param = aJson.getArrayItem(kPIDObj, 2); param = aJson.getArrayItem(kPIDObj, 2);
if (param->type == aJson_Float) kD=param->valuefloat; if (param->type == aJson_Float) kD=param->valuefloat;
@@ -88,7 +96,7 @@ bool out_pid::getConfig()
if (!store->pid) return false; if (!store->pid) return false;
store->pid->SetMode(AUTOMATIC); store->pid->SetMode(AUTOMATIC);
//store->pid->SetOutputLimits(outMin,outMax); //store->pid->SetOutputLimits(outMin,outMax);
store->pid->SetSampleTime(5000); store->pid->SetSampleTime(dT*1000.0);
store->alarmTimer=millis(); store->alarmTimer=millis();
store->alarmArmed=false; store->alarmArmed=false;
store->alarmTimeout=alarmTO; //in sec store->alarmTimeout=alarmTO; //in sec
@@ -161,6 +169,8 @@ if (store && store->pid && (Status() == CST_INITIALIZED) && item && (item->getCm
if (item->getCmd() != CMD_OFF) if (item->getCmd() != CMD_OFF)
{ {
if(store->pid->Compute() && !store->alarmArmed) if(store->pid->Compute() && !store->alarmArmed)
{
debugSerial<<F("PID ")<<item->itemArr->name<<F("- set:")<<store->setpoint<<F(" in:")<<store->input<<(" out:") << store->output<<endl;
if (abs(store->output-store->prevOut)>OUTPUT_TRESHOLD) if (abs(store->output-store->prevOut)>OUTPUT_TRESHOLD)
{ {
aJsonObject * oCmd = aJson.getArrayItem(item->itemArg, 1); aJsonObject * oCmd = aJson.getArrayItem(item->itemArg, 1);
@@ -169,8 +179,8 @@ if (store && store->pid && (Status() == CST_INITIALIZED) && item && (item->getCm
executeCommand(oCmd,-1,value); executeCommand(oCmd,-1,value);
store->prevOut=store->output; store->prevOut=store->output;
} }
}
if(!store->alarmArmed && isTimeOver(store->alarmTimer,millis(),store->alarmTimeout*1000) ) if(!store->alarmArmed && store->alarmTimeout && isTimeOver(store->alarmTimer,millis(),store->alarmTimeout*1000) )
{ {
store->alarmArmed=true; store->alarmArmed=true;
alarm(true); alarm(true);

View File

@@ -13,6 +13,8 @@ static int driverStatus = CST_UNKNOWN;
void out_relay::getConfig() void out_relay::getConfig()
{ {
inverted=false; inverted=false;
if (!item) return;
pin=item->getArg(0); pin=item->getArg(0);
if (pin<0) if (pin<0)
{ {
@@ -20,7 +22,9 @@ void out_relay::getConfig()
inverted=true; inverted=true;
} }
if(pin==0 || pin>=PINS_COUNT) pin=32; if(pin==0 || pin>=PINS_COUNT) pin=32;
period = item->getArg(1);
period = item->getFloatArg(1)*1000.0;
if (!period) period = 5000UL;
} }

View File

@@ -72,7 +72,7 @@
#define TIMEOUT_REINIT 5000UL #define TIMEOUT_REINIT 5000UL
#define TIMEOUT_RETAIN 8000UL #define TIMEOUT_RETAIN 8000UL
#define INTERVAL_1W 5000UL #define INTERVAL_1W 5000UL
#define PERIOD_THERMOSTAT_FAILED (600 * 1000UL)>>8 #define PERIOD_THERMOSTAT_FAILED (600 * 1000UL)
//#define T_ATTEMPTS 200 //#define T_ATTEMPTS 200
//#define IET_TEMP 0 //#define IET_TEMP 0