EMG aansluiten op motor
Dependencies: FastPWM HIDScope MODSERIAL mbed
Revision 3:4b3ccfbae1c1, committed 2018-10-16
- Comitter:
- MAHCSnijders
- Date:
- Tue Oct 16 11:34:12 2018 +0000
- Parent:
- 2:9c1bdcf6bc26
- Commit message:
- Alles bij elkaar so far
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9c1bdcf6bc26 -r 4b3ccfbae1c1 main.cpp --- a/main.cpp Thu Oct 11 14:35:38 2018 +0000 +++ b/main.cpp Tue Oct 16 11:34:12 2018 +0000 @@ -10,28 +10,28 @@ DigitalOut directionpin2(D7); // SPECIFIC PIN (does not need to be plugged in) Direction value (0-1) that the mbed will give the motor: in which direction the motor must rotate AnalogIn emg0( A0 ); // EMG on Bicep 1a AnalogIn emg1( A1 ); // EMG on Bicep 1b -AnalogIn emg2( A2 ); // EMG on Bicep 2a CHECK IF THIS WORKS -AnalogIn emg3( A3 ); // EMG on Bicep 2b CHECK IF THIS WORKS +//AnalogIn emg2( A2 ); // EMG on Bicep 2a CHECK IF THIS WORKS +//AnalogIn emg3( A3 ); // EMG on Bicep 2b CHECK IF THIS WORKS DigitalOut led(LED1); // LED check for Sample function InterruptIn button1(PTC6); // Button interrupt for EMG 1 -InterruptIn button2(PTA4); // Button interrupt for EMG 2 +//InterruptIn button2(PTA4); // Button interrupt for EMG 2 DigitalOut ledb1(LED_RED); // LED check for button_pressed1 function -DigitalOut ledb2(LED_GREEN); // LED check for button_pressed2 function +//DigitalOut ledb2(LED_GREEN); // LED check for button_pressed2 function // Define variables Ticker sample_timer; // Ticker for EMG sample function -HIDScope scope( 2 ); // HIDScope for EMG +HIDScope scope( 2 ); // HIDScope for EMG Ticker motor; // Ticker function for motor function volatile float u1; // Motor 1 control signal -volatile float u2; // Motor 2 control signal +//volatile float u2; // Motor 2 control signal void sample() // Function for getting EMG signals { // Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' scope.set(0, emg0.read() ); scope.set(1, emg1.read() ); - scope.set(0, emg2.read() ); // CHECK IF THIS WORKS - scope.set(1, emg3.read() ); // CHECK IF THIS WORKS +// scope.set(0, emg2.read() ); // CHECK IF THIS WORKS +// scope.set(1, emg3.read() ); // CHECK IF THIS WORKS // Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) // Ensure that enough channels are available (HIDScope scope( 2 )) // Finally, send all channels to the PC at once @@ -46,26 +46,29 @@ directionpin1 = 0; // Direction for motor 1 becomes negative CHECK IF THIS WORKS } -void button_pressed2() // Indicates direction of motor 2 becomes negative - { - ledb2 = 0; // Turns on green led as indication of negative direction for motor 2 - directionpin2 = 0; // Direction for motor 2 becomes negative CHECK IF THIS WORKS - } +//void button_pressed2() // Indicates direction of motor 2 becomes negative +// { +// ledb2 = 0; // Turns on green led as indication of negative direction for motor 2 +// directionpin2 = 0; // Direction for motor 2 becomes negative CHECK IF THIS WORKS +// } void motorfunction() // Function for motor control { - u1 = EMG1_scale; // Motor control signal - u2 = EMG2_scale; // Motor control signal + u1 = emg0.read(); // EMG1_scale; // Motor control signal +// u2 = emg0.read(); // EMG2_scale; // Motor control signal pwmpin1 = fabs(u1); // PWM duty cycle can only be positive, floating point absolute value (if value is >0, there still will be a positive value). - pwmpin2 = fabs(u2); // PWM duty cycle can only be positive, floating point absolute value (if value is >0, there still will be a positive value). +// pwmpin2 = fabs(u2); // PWM duty cycle can only be positive, floating point absolute value (if value is >0, there still will be a positive value). } int main() { + led = 0; + ledb1 = 0; +// ledb2 = 1; sample_timer.attach(&sample, 0.002); // 500 Hz pwmpin1.period_us(60.0); //60 microseconds PWM period, 16.7 kHz, defines all PWM pins (only needs to be done once) motor.attach(motorfunction,0.5); button1.fall(&button_pressed1); // Whenever button 1 falls, execute button_pressed1 function (blinks led red and changes motor direction) - button2.fall(&button_pressed2); // Whenever button 2 falls, execute button_pressed1 function (blinks led green and changes motor direction) +// button2.fall(&button_pressed2); // Whenever button 2 falls, execute button_pressed1 function (blinks led green and changes motor direction) while(1) {} } \ No newline at end of file