/* Test pour mettre au point l'algorythme PID */ #include #include #include #include #include #include #include using namespace std; #include "pid.h" static int ads_gettemps(const char *host, const char *port, vector &temps) { glocal temps; (host,port,5); send ("gettemps\n"); if (is_eq(line,"fin")){ end = true; }else{ glocal.temps.push_back(RECORD(line)); } return temps.size() > 0 ? 0 : -1; } static void show_compute (const char *parmname, double value, double parm) { printf ("%-8s = %8.4lf parm = %8.4lf -> %8.4lf\n",parmname,value,parm,parm*value); } int main (int argc, char *argv[]) { glocal int ret = -1; glocal int monitor = 1; glocal double targettemp = 53; // Température cible pour le mode PID glocal double pidparmprop = -0.5; glocal double pidparmdiff = 1; glocal double pidparmintg = -0.1; glocal.ret = (argc,argv); setproginfo ("","0.0","..."); setarg (' ',"targettemp","Température cible",glocal.targettemp,false); setarg (' ',"pidparmprop","Paramètre pour la partie proportionnelle",glocal.pidparmprop,false); setarg (' ',"pidparmintg","Paramètre pour la partie intégrale",glocal.pidparmintg,false); setarg (' ',"pidparmdiff","Paramètre pour la partie différentielle",glocal.pidparmdiff,false); int ret = -1; vector temps; if (ads_gettemps("hangar","43",temps)!=-1){ printf ("temps.size=%zu\n",temps.size()); auto &last = temps.back().temp; double curtemp = last[glocal.monitor]; double prop = curtemp - glocal.targettemp; double intg = ads_intg (temps,glocal.monitor,glocal.targettemp); double diff = ads_diff (temps,glocal.monitor,glocal.targettemp); printf ("curtemp = %8.4lf cible = %8.4lf\n",curtemp,glocal.targettemp); if ((prop < 0 && diff > 0) || (prop > 0 && diff < 0)){ double nbminutes = -(prop/diff); printf (" On atteint la cible dans %8.4lf minutes\n",nbminutes); }else{ printf ("**** on n'atteint pas la cible sans changer la puissance\n"); } show_compute ("prop",prop,glocal.pidparmprop); show_compute ("intg",intg,glocal.pidparmintg); show_compute ("diff",diff,glocal.pidparmdiff); double res = glocal.pidparmprop*prop + glocal.pidparmintg*intg + glocal.pidparmdiff*diff; printf ("res = %8.4lf\n",res); } return ret; return glocal.ret; }