next up previous
Naprej: Kaskadna regulacija Gor: Enozan"cna reglacija Nazaj: Diferencialni del regulatorja

Ansi C program

/*\
 *   Simulacije sistemov  - vaja 3a
 *   Zaprtozan"cna regulacija nivoja posode
 *   $Id: sim3a.c,v 1.2 1994/05/05 07:36:14 Exp $
\*/
#include <stdio.h>
#include <math.h>

#define KPg          3.8876	/* Parametri   */
#define KIg          0.1718	/* glavnega    */
#define KDg          30.599	/* regulatorja */

#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, p, i, d, x, fiv;
static float h3ref, fi1d, fi1, h3dd, h3d, h3, itae;
static short n;

static void
initialize (void)
{
  tc = 0.1 * KDg / KPg;
  t = i = x = 0.0;
  fi1d = fi1 = 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, h3ref, h3, itae);
}

static void
derive (void)
{
  fi1d = fiv / 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 = 1.0;
  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;
      /* Prvi proces */
      fi1 += 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;
}



Leon Kos
Thu Feb 22 16:56:07 GMT+0100 1996