to send emg signal to motor with test programm
Dependencies: HIDScope biquadFilter mbed
Fork of EMGvoorjan by
Diff: main.cpp
- Revision:
- 34:008bd226d37e
- Parent:
- 33:84d986230e15
- Child:
- 35:5a8a7bd8ae59
--- a/main.cpp Thu Oct 26 07:55:14 2017 +0000 +++ b/main.cpp Thu Oct 26 09:29:42 2017 +0000 @@ -12,10 +12,10 @@ DigitalIn TestButton(PTA4); // button naast het ledje DigitalIn onoff(PTC6); // button aan de andere kant Ticker emgSampleTicker; // Ticker voor de sample frequency -DigitalOut motor2MagnitudePin(D5); // magnitude motor 2 +PwmOut motor2MagnitudePin(D5); // magnitude motor 2 DigitalOut motor2DirectionPin(D4); // direction of the motor 2 -InterruptIn MotorOn(D10); -InterruptIn SpeedUp(D12); +InterruptIn MotorOn(D8); + int P= 200; // aantal test punten voor de moving average @@ -30,6 +30,7 @@ float ErrorZero = 3; double MotorSpeed = 0.5; + // Filters BiQuadChain bqc; BiQuad bq1( 0.6844323315947305,1.368864663189461, 0.6844323315947305,1.2243497755555954,0.5133795508233265); //lp? @@ -45,7 +46,7 @@ double emgabs = abs(emgFiltered); // absolute waarde van het gefilterde signaal scope.set(0, emgFiltered ); // stuurt de waarden naar de grafiek scope.set(1, emgabs ); // stuurt de waarden naar de grafiek - Vwaarde[0] = 0.01; + // deze for-loop maakt de vector voor de moving average for(int i = P-1; i >= 0; i--){ @@ -109,8 +110,9 @@ } scope.set(5,EMGInput); + scope.send(); - scope.send(); + //motor2MagnitudePin = 0.2; } float GetReferenceVelocity() @@ -148,28 +150,18 @@ } } -void TestMotorSpeed() { - if (MotorSpeed == 0.5) { - MotorSpeed = 1.0; - } - else if (MotorSpeed == 1.0) { - MotorSpeed == 0.5; - } -} - int main() { ledB = 1; ledG = 1; bqc.add( &bq1 ).add( &bq2 ).add( &bq3 ); // hier wordt het filter gemaakt emgSampleTicker.attach( &emgSample, 0.002 ); //dit bepaald de sample frequency en is nu 500 Hz +Vwaarde[0] = 0.01; +motor2DirectionPin = 1; - while(1) { MotorOn.rise(&MotorLocker); - motor2DirectionPin = 1; - //SetMotor2(FeedForwardControl(GetReferenceVelocity())); - SpeedUp.rise(&TestMotorSpeed); - motor2MagnitudePin = MotorSpeed; + motor2MagnitudePin = EMGInput; + wait(0.01); } } \ No newline at end of file