Christina Lanier
/
Modelling
Code for the Transfer Function Modelling
Revision 0:8c805c2b0d35, committed 2015-03-26
- Comitter:
- LanierUSNA16
- Date:
- Thu Mar 26 13:43:39 2015 +0000
- Commit message:
- Modelling Code;
Changed in this revision
diff -r 000000000000 -r 8c805c2b0d35 QEI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QEI.lib Thu Mar 26 13:43:39 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r 8c805c2b0d35 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 26 13:43:39 2015 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "QEI.h" + +PwmOut turret_speed(p21); +DigitalOut turret_direction(p22); + +QEI myEncoder (p16,p15, NC, 1600); +Timer t; + +int main() +{ +float input_dc =50.0; +int user_direction = 0; +float duty_cycle ; +int pulses = 0; +float theta[500] ; +float time[500]; +float Kp = 0.2; +int counter = 1; +int k; + +float theta_ref = 3.14/4.0; + +while(1) + { + printf("Enter duty cycle, 0 to 100:\n"); + scanf("%f", &input_dc); + + duty_cycle = input_dc/100.0; + + printf("\n %f duty cycle set. Enter 1 for CCW or 0 for CW spin direction:\n",duty_cycle); + scanf("%d", &user_direction); + + t.start(); + turret_speed = duty_cycle; + turret_direction = user_direction; + + while (t.read()<5.05) + { + wait(0.01); + pulses = myEncoder.getPulses(); + theta[counter] = ((float)pulses/ (1600.0*2.0))*-2.0*3.14; + time[counter] = t.read(); + printf("Time(%d)= %f Angle(%d) = %f \n", counter+1,time[counter],counter+1, theta[counter]); + counter= counter + 1; + } + t.stop(); + for(k=0; k<counter; k++) + { + printf("time(%d,1) = %.5f;\n",k+1,time[k]); + printf("theta(%d,1) = %.5f;\n",k+1,theta[k]); + + } + } +} \ No newline at end of file
diff -r 000000000000 -r 8c805c2b0d35 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Mar 26 13:43:39 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file