/*\ * Simulacije sistemov - vaja 3d * Kaskadna regulacija nivoja posode * $Id: sim3d.c,v 1.1 1994/05/05 09:29:43 $ \*/ #include <stdio.h> #include <math.h> #define KPg 4.965 /* Parametri */ #define KIg 0.239 /* glavnega */ #define KDg 28.414 /* regulatorja */ #define KPp 2.0 /* Pomo"zni reg.*/ #define TFIN 200.0 /* Kon"cni "cas */ #define DT 0.005 /* delta time */ #define NTHELEM 100 /* izpis n-tega "casa */ static float t, tc, e, ee, p, i, d, x, z, fiv; static float h3ref, fi1d, fi1, fi1i, h3dd, h3d, h3, itae; static short n; static void initialize (void) { tc = 0.1 * KDg / KPg; t = i = x = 0.0; fi1d = fi1 = fi1i = 0.0; h3dd = h3d = h3 = 0.0; e = p = d = itae = 0.0; n = 100; } static void output (void) { printf ("%5.1f %5.3f %5.3f %4.2f\n", t, fi1i, h3, itae); } static void derive (void) { fi1d = ee * KPp / 10.0 - fi1 / 5.0;/* prvi proces */ /* drugi proces */ h3dd = (2.0 * fi1 - 20.0 * h3d - 1.0 * h3) / 100.0; d = (e - x) / tc; /* Diferencialni del glavnega regulatorja */ } static void integrate (void) { h3ref = 0.0; /* referenca je 0 */ z = 1.0; /* motnja v prvem procesu */ do { derive (); if (n++ % NTHELEM == 0) output (); t += DT; /* Glavni regulator */ e = h3ref - h3; p = e; /* proprocionalni del */ i += e * DT; /* integralni del */ x += d * DT; /* diferencialni del */ fiv = KPg * p + KIg * i + KDg * d; /* Pomo"zni regulator */ ee = fiv - fi1; /* Prvi proces */ fi1 = fi1i + z; fi1i += fi1d * DT; /* Drugi proces */ h3d += h3dd * DT; h3 += h3d * DT; /* ITAE integralska cenilka */ itae += t * fabs (e) * DT; /* scanf("%*[^\n]"); */ } while (t < TFIN); } int main (int argc, char *argv[]) { initialize (); integrate (); fprintf(stderr, "ITAE = %8.2f\n", itae); return 0; }