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 11:e563823d3c94, committed 2017-03-01
- Comitter:
- abraham1
- Date:
- Wed Mar 01 03:10:29 2017 +0000
- Parent:
- 10:ae139f40acc0
- Child:
- 12:6e13c34c4295
- Commit message:
- giving this to sangbae;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 16 23:27:49 2017 +0000 +++ b/main.cpp Wed Mar 01 03:10:29 2017 +0000 @@ -19,6 +19,9 @@ const int CPR = 900*4; // Encoder counts per revolution. Change to match your encoder. x4 for quadrature! const double VREF = 3; //Microcontroller reference voltage const float currentSensorOutputRatio = 0.185; // Volts/Amp. Divide Voltage by cSenseOutput to get current +const float PSupply_Voltage = 12.0; +const float Output_Voltage = 6.0; +const float pwm_pulley = Output_Voltage/PSupply_Voltage; void EncoderInitialise(void) { // configure GPIO PA0 & PA1 as inputs for Encoder @@ -91,39 +94,32 @@ float currentSensorOffset = 0; int i; for(i=1;i<301;i++){ currentSensorOffset += currentSense.read(); } currentSensorOffset = currentSensorOffset*VREF/300; - EncoderInitialise(); fflush(pc); - /*** wait here for matlab information like voltage before starting? ***/ - + while(1) { -// currentSensorOffset = 0; i = 0; -// for(i=1;i<201;i++){ currentSensorOffset += currentSense.read(); } //TODO: watch out this could take some time, but this should make things better! -// currentSensorOffset = currentSensorOffset*VREF/300; while(1) { green = true; - if(pc.readable()) - { + if(pc.readable()) { char charIn = pc.getc(); if(charIn == 'g'){ - fflush(pc); // TODO: this was recently changed check to see it causes no bugs + fflush(pc); absoluteStart = clock(); - end = clock(); /* TODO: fix clock things */ + end = clock(); ZeroEncoder(); velocity = 0; startcount = 0; endcount = 0; currentSensed = 0; + pwm.write(pwm_pulley); break; - } else if(isdigit(charIn)) { - double abrahamsCommand = (double)(charIn - '0'); - pwm.write(abrahamsCommand/10.0); } } + wait(0.05); } @@ -147,17 +143,14 @@ { 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 */ + fflush(pc); + pwm.write(0.0); break; - } else if(isdigit(charIn)) { - double abrahamsCommand = (double)(charIn - '0'); - pwm.write(abrahamsCommand/10.0); } } if(publishCounter == samplesPerPublish) { - printf("%+9.5f,%+8.4f,%+9.5f,%+8.2f\n", currentSensed/currentSensorOutputRatio, pwm.read(), velocity, ((double)(end-absoluteStart)/CLOCKS_PER_SEC)); - publishCounter = 1; // good for 1000 seconds. and room to grow one power of 10 on all other inputs. + printf("%+9.5f,%+8.4f,%+9.4f,%+8.2f\n", currentSensed/currentSensorOutputRatio, pwm.read(), velocity, ((double)(end-absoluteStart)/CLOCKS_PER_SEC)); + publishCounter = 1; // good for 1000 seconds. and room to grow one power of 10 on all other inputs. //just changed velocity to 4 precision to give it extra room for no load? bug maybe? } publishCounter++;