emg
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
main.cpp@2:c87703888e97, 2019-10-22 (annotated)
- Committer:
- pinkyKathlea
- Date:
- Tue Oct 22 15:37:02 2019 +0000
- Revision:
- 2:c87703888e97
- Parent:
- 1:b862262a9d14
template biorobotics with biquad filter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobertoO | 0:67c50348f842 | 1 | #include "mbed.h" |
pinkyKathlea | 2:c87703888e97 | 2 | #include "HIDScope.h" |
pinkyKathlea | 2:c87703888e97 | 3 | #include "QEI.h" |
RobertoO | 1:b862262a9d14 | 4 | #include "MODSERIAL.h" |
pinkyKathlea | 2:c87703888e97 | 5 | #include "BiQuad.h" |
pinkyKathlea | 2:c87703888e97 | 6 | #include "FastPWM.h" |
pinkyKathlea | 2:c87703888e97 | 7 | #include <iostream> |
pinkyKathlea | 2:c87703888e97 | 8 | #include <complex> |
pinkyKathlea | 2:c87703888e97 | 9 | #include <vector> |
RobertoO | 0:67c50348f842 | 10 | |
pinkyKathlea | 2:c87703888e97 | 11 | InterruptIn button(SW2); |
pinkyKathlea | 2:c87703888e97 | 12 | DigitalOut led(LED1); |
pinkyKathlea | 2:c87703888e97 | 13 | DigitalOut flash(LED3); |
pinkyKathlea | 2:c87703888e97 | 14 | DigitalOut ledg(LED2); |
pinkyKathlea | 2:c87703888e97 | 15 | //char c; |
pinkyKathlea | 2:c87703888e97 | 16 | |
RobertoO | 0:67c50348f842 | 17 | |
RobertoO | 1:b862262a9d14 | 18 | MODSERIAL pc(USBTX, USBRX); |
pinkyKathlea | 2:c87703888e97 | 19 | // Example: 4th order Butterworth LP (w_c = 0.1*f_nyquist) |
pinkyKathlea | 2:c87703888e97 | 20 | BiQuad lowpass( 4.16599e-04, 8.33198e-04, 4.16599e-04, -1.47967e+00, 5.55822e-01 ); |
pinkyKathlea | 2:c87703888e97 | 21 | BiQuad bq2( 1.00000e+00, 2.00000e+00, 1.00000e+00, -1.70096e+00, 7.88500e-01 ); |
pinkyKathlea | 2:c87703888e97 | 22 | BiQuadChain bqc; |
pinkyKathlea | 2:c87703888e97 | 23 | |
pinkyKathlea | 2:c87703888e97 | 24 | AnalogIn emg0( A0 ); |
pinkyKathlea | 2:c87703888e97 | 25 | AnalogIn emg1( A1 ); |
pinkyKathlea | 2:c87703888e97 | 26 | |
pinkyKathlea | 2:c87703888e97 | 27 | Ticker sample_timer; |
pinkyKathlea | 2:c87703888e97 | 28 | HIDScope scope( 2 ); |
pinkyKathlea | 2:c87703888e97 | 29 | |
pinkyKathlea | 2:c87703888e97 | 30 | |
pinkyKathlea | 2:c87703888e97 | 31 | |
pinkyKathlea | 2:c87703888e97 | 32 | void sample() |
pinkyKathlea | 2:c87703888e97 | 33 | { |
pinkyKathlea | 2:c87703888e97 | 34 | /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ |
pinkyKathlea | 2:c87703888e97 | 35 | scope.set(0, emg0.read() ); |
pinkyKathlea | 2:c87703888e97 | 36 | scope.set(1, emg1.read() ); |
pinkyKathlea | 2:c87703888e97 | 37 | /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) |
pinkyKathlea | 2:c87703888e97 | 38 | * Ensure that enough channels are available (HIDScope scope( 2 )) |
pinkyKathlea | 2:c87703888e97 | 39 | * Finally, send all channels to the PC at once */ |
pinkyKathlea | 2:c87703888e97 | 40 | scope.send(); |
pinkyKathlea | 2:c87703888e97 | 41 | /* To indicate that the function is working, the LED is toggled */ |
pinkyKathlea | 2:c87703888e97 | 42 | led = !led; |
pinkyKathlea | 2:c87703888e97 | 43 | } |
RobertoO | 0:67c50348f842 | 44 | |
RobertoO | 0:67c50348f842 | 45 | int main() |
RobertoO | 0:67c50348f842 | 46 | { |
RobertoO | 0:67c50348f842 | 47 | pc.baud(115200); |
RobertoO | 1:b862262a9d14 | 48 | pc.printf("\r\nStarting...\r\n\r\n"); |
pinkyKathlea | 2:c87703888e97 | 49 | //pc.attach(ProcessCharacter, MODSERIAL::RxIrq); |
pinkyKathlea | 2:c87703888e97 | 50 | pc.getc(); |
pinkyKathlea | 2:c87703888e97 | 51 | |
pinkyKathlea | 2:c87703888e97 | 52 | // button.rise(&flip); // attach the address of the flip function to the rising edge |
pinkyKathlea | 2:c87703888e97 | 53 | |
pinkyKathlea | 2:c87703888e97 | 54 | |
pinkyKathlea | 2:c87703888e97 | 55 | sample_timer.attach(&sample, 0.002); |
pinkyKathlea | 2:c87703888e97 | 56 | // Add the biquads to the chain |
pinkyKathlea | 2:c87703888e97 | 57 | |
pinkyKathlea | 2:c87703888e97 | 58 | |
pinkyKathlea | 2:c87703888e97 | 59 | while(1) { // wait around, interrupts will interrupt this! |
pinkyKathlea | 2:c87703888e97 | 60 | |
RobertoO | 0:67c50348f842 | 61 | } |
pinkyKathlea | 2:c87703888e97 | 62 | |
RobertoO | 0:67c50348f842 | 63 | } |