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.
main.cpp
- Committer:
- LanierUSNA16
- Date:
- 2015-03-26
- Revision:
- 0:8c805c2b0d35
File content as of revision 0:8c805c2b0d35:
#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]);
}
}
}