2.007 PulleyInterface mbed code. Biomimetics robotics lab. Sangbae Kim. Ben Katz. For use with PulleyInterface.mlapp
Diff: main.cpp
- Revision:
- 7:1726c40ad774
- Parent:
- 6:73e417b1c521
- Child:
- 8:6ae3c3cd7f55
diff -r 73e417b1c521 -r 1726c40ad774 main.cpp --- a/main.cpp Tue Feb 07 20:02:52 2017 +0000 +++ b/main.cpp Fri Feb 10 00:04:57 2017 +0000 @@ -78,7 +78,7 @@ double time_between_readings; double velocity; double currentSensed = 0; - clock_t start, end; + clock_t start, end, absoluteStart; int ticks; a=1; b=0; pwm.write(0); button.fall(&pressed); @@ -87,7 +87,7 @@ double samplesPerPublish = (int)(publishFrequency/updatePeriod); /*this improves time response of filter and maintains smoothness*/ int publishCounter = 1; double filterRatio = 0.045; - double currentFilterRatio = 0.02; + double currentFilterRatio = 0.03; float currentSensorOffset = 0; int i; for(i=1;i<301;i++){ currentSensorOffset += currentSense.read(); } currentSensorOffset = currentSensorOffset*VREF/300; @@ -99,13 +99,16 @@ while(1) { + while(1) { + green = true; if(pc.readable()) { char charIn = pc.getc(); if(charIn == 'g'){ fflush(pc); // TODO: this was recently changed check to see it causes no bugs + absoluteStart = clock(); end = clock(); /* TODO: fix clock things */ ZeroEncoder(); velocity = 0; @@ -119,13 +122,14 @@ } } wait(0.05); + } while(1) { + green = false; wait(updatePeriod); - clock_t absoluteStart = clock(); start = end; end = clock(); time_between_readings = ((double)(end - start)) / CLOCKS_PER_SEC; @@ -141,21 +145,22 @@ char charIn = pc.getc(); if(charIn == 'r'){ fflush(pc); /* TODO: purge much better than this! */ + pwm.write(0.0); /* eliminates the need to write r and 0 commands in matlab which mbed couldn't read fast enough */ break; } else if(isdigit(charIn)) { double abrahamsCommand = (double)(charIn - '0'); pwm.write(abrahamsCommand/10.0); } } - if(publishCounter == samplesPerPublish) - { + if(publishCounter == samplesPerPublish) { printf("%+8f,%+8f,%+8f,%+8f\n", currentSensed/currentSensorOutputRatio, pwm.read(), velocity, ((double)(end-absoluteStart)/CLOCKS_PER_SEC)); publishCounter = 1; - } + } publishCounter++; } + } }