a

Dependencies:   Motor mbed

Committer:
Ty
Date:
Thu Mar 05 01:16:24 2015 +0000
Revision:
0:1bcc2ae04a31
aq

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ty 0:1bcc2ae04a31 1 //Integral
Ty 0:1bcc2ae04a31 2 #include "mbed.h"
Ty 0:1bcc2ae04a31 3 #include "Motor.h"
Ty 0:1bcc2ae04a31 4 Serial pc(USBTX,USBRX);//allows communication through the USB
Ty 0:1bcc2ae04a31 5 AnalogIn range(p19);
Ty 0:1bcc2ae04a31 6 float height;
Ty 0:1bcc2ae04a31 7 float rv;
Ty 0:1bcc2ae04a31 8 float dh;
Ty 0:1bcc2ae04a31 9 float ds;
Ty 0:1bcc2ae04a31 10 float er;
Ty 0:1bcc2ae04a31 11 float k=0.35;
Ty 0:1bcc2ae04a31 12 float ki=.03;
Ty 0:1bcc2ae04a31 13 float tgl=0.0;
Ty 0:1bcc2ae04a31 14 Motor m(p26, p29, p30);
Ty 0:1bcc2ae04a31 15 int count;
Ty 0:1bcc2ae04a31 16 int main()
Ty 0:1bcc2ae04a31 17 {
Ty 0:1bcc2ae04a31 18
Ty 0:1bcc2ae04a31 19 m.speed(0);
Ty 0:1bcc2ae04a31 20 while(1) {
Ty 0:1bcc2ae04a31 21 count=0;
Ty 0:1bcc2ae04a31 22 m.speed(0);
Ty 0:1bcc2ae04a31 23 rv=range;
Ty 0:1bcc2ae04a31 24 height=(-75.7457492123552*pow(rv,2))+(90.6774745565381*rv)+(-4.00358328437282);
Ty 0:1bcc2ae04a31 25 pc.printf("%f,%f\n",rv,height);
Ty 0:1bcc2ae04a31 26 pc.printf("Enter desired height\n");
Ty 0:1bcc2ae04a31 27 pc.scanf("%f",&dh);
Ty 0:1bcc2ae04a31 28 while(count<600) {
Ty 0:1bcc2ae04a31 29 rv=range;
Ty 0:1bcc2ae04a31 30 height=(-75.7457492123552*pow(rv,2))+(90.6774745565381*rv)+(-4.00358328437282);
Ty 0:1bcc2ae04a31 31 er=dh-height;
Ty 0:1bcc2ae04a31 32 pc.printf("%f\n", er);
Ty 0:1bcc2ae04a31 33 tgl=tgl+er*0.05;
Ty 0:1bcc2ae04a31 34 ds=k*er+ki*tgl;
Ty 0:1bcc2ae04a31 35 m.speed(-ds);
Ty 0:1bcc2ae04a31 36 count=count+1;
Ty 0:1bcc2ae04a31 37
Ty 0:1bcc2ae04a31 38
Ty 0:1bcc2ae04a31 39 }
Ty 0:1bcc2ae04a31 40 }
Ty 0:1bcc2ae04a31 41 }