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: BiQuad4th_order Biquad HIDScope MODSERIAL biquadFilter mbed
Fork of emg_calibration by
main.cpp@0:802c9c6b30d3, 2018-10-31 (annotated)
- Committer:
- Duif
- Date:
- Wed Oct 31 12:57:37 2018 +0000
- Revision:
- 0:802c9c6b30d3
- Child:
- 1:f99650c5b9eb
Weird error. Editions made so the calibration can be checked;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Duif | 0:802c9c6b30d3 | 1 | #include "mbed.h" |
| Duif | 0:802c9c6b30d3 | 2 | #include "MODSERIAL.h" |
| Duif | 0:802c9c6b30d3 | 3 | #include "BiQuad.h" |
| Duif | 0:802c9c6b30d3 | 4 | #include "BiQuad4.h" |
| Duif | 0:802c9c6b30d3 | 5 | #include "FilterDesign.h" |
| Duif | 0:802c9c6b30d3 | 6 | #include "FilterDesign2.h" |
| Duif | 0:802c9c6b30d3 | 7 | MODSERIAL pc(USBTX, USBRX); //makes sure the computer is hooked up |
| Duif | 0:802c9c6b30d3 | 8 | |
| Duif | 0:802c9c6b30d3 | 9 | AnalogIn emg1_raw(A0); |
| Duif | 0:802c9c6b30d3 | 10 | AnalogIn emg2_raw(A1); |
| Duif | 0:802c9c6b30d3 | 11 | DigitalOut led(LED_RED); |
| Duif | 0:802c9c6b30d3 | 12 | |
| Duif | 0:802c9c6b30d3 | 13 | //global variables |
| Duif | 0:802c9c6b30d3 | 14 | double emg1_cal = 0.00000; //measured value of the first emg |
| Duif | 0:802c9c6b30d3 | 15 | double emg2_cal = 0.00000; //measured value of the second emg |
| Duif | 0:802c9c6b30d3 | 16 | double EMG_calibrated_max_1 = 0.00000; //final calibration value of EMG1 |
| Duif | 0:802c9c6b30d3 | 17 | double EMG_calibrated_max_2 = 0.00000; //final calibration value of EMG2 |
| Duif | 0:802c9c6b30d3 | 18 | |
| Duif | 0:802c9c6b30d3 | 19 | |
| Duif | 0:802c9c6b30d3 | 20 | void EMG_calibration(){ |
| Duif | 0:802c9c6b30d3 | 21 | for (int i = 0; i <= 10; i++) //10 measuring points |
| Duif | 0:802c9c6b30d3 | 22 | { |
| Duif | 0:802c9c6b30d3 | 23 | emg1_cal = FilterDesign(emg1_raw.read()); |
| Duif | 0:802c9c6b30d3 | 24 | emg2_cal = FilterDesign2(emg2_raw.read()); |
| Duif | 0:802c9c6b30d3 | 25 | |
| Duif | 0:802c9c6b30d3 | 26 | if (emg1_cal > EMG_calibrated_max_1){ |
| Duif | 0:802c9c6b30d3 | 27 | EMG_calibrated_max_1 = emg1_cal;} |
| Duif | 0:802c9c6b30d3 | 28 | |
| Duif | 0:802c9c6b30d3 | 29 | if (emg2_cal > EMG_calibrated_max_2){ |
| Duif | 0:802c9c6b30d3 | 30 | EMG_calibrated_max_2 = emg2_cal;} |
| Duif | 0:802c9c6b30d3 | 31 | |
| Duif | 0:802c9c6b30d3 | 32 | wait(0.5f); |
| Duif | 0:802c9c6b30d3 | 33 | } |
| Duif | 0:802c9c6b30d3 | 34 | } |
| Duif | 0:802c9c6b30d3 | 35 | |
| Duif | 0:802c9c6b30d3 | 36 | |
| Duif | 0:802c9c6b30d3 | 37 | |
| Duif | 0:802c9c6b30d3 | 38 | int main(){ |
| Duif | 0:802c9c6b30d3 | 39 | pc.baud(115200); |
| Duif | 0:802c9c6b30d3 | 40 | while (true) { |
| Duif | 0:802c9c6b30d3 | 41 | led = 0; |
| Duif | 0:802c9c6b30d3 | 42 | EMG_calibration(); |
| Duif | 0:802c9c6b30d3 | 43 | led = 1; |
| Duif | 0:802c9c6b30d3 | 44 | pc.printf("EMG1 = %f, EMG2 = %f \r\n",EMG_calibrated_max_1,EMG_calibrated_max_2); |
| Duif | 0:802c9c6b30d3 | 45 | } |
| Duif | 0:802c9c6b30d3 | 46 | } |
