calibrate
Dependencies: FastPWM MODSERIAL QEI mbed
main.cpp@0:46c28ea3feb9, 2018-10-30 (annotated)
- Committer:
- s1737619
- Date:
- Tue Oct 30 15:00:46 2018 +0000
- Revision:
- 0:46c28ea3feb9
calibratie
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s1737619 | 0:46c28ea3feb9 | 1 | #include "mbed.h" |
s1737619 | 0:46c28ea3feb9 | 2 | |
s1737619 | 0:46c28ea3feb9 | 3 | //global variables |
s1737619 | 0:46c28ea3feb9 | 4 | |
s1737619 | 0:46c28ea3feb9 | 5 | double EMG_filt1; |
s1737619 | 0:46c28ea3feb9 | 6 | double EMG_filt2; |
s1737619 | 0:46c28ea3feb9 | 7 | double EMG_filt3; |
s1737619 | 0:46c28ea3feb9 | 8 | double EMG_filt4; |
s1737619 | 0:46c28ea3feb9 | 9 | bool calibrationbool; |
s1737619 | 0:46c28ea3feb9 | 10 | double EMG_max1 = 10000.0; |
s1737619 | 0:46c28ea3feb9 | 11 | double EMG_max2 = 10000.0; |
s1737619 | 0:46c28ea3feb9 | 12 | double EMG_max3 = 10000.0; |
s1737619 | 0:46c28ea3feb9 | 13 | double EMG_max4 = 10000.0; |
s1737619 | 0:46c28ea3feb9 | 14 | |
s1737619 | 0:46c28ea3feb9 | 15 | void calibrationbutton |
s1737619 | 0:46c28ea3feb9 | 16 | { |
s1737619 | 0:46c28ea3feb9 | 17 | calibrationbool = true; |
s1737619 | 0:46c28ea3feb9 | 18 | EMG_max1 = 0.0001; |
s1737619 | 0:46c28ea3feb9 | 19 | EMG_max2 = 0.0001; |
s1737619 | 0:46c28ea3feb9 | 20 | EMG_max3 = 0.0001; |
s1737619 | 0:46c28ea3feb9 | 21 | EMG_max4 = 0.0001; |
s1737619 | 0:46c28ea3feb9 | 22 | |
s1737619 | 0:46c28ea3feb9 | 23 | } |
s1737619 | 0:46c28ea3feb9 | 24 | |
s1737619 | 0:46c28ea3feb9 | 25 | void switchtostate |
s1737619 | 0:46c28ea3feb9 | 26 | { |
s1737619 | 0:46c28ea3feb9 | 27 | calibrationbool = false //Dit moet waarschijnlijk anders in het hele script. |
s1737619 | 0:46c28ea3feb9 | 28 | } |
s1737619 | 0:46c28ea3feb9 | 29 | |
s1737619 | 0:46c28ea3feb9 | 30 | void calibratie() |
s1737619 | 0:46c28ea3feb9 | 31 | { |
s1737619 | 0:46c28ea3feb9 | 32 | static int count |
s1737619 | 0:46c28ea3feb9 | 33 | |
s1737619 | 0:46c28ea3feb9 | 34 | if (0.95*EMG_filt1>EMG_max1) |
s1737619 | 0:46c28ea3feb9 | 35 | { |
s1737619 | 0:46c28ea3feb9 | 36 | EMG_max1 = 0.95*EMG_filt1; |
s1737619 | 0:46c28ea3feb9 | 37 | } |
s1737619 | 0:46c28ea3feb9 | 38 | if (0.95*EMG_filt2>EMG_max2) |
s1737619 | 0:46c28ea3feb9 | 39 | |
s1737619 | 0:46c28ea3feb9 | 40 | { |
s1737619 | 0:46c28ea3feb9 | 41 | EMG_max2 = 0.95*EMG_filt2; |
s1737619 | 0:46c28ea3feb9 | 42 | } |
s1737619 | 0:46c28ea3feb9 | 43 | |
s1737619 | 0:46c28ea3feb9 | 44 | if (0.95*EMG_filt3>EMG_max3) |
s1737619 | 0:46c28ea3feb9 | 45 | { |
s1737619 | 0:46c28ea3feb9 | 46 | EMG_max3 = 0.95*EMG_filt3; |
s1737619 | 0:46c28ea3feb9 | 47 | } |
s1737619 | 0:46c28ea3feb9 | 48 | if (0.95*EMG_filt4>EMG_max4) |
s1737619 | 0:46c28ea3feb9 | 49 | { |
s1737619 | 0:46c28ea3feb9 | 50 | EMG_max4 = 0.95*EMG_filt4; |
s1737619 | 0:46c28ea3feb9 | 51 | } |
s1737619 | 0:46c28ea3feb9 | 52 | |
s1737619 | 0:46c28ea3feb9 | 53 | count++; |
s1737619 | 0:46c28ea3feb9 | 54 | if (count == eengetal) |
s1737619 | 0:46c28ea3feb9 | 55 | { |
s1737619 | 0:46c28ea3feb9 | 56 | switchtostate() |
s1737619 | 0:46c28ea3feb9 | 57 | } |
s1737619 | 0:46c28ea3feb9 | 58 | } |
s1737619 | 0:46c28ea3feb9 | 59 | } |
s1737619 | 0:46c28ea3feb9 | 60 | |
s1737619 | 0:46c28ea3feb9 | 61 | InterruptIn button |
s1737619 | 0:46c28ea3feb9 | 62 | |
s1737619 | 0:46c28ea3feb9 | 63 | |
s1737619 | 0:46c28ea3feb9 | 64 | int main |
s1737619 | 0:46c28ea3feb9 | 65 | { |
s1737619 | 0:46c28ea3feb9 | 66 | button.fall(calibrationbutton) |
s1737619 | 0:46c28ea3feb9 | 67 | |
s1737619 | 0:46c28ea3feb9 | 68 | while (true) |
s1737619 | 0:46c28ea3feb9 | 69 | { |
s1737619 | 0:46c28ea3feb9 | 70 | } |
s1737619 | 0:46c28ea3feb9 | 71 | |
s1737619 | 0:46c28ea3feb9 | 72 |