Werkcollege opgave 23 september BMT K9

Dependencies:   Encoder HIDScope MODSERIAL mbed QEI biquadFilter

main.cpp

Committer:
bscheltinga
Date:
2015-10-09
Revision:
22:14abcfdd1554
Parent:
21:594915ba2bf9
Child:
23:c9c9c1d7864a

File content as of revision 22:14abcfdd1554:

#include "mbed.h"
#include "HIDScope.h"
#include "MODSERIAL.h"
#include "biquadFilter.h" //Filter direct form II

//Define inputs
AnalogIn    emgL(A0); //Analog input left arm
//AnalogIn    emgR(PTB1); //Analog input right arm
DigitalOut  led1(LED_GREEN);

MODSERIAL pc(USBTX,USBRX);
volatile bool control_go = false;
Ticker control_tick;

//Define constants
float emgL_L;
float emgL_LH;

const float la1 = 0;
const float la2 = 0.17156822136;
const float lb0 = 0.2928920553;
const float lb1 = 0.5857841107;
const float lb2 = 0.2928920554; // Waarde van biquads via groep 1 2014
biquadFilter Lowpassfilter (la1, la2, lb0, lb1, lb2);

const float ha1 = -1.5610153913;
const float ha2 = 0.6413487154;
const float hb0 = 0.8005910267;
const float hb1 = -1.6011820533;
const float hb2 = 0.8005910267; // Waarde van biquads via groep 1 2014
biquadFilter Highpassfilter (ha1, ha2, hb0, hb1, hb2);

HIDScope scope(3); // Aantal HIDScope kanalen

void ControlGo() //Control flag
{
    control_go = true;
    led1 = 0;
}

int main()
{
    control_tick.attach(&ControlGo, 0.01);
    pc.baud(9600);

    while(true) {
        
        if(control_go)
        emgL_L = Lowpassfilter.step(emgL.read()); //emgL_L Linker bicep met lowpass filter
        emgL_LH = Highpassfilter.step(emgL_L); //emgL_L met Highpassfilter
        scope.set(0,emgL.read());
        scope.set(1,emgL_L);
        scope.set(2,emgL_LH);
        scope.send();
        led1 = 1; //De led gaat flikkeren wanneer deze loop uitgevoerd wordt

    }
}