to send emg signal to motor with test programm
Dependencies: HIDScope biquadFilter mbed
Fork of EMGvoorjan by
main.cpp@22:a85b568a83e5, 2017-10-20 (annotated)
- Committer:
- Roytsg
- Date:
- Fri Oct 20 11:29:43 2017 +0000
- Revision:
- 22:a85b568a83e5
- Parent:
- 21:77998ce2c0dd
lp: 200 Hz; hp: 20 Hz; notch: 50 Hz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsluiter | 0:32bb76391d89 | 1 | #include "mbed.h" |
vsluiter | 11:ce72ec658a95 | 2 | #include "HIDScope.h" |
Roytsg | 21:77998ce2c0dd | 3 | #include "BiQuad.h" |
vsluiter | 0:32bb76391d89 | 4 | |
vsluiter | 4:8b298dfada81 | 5 | //Define objects |
tomlankhorst | 19:2bf824669684 | 6 | AnalogIn emg0( A0 ); |
tomlankhorst | 19:2bf824669684 | 7 | AnalogIn emg1( A1 ); |
tomlankhorst | 19:2bf824669684 | 8 | |
tomlankhorst | 14:f83354387756 | 9 | Ticker sample_timer; |
tomlankhorst | 19:2bf824669684 | 10 | HIDScope scope( 2 ); |
tomlankhorst | 18:21d8e7a81cf5 | 11 | DigitalOut led(LED1); |
vsluiter | 2:e314bb3b2d99 | 12 | |
tomlankhorst | 14:f83354387756 | 13 | /** Sample function |
tomlankhorst | 14:f83354387756 | 14 | * this function samples the emg and sends it to HIDScope |
tomlankhorst | 14:f83354387756 | 15 | **/ |
tomlankhorst | 14:f83354387756 | 16 | void sample() |
vsluiter | 2:e314bb3b2d99 | 17 | { |
tomlankhorst | 19:2bf824669684 | 18 | /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ |
tomlankhorst | 19:2bf824669684 | 19 | scope.set(0, emg0.read() ); |
tomlankhorst | 19:2bf824669684 | 20 | scope.set(1, emg1.read() ); |
tomlankhorst | 19:2bf824669684 | 21 | /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) |
tomlankhorst | 19:2bf824669684 | 22 | * Ensure that enough channels are available (HIDScope scope( 2 )) |
tomlankhorst | 20:97059009a491 | 23 | * Finally, send all channels to the PC at once */ |
vsluiter | 11:ce72ec658a95 | 24 | scope.send(); |
tomlankhorst | 18:21d8e7a81cf5 | 25 | /* To indicate that the function is working, the LED is toggled */ |
tomlankhorst | 18:21d8e7a81cf5 | 26 | led = !led; |
vsluiter | 2:e314bb3b2d99 | 27 | } |
vsluiter | 0:32bb76391d89 | 28 | |
Roytsg | 21:77998ce2c0dd | 29 | BiQuadChain bqc; |
Roytsg | 22:a85b568a83e5 | 30 | BiQuad bq1( 0.6844323315947305,1.368864663189461, 0.6844323315947305,1.2243497755555954,0.5133795508233265); //lp |
Roytsg | 22:a85b568a83e5 | 31 | BiQuad bq2( 0.8664196904854168, -1.7328393809708336, 0.8664196904854168, -1.7051848034569674, 0.7604939584846998); //hp |
Roytsg | 22:a85b568a83e5 | 32 | BiQuad bq3( 0.7566897754116633, -1.2243497755555959, 0.7566897754116633, -1.2243497755555959, 0.5133795508233266); //notch |
Roytsg | 21:77998ce2c0dd | 33 | |
Roytsg | 21:77998ce2c0dd | 34 | Ticker emgSampleTicker; |
Roytsg | 21:77998ce2c0dd | 35 | AnalogIn emg( A0 ); |
Roytsg | 21:77998ce2c0dd | 36 | |
Roytsg | 21:77998ce2c0dd | 37 | void emgSample() { |
Roytsg | 21:77998ce2c0dd | 38 | |
Roytsg | 21:77998ce2c0dd | 39 | double emgFiltered = bqc.step( emg.read() ); |
Roytsg | 21:77998ce2c0dd | 40 | scope.set(0, emgFiltered ); |
Roytsg | 21:77998ce2c0dd | 41 | scope.send(); |
Roytsg | 21:77998ce2c0dd | 42 | } |
Roytsg | 21:77998ce2c0dd | 43 | |
Roytsg | 21:77998ce2c0dd | 44 | |
vsluiter | 0:32bb76391d89 | 45 | int main() |
tomlankhorst | 19:2bf824669684 | 46 | { |
Roytsg | 21:77998ce2c0dd | 47 | bqc.add( &bq1 ).add( &bq2 ).add( &bq3 ); |
Roytsg | 21:77998ce2c0dd | 48 | emgSampleTicker.attach( &emgSample, 0.002 ); |
tomlankhorst | 14:f83354387756 | 49 | /**Attach the 'sample' function to the timer 'sample_timer'. |
tomlankhorst | 19:2bf824669684 | 50 | * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz |
vsluiter | 4:8b298dfada81 | 51 | */ |
Roytsg | 21:77998ce2c0dd | 52 | //sample_timer.attach(&sample, 0.01); |
tomlankhorst | 15:0da764eea774 | 53 | |
tomlankhorst | 14:f83354387756 | 54 | /*empty loop, sample() is executed periodically*/ |
tomlankhorst | 15:0da764eea774 | 55 | while(1) {} |
vsluiter | 0:32bb76391d89 | 56 | } |