#include #include #include #include #include #define JW (pow((10.0/2.0) , 1.5)) static double kp1(double t) { double c1 = pow(10.0, 0.2) / ( pow(t, 0.3) * pow(JW, 0.5) ); double c2 = 0.62 / t; if (c1 < c2) { return c1; } return c2; } static double ki1(double t) { double c1 = pow(10.0, 0.1) / ( pow(t, -0.4) * JW ); double c2 = 0.38 / t; if (c1 < c2) { return c1; } return c2; } #define AP .8 #define AI .2 #define BP (-0.5) #define BI ( 0.5) #define TT 1.0 static double kp2(double t) { if (t > TT) { return .7 / t; } return AP * pow(t, BP); } static double ki2(double t) { if (t > TT) { return .38 / t; } return AI * pow(t, BI); } static void usage(char *progname) { fprintf(stderr, "\n" "usage: %s [options]\n\n" " -a use method A\n" " -b use method B\n" " -s [num] start sync period in log seconds (default 0)\n" " -n [num] number of sync period steps (default 1)\n" " -h prints this message and exits\n" "\n", progname); } int main(int argc, char *argv[]) { char *progname; int c, i, s = 0, nvals = 1, method = 1; double ts, kp, ki; /* Process the command line arguments. */ progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; while (EOF != (c = getopt(argc, argv, "abs:n:h"))) { switch (c) { case 'a': method = 1; break; case 'b': method = 2; break; case 's': s = atoi(optarg); break; case 'n': nvals = atoi(optarg); break; case 'h': usage(progname); return 0; default: usage(progname); return -1; } } for (i = 0; i < nvals; i++, s++) { if (s < 0) { ts = 1.0 / (1 << -s); } else { ts = (1 << s); } switch (method) { case 1: kp = kp1(ts); ki = ki1(ts); break; case 2: kp = kp2(ts); ki = ki2(ts); break; } printf("%+d %.13f %.13f\n", s, kp, ki); } return 0; }