Facking kut filter werkt EINDELIJK !311!!111!!1!!!!!!!!!!!!!!!!!!!
Dependencies: HIDScope MODSERIAL Matrix QEI biquadFilter mbed
Fork of Filter by
Diff: main.cpp
- Revision:
- 3:c8f0fc045505
- Parent:
- 2:dc9766657afb
- Child:
- 4:8f67b8327300
diff -r dc9766657afb -r c8f0fc045505 main.cpp --- a/main.cpp Mon Oct 22 08:15:41 2018 +0000 +++ b/main.cpp Mon Oct 22 14:51:46 2018 +0000 @@ -16,6 +16,13 @@ AnalogIn emg2( A2 ); AnalogIn emg3( A3 ); +DigitalIn a1( D10); +DigitalIn b1( D11); +DigitalIn a2( D12); +DigitalIn b2( D13); + + +Ticker EncodingTicker; Ticker printTicker; Ticker mycontrollerTicker1; Ticker mycontrollerTicker2; @@ -25,19 +32,33 @@ Ticker sample_timer; HIDScope scope( 4 ); -volatile float Bicep_Right = 0.0; -volatile const float maxVelocity=8.4; // in rad/s -volatile float referenceVelocity1 = 0.5; //dit is de gecentreerde waarde en dus de nulstand -volatile float referenceVelocity2 = 0.5; +volatile float Bicep_Right = 0.0; +volatile float Bicep_Left = 0.0; +volatile float Tricep_Right = 0.0; +volatile float Tricep_Left = 0.0; +volatile const float maxVelocity = 8.4; // in rad/s +volatile float referenceVelocity1 = 0.5; //dit is de gecentreerde waarde en dus de nulstand +volatile float referenceVelocity2 = 0.5; volatile int counts1; volatile int counts2; -QEI Encoder1(D12,D13,NC,64,QEI::X4_ENCODING); -QEI Encoder2(D10,D11,NC,64,QEI::X4_ENCODING); + +void Encoding() +{ + + QEI Encoder1(D12,D13,NC,32); + QEI Encoder2(D10,D11,NC,64,QEI::X4_ENCODING); + counts1 = Encoder1.getPulses(); + counts2 = Encoder2.getPulses(); + +} void EMG_Read() { - Bicep_Right = emg0.read(); + Bicep_Right = emg0.read(); + Bicep_Left = emg1.read(); + Tricep_Right = emg2.read(); + Tricep_Left = emg3.read(); } void sample() @@ -54,7 +75,7 @@ void velocity1() { - if ((pot1.read()>0.5f) || (Knop1 == true))//gezeik met die knop doet het niet ff uitzoeken nog + if (pot1.read()>0.5f) { // Clockwise rotation referenceVelocity1 = (pot1.read()-0.5f) * 2.0f; @@ -114,7 +135,7 @@ //eventueel nog counts -> rad/s //pc.printf("%f \n %f snelheid Motor1 \n %f snelheid Motor2 \n", Bicep_Right,v1,v2); - pc.printf("%i counts van m1, %i counts van m2", counts1, counts2); + pc.printf("%f ", counts1); } @@ -122,10 +143,9 @@ int main() { pc.baud(115200); - PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz + PwmPin1.period_us(40); //60 microseconds pwm period, 16.7 kHz - counts1 = Encoder1.getPulses(); - counts2 = Encoder2.getPulses(); + EncodingTicker.attach(&Encoding, 0.002); sample_timer.attach(&sample, 0.002); EMG_Read_Ticker.attach(&EMG_Read, 0.002);