Galileo Hand Basic Example implemented on FRDM K64F
Dependencies: NOKIA_5110 mbed-dsp mbed
Fork of Nucleo_EMG_Galileo_Hand by
Revision 6:78494092a326, committed 2015-11-01
- Comitter:
- julioefajardo
- Date:
- Sun Nov 01 18:35:45 2015 +0000
- Parent:
- 5:49c5553b6e2c
- Commit message:
- FRDM EMG Galileo Hand Basic Examples
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Oct 11 03:42:30 2015 +0000 +++ b/main.cpp Sun Nov 01 18:35:45 2015 +0000 @@ -11,8 +11,10 @@ #define FLEXION2 0.0f Ticker EMG_Sampler; -Serial pc(SERIAL_TX, SERIAL_RX); +//Serial pc(SERIAL_TX, SERIAL_RX); +Serial pc(USBTX, USBRX); DigitalOut myled(LED1); +InterruptIn sw2(SW2); AnalogIn Ref(A0); AnalogIn E1(A1); AnalogIn E2(A2); @@ -37,7 +39,7 @@ //variables for state machines uint8_t state = 0; -uint8_t action = 0; +uint8_t action = '0'; //conversion and data collection complete flag uint8_t COCO = 0; @@ -48,10 +50,16 @@ void RX_Interrupt(void); void Serial_Oscilloscope(uint8_t activation, uint8_t type); void FingerPosition(float32_t thumb_us, float32_t index_us, float32_t middle_us, float32_t pinky_us, float32_t thumbrot_us); - + +void flip() { + if(action<='5') action++; + else action = '1'; +} + int main() { pc.baud(115200); //Serial com at 115200 bauds pc.attach(&RX_Interrupt); //Serial RX interrupt attachment + sw2.rise(&flip); EMG_Sampler.attach(&ADC_Sampler, 0.001); //1 ms ticker for ADC Sampler PWM_Init(); //Servo initialization myled = 1; @@ -64,7 +72,7 @@ arm_mean_f32(abs_output, 25, &mean); //mean EMG1 arm_mean_f32(abs_output2, 25, &mean2); //mean EMG2 arm_mean_f32(abs_output3, 25, &mean3); //mean EMG3 - Serial_Oscilloscope(FALSE,SMOOTH); + Serial_Oscilloscope(TRUE,SMOOTH); switch(state){ case 0: { if (mean>THRESHOLDF){ @@ -84,7 +92,7 @@ if (mean2>THRESHOLDE){ myled = 1; state = 0; - FingerPosition(1000,2400,2400, 600, 600); //Open + FingerPosition(1000,2400,2400, 600, 2400); //Open } } } @@ -98,7 +106,7 @@ EMG1 = (E1.read()-Ref.read())*3.3f; EMG2 = (E2.read()-Ref.read())*3.3f; EMG3 = (E3.read()-Ref.read())*3.3f; - Serial_Oscilloscope(TRUE,RAW); + Serial_Oscilloscope(FALSE,RAW); uint32_t m = __get_PRIMASK(); __disable_irq(); for(int j=24;j>0;j--) { @@ -129,38 +137,38 @@ //PWM initialization for servos void PWM_Init(void){ //Open -> 0.6ms - Close 2.4ms - Thumb.period(0.02f/2.0f); - Thumb.pulsewidth(0.0010f/2.0f); + Thumb.period(0.02f); + Thumb.pulsewidth(0.0010f); //Open -> 2.4ms - Close 0.6ms - Index.period(0.02f*2.0f); - Index.pulsewidth(0.0024f*2.0f); + //Index.period(0.02f); + Index.pulsewidth(0.0024f); //Open -> 2.4ms - Close 0.6ms - Middle.period(0.02f*2.0f); - Middle.pulsewidth(0.0024f*2.0f); + Middle.period(0.02f); + Middle.pulsewidth(0.0024f); //Open -> 0.6ms - Close 2.4ms - Pinky.period(0.02f*2.0f); - Pinky.pulsewidth(0.0006f*2.0f); + //Pinky.period(0.02f); + Pinky.pulsewidth(0.0006f); //Open -> 0.6ms - Close 2.4ms - ThumbRot.pulsewidth(0.0006f*2.0f); + ThumbRot.pulsewidth(0.0006f); } //send data through serail port for oscilloscope visualization void Serial_Oscilloscope(uint8_t activation, uint8_t type){ if (activation){ switch(type){ - case RAW: pc.printf("%.10f,%.10f,%.10f\n\r",EMG1,EMG2,EMG3); break; - case RECTIFIED: pc.printf("%.10f,%.10f,%.10f\n\r",abs_output[0],abs_output2[0],abs_output3[0]);break; - case SMOOTH: pc.printf("%.10f,%.10f\n\r",mean,mean2,mean3); break; - default: pc.printf("%.10f,%.10f,%.10f\n\r",EMG1,EMG2,EMG3); + case RAW: pc.printf("%.10f,%.10f\n\r",EMG1,EMG2); break; + case RECTIFIED: pc.printf("%.10f,%.10f\n\r",abs_output[0],abs_output2[0]);break; + case SMOOTH: pc.printf("%.10f,%.10f\n\r",mean,mean2); break; + default: pc.printf("%.10f,%.10f\n\r",EMG1,EMG2); } } } //finger position through servos - values on microseconds (600 us - 2400 us) void FingerPosition(float32_t thumb_us, float32_t index_us, float32_t middle_us, float32_t pinky_us, float32_t thumbrot_us){ - Thumb.pulsewidth(thumb_us/1000000.0f/2.0f); - Index.pulsewidth(index_us/1000000.0f*2.0f); - Middle.pulsewidth(middle_us/1000000.0f*2.0f); - Pinky.pulsewidth(pinky_us/1000000.0f*2.0f); - ThumbRot.pulsewidth(thumbrot_us/1000000.0f*2.0f); + Thumb.pulsewidth(thumb_us/1000000.0f); + Index.pulsewidth(index_us/1000000.0f); + Middle.pulsewidth(middle_us/1000000.0f); + Pinky.pulsewidth(pinky_us/1000000.0f); + ThumbRot.pulsewidth(thumbrot_us/1000000.0f); }