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.
Dependencies: mbed QEI biquadFilter
Revision 29:1c5254b27851, committed 2016-11-04
- Comitter:
- Jankoekenpan
- Date:
- Fri Nov 04 13:26:28 2016 +0000
- Parent:
- 28:09b08753498c
- Commit message:
- documented the processEMG function
Changed in this revision
arm.cpp | Show annotated file Show diff for this revision Revisions of this file |
test_main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/arm.cpp Thu Nov 03 18:23:51 2016 +0000 +++ b/arm.cpp Fri Nov 04 13:26:28 2016 +0000 @@ -39,7 +39,7 @@ // Counterclockwise rotation if (referenceVelocity < 0) { motorDirection = counterClockwise; - velocity = (referenceVelocity < (-1 * maxAllowedVelocity))? (-1 * maxAllowedVelocity):referenceVelocity; + velocity = (referenceVelocity < (-1 * maxAllowedVelocity)) ? (-1 * maxAllowedVelocity) : referenceVelocity; // Clockwise rotation } else { motorDirection = clockwise;
--- a/test_main.cpp Thu Nov 03 18:23:51 2016 +0000 +++ b/test_main.cpp Fri Nov 04 13:26:28 2016 +0000 @@ -51,7 +51,9 @@ const float sample_frequency = 500.0f; //Hz const float Ts = 1.0f / sample_frequency; -volatile int count = 0; //how many signals have passed. resets at 50. + +//Counts how many signals have passed. Resets at 50. See processEMG. +volatile int count = 0; /*Function used to send data to the motor*/ void (*motorFunc)(bool, bool); @@ -243,24 +245,40 @@ } // ===== The main functions called by our main ticker ====== - + +/** + * processEMG function + * This function is called by our ticker. + * This function measures emg and applies the filters. + * out of 50 emg values, a 1 or 0 is chosen depending on which occurs the most + * then that value is used in the motor func. + */ void processEMG() { + //read emg float emgOne = emg1.read(); float emgTwo = emg2.read(); + + //apply notch filter float notch1 = bqc1.step( emgOne ); float notch2 = bqc2.step( emgTwo ); - + + //then apply rectifier float rect1 = rectifier(notch1); float rect2 = rectifier(notch2); + //then apply moving average float filtered1 = movingAverage( rect1, emgCache1, numEmgCache); float filtered2 = movingAverage( rect2, emgCache2, numEmgCache); + //decide on wether the signal was strong enough (1) or too weak (0) int decide1 = decide(mean(emgCache1, numEmgCache ), threshold1); int decide2 = decide(mean(emgCache2, numEmgCache ), threshold2); + + //add boolean value in front of the boolean arrays addFirst(decide1, decided1, numEmgCache); addFirst(decide2, decided2, numEmgCache); + //after 50 calls of this function, control the motor. if (count >= 49) { int counter1=0; int counter2=0; @@ -270,10 +288,15 @@ if(decided2[i] == 0) ++counter2; } + // avgDecide1 = true if the decided1 array contains mostly ones, otherwise false. int avgDecide1 = counter1 > std::ceil(numEmgCache/2.0) ? 0: 1; + // avgDecide2 = true if the decided2 array contains mostly ones, otherwise false. int avgDecide2 = counter2 > std::ceil(numEmgCache/2.0) ? 0: 1; + + // Use these values to contorl the motor. sendToMotor(motorFunc,avgDecide1, avgDecide2); + //reset function call count to 0 count =0; } else { count++;