/* LAB2.C */ /* DC motor with proportional feedback */ #include #include #include #include #include #include /* Declaration of user variables and constants */ #define ampgain 5. /* Amplifier gain */ #define maxpoints 4000 /* Number of points to be stored on disk */ #define twopi 6.2831852 /* 2 pi */ FILE *fp; char fname[]="DATA.M"; float ref[maxpoints],vol[maxpoints],pos[maxpoints]; float keybin,y,r,e,u,uda,kp,kd,ki,kdd,kid,em,dst,ist;int clock,npoints; /* Keyboard routine */ void user_interface() { scanf("%f",&keybin); } /* Initialization routine */ void user_init() { put_da(0,0.); encoder_init(); freq=500.; clock=0; printf("Enter kp:\n"); scanf("%f",&kp); printf("Enter reference position in degrees, type Ctrl-Break to stop:\n"); scanf("%f",&keybin); } /* Data storage on disk -- File readable by MATLAB, simply typing "data" */ void write_data() { npoints=clock; fp=fopen(fname,"w"); fprintf(fp,"t=[\n"); for (clock=0;clock