Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GainController by
Diff: GainControl.cpp
- Revision:
- 2:eabcd6202bff
- Parent:
- 1:d4c2e72540db
- Child:
- 3:9bdf180baa64
--- a/GainControl.cpp Thu Mar 26 12:30:15 2015 +0000
+++ b/GainControl.cpp Tue Mar 31 12:48:54 2015 +0000
@@ -13,45 +13,50 @@
int user_direction = 0;
float duty_cycle = 0.0;
int pulses = 0;
-float theta = 0.0;
-float time =0.0;
-float signed_duty_cycle = 0.0;
-float Kp = 1;
-
-float theta_ref = 3.14/4.0;
+float time[500]={0} ;
+float theta[500]={0} ;
+float ang_v[500]={0};
+int counter = 1;
+int k = 0;
+
while(1)
{
- //printf("Enter duty cycle, 0 to 100:\n");
- //scanf("%d", &input_dc);
+ printf("Enter duty cycle, 0 to 100:\n");
+ scanf("%d", &input_dc);
- //signed_duty_cycle = Kp*(theta_ref - theta);
- //duty_cycle = input_dc/100.0;
- duty_cycle = signed_duty_cycle/100.0;
+ 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);
+ printf("\n %f duty cycle set. Enter 0 for CCW or 1 for CW spin direction:\n",duty_cycle);
scanf("%d", &user_direction);
-
- printf("it's starting... move the thing!\n");
- t.start();
+
turret_speed = duty_cycle;
turret_direction = user_direction;
printf("%f duty cycle. %d spin.\n", duty_cycle, user_direction);
+
+ t.start();
+ while(time[counter-1]<5.05)
+ {
+ wait(0.01);
+ pulses = myEncoder.getPulses();
+ theta[counter] = ((float)pulses/ (1600.0*2.0))*-2.0*3.14;
+ time[counter] = t.read();
+ ang_v[counter]=(theta[counter]-theta[counter-1])/(time[counter]-time[counter-1]);
+
+ printf("time(%d,1) = %.5f;\n",counter,time[counter]);
+ printf("theta(%d,1) = %.5f;\n",counter,theta[counter]);
+ printf("ang_v(%d,1) = %.5f; \n",counter,ang_v[counter]);
+ counter = counter +1;
+ }
+ turret_speed = 0;
+ t.stop();
- while(1)
+ for(k=0; k<counter+1; k++)
{
- wait(0.01);
- pulses = myEncoder.getPulses();
- theta = ((float)pulses/ (1600.0*2.0))*-2.0*3.14;
- time = t.read();
-
- signed_duty_cycle = Kp*(theta_ref - theta);
- duty_cycle = signed_duty_cycle;
- turret_speed = duty_cycle;
-
- printf("time = %.5f;\n",time);
- printf("theta = %.5f;\n",theta);
- printf("duty cyle= %f. \n", duty_cycle);
- }
+ printf("time(%d,1) = %.5f;\n",k+1,time[k]);
+ printf("theta(%d,1) = %.5f;\n",k+1,theta[k]);
+ }
+ printf("Duty Cycle = %f", duty_cycle);
+
}
}
\ No newline at end of file
