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.
Revision 7:1726c40ad774, committed 2017-02-10
- Comitter:
- abraham1
- Date:
- Fri Feb 10 00:04:57 2017 +0000
- Parent:
- 6:73e417b1c521
- Child:
- 8:6ae3c3cd7f55
- Commit message:
- This is working as of feb 9 night snow day;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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++; } + } }