Luke Plummer
/
JesusLizard
lizard leg trajectory pd control code for 2.s994
Revision 10:6ecef8d1a018, committed 2013-12-01
- Comitter:
- lukeplummer
- Date:
- Sun Dec 01 22:25:40 2013 +0000
- Parent:
- 9:80c1f8bbcd55
- Commit message:
- added button code, removed file write code, fixed trigger code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Dec 01 21:19:53 2013 +0000 +++ b/main.cpp Sun Dec 01 22:25:40 2013 +0000 @@ -16,18 +16,13 @@ PwmOut pwmOut2(p22); QEI encoder2(p9, p10, NC, 1200, QEI::X4_ENCODING); -//force measurement pins -AnalogIn aIn1(p15); -AnalogIn aIn2(p16); +DigitalIn button(p7); // Declare other objects Ticker ctrlTicker; // creates an instance of the ticker class, which can be used for running functions at a specified frequency. Ticker trajTicker; -Ticker writeTicker; +Ticker buttonTicker; Serial mySerial(USBTX, USBRX); // create a serial connection to the computer over the tx/rx pins -LocalFileSystem local("local"); -FILE *fp1 = fopen("/local/encoders.csv", "w"); -FILE *fp2 = fopen("/local/force.csv", "w"); DigitalOut dOut1(p17); @@ -94,16 +89,14 @@ done = false; aD[0] = traj1[nTraj]-a1_0; aD[1] = traj2[nTraj]-a2_0; -// aD[1] = traj2[nTraj]-a0_2+aD[0]; //corrects for coaxial motors nTraj++; } } -void writeFiles() { - float f1 = aIn1.read(); - float f2 = aIn2.read(); - fprintf(fp1, "%f, %f\n",a1_t1, a2_t1); - fprintf(fp2, "%f, %f average: $f\n",f1,f2, (f1+f2)/2); +void checkBtn() { + if (button.read() == 1){ + done = true; + } } int main() { @@ -113,29 +106,26 @@ mDir2_A = 1; mDir2_B = 0; - mySerial.printf("numPoints: %d, fTraj: %f, fPWM: %f\n\r", numPoints, fTraj, fPWM); + //mySerial.printf("numPoints: %d, fTraj: %f, fPWM: %f\n\r", numPoints, fTraj, fPWM); //get initial position dOut1.write(1); - wait(0.1); - dOut1.write(0); if (sizeof(traj1) == sizeof(traj2)) { trajTicker.attach(setTraj, 1/fTraj); ctrlTicker.attach(pdControl, 1/fPWM); - //writeTicker.attach(writeFiles, 0.01); + buttonTicker.attach(checkBtn, 0.1); while (!done) { - mySerial.printf("motor 2: %f \n\r", a2_t1); + //mySerial.printf("motor 2: %f \n\r", a2_t1); } - mySerial.printf("Done\n\r"); - fclose(fp1); - fclose(fp2); + //mySerial.printf("Done\n\r"); + dOut1.write(0); mDir1_A = 0; mDir1_B = 0; mDir2_A = 0; mDir2_B = 0; } else { - mySerial.printf("Input error\n\r"); + //mySerial.printf("Input error\n\r"); } } \ No newline at end of file