filewriting program for second mbed

Dependencies:   QEI mbed

Committer:
lukeplummer
Date:
Sun Dec 01 23:05:45 2013 +0000
Revision:
3:24f214dd6994
Parent:
2:4355e6305710
fixed again;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lukeplummer 0:62a5c4d985cc 1 #include "mbed.h"
lukeplummer 0:62a5c4d985cc 2 #include "QEI.h"
lukeplummer 0:62a5c4d985cc 3
lukeplummer 0:62a5c4d985cc 4 QEI encoder1(p25, p26, NC, 1200, QEI::X4_ENCODING);
lukeplummer 0:62a5c4d985cc 5 QEI encoder2(p23, p24, NC, 1200, QEI::X4_ENCODING);
lukeplummer 0:62a5c4d985cc 6 DigitalIn trigger(p21);
lukeplummer 0:62a5c4d985cc 7 AnalogIn force1(p20);
lukeplummer 0:62a5c4d985cc 8 AnalogIn force2(p19);
lukeplummer 0:62a5c4d985cc 9 AnalogIn current1(p18);
lukeplummer 0:62a5c4d985cc 10 AnalogIn current2(p17);
lukeplummer 0:62a5c4d985cc 11
lukeplummer 0:62a5c4d985cc 12 LocalFileSystem local("local");
lukeplummer 0:62a5c4d985cc 13 FILE *fp = fopen("/local/OUT.csv", "w");
lukeplummer 0:62a5c4d985cc 14
lukeplummer 0:62a5c4d985cc 15 int main() {
lukeplummer 3:24f214dd6994 16 fprintf(fp, "encoder 1, encoder 2, force 1, force 2, average force, current 1, current 2\n");
lukeplummer 0:62a5c4d985cc 17 while (trigger.read() == 0) {
lukeplummer 0:62a5c4d985cc 18 //do nothing
lukeplummer 0:62a5c4d985cc 19 }
lukeplummer 0:62a5c4d985cc 20 while (trigger.read() == 1) {
lukeplummer 0:62a5c4d985cc 21 float c1 = current1.read();
lukeplummer 0:62a5c4d985cc 22 float c2 = current2.read();
lukeplummer 0:62a5c4d985cc 23 float f1 = force1.read();
lukeplummer 0:62a5c4d985cc 24 float f2 = force2.read();
lukeplummer 0:62a5c4d985cc 25 float e1 = encoder1.getPulses()*2*3.14/1200.0;
lukeplummer 0:62a5c4d985cc 26 float e2 = encoder2.getPulses()*2*3.14/1200.0;
lukeplummer 0:62a5c4d985cc 27
lukeplummer 3:24f214dd6994 28 fprintf(fp, "%f, %f, %f, %f, %f, %f, %f\n", e1, e2, f1, f2, (f1+f2)/2.0, c1, c2);
lukeplummer 0:62a5c4d985cc 29 }
lukeplummer 0:62a5c4d985cc 30 fclose(fp);
lukeplummer 0:62a5c4d985cc 31 }