Overzetten
Dependencies: HIDScope MODSERIAL mbed
main.cpp
00001 #include "mbed.h" 00002 #include "MODSERIAL.h" 00003 #include "HIDScope.h" 00004 MODSERIAL pc(USBTX, USBRX); 00005 00006 DigitalOut DirectionPin1(D4); 00007 PwmOut PwmPin1(D5); 00008 DigitalOut DirectionPin2(D7); 00009 PwmOut PwmPin2(D6); 00010 DigitalIn Knop1(D3); 00011 DigitalIn Knop2(D2); 00012 DigitalIn Knop3(PTA4); 00013 DigitalIn Knop4(PTC6); 00014 AnalogIn emg0( A0 ); 00015 AnalogIn emg1( A1 ); 00016 00017 Ticker sample_timer; 00018 HIDScope scope( 2 ); 00019 DigitalOut led(LED1); 00020 00021 Ticker EMG_Read_Ticker; 00022 00023 volatile float Bicep_Right = 0.0; 00024 00025 void EMG_Read() 00026 { 00027 Bicep_Right = emg0.read(); 00028 pc.printf("%f ", Bicep_Right); 00029 } 00030 00031 void sample() 00032 { 00033 00034 scope.set(0, emg0.read() ); 00035 scope.set(1, emg1.read() ); 00036 00037 scope.send(); 00038 led = !led; 00039 } 00040 00041 int Turn_Motor1() 00042 { 00043 00044 00045 if(!Knop1 && !Knop3 == true) // Motor 1 rotates CW 00046 { 00047 PwmPin1 = fabs(0.0); 00048 } 00049 00050 else if (Knop1==false) // Motor 1 rotates CW 00051 { 00052 float u = 0.8f; //determine useful value, this is not final 00053 DirectionPin1 = u > 0.0f; //either true or false 00054 // True = CW, for False = CW 00055 PwmPin1 = fabs(u); 00056 PwmPin2 = fabs(0.0); 00057 } 00058 00059 else if (Knop3==false)// We see that Motor2 keeps rotating if we leave out the "else" statement, somehow the signal leaks 00060 { 00061 float u = 0.8f; 00062 DirectionPin1 = u < 0.0f; 00063 PwmPin1 = fabs(u); 00064 PwmPin2 = fabs(0.0); 00065 } 00066 00067 else if (Bicep_Right > 0.55f) 00068 { 00069 float u = 0.8f; //determine useful value, this is not final 00070 DirectionPin1 = u > 0.0f; //either true or false 00071 // True = CW, for False = CW 00072 PwmPin1 = fabs(u); 00073 PwmPin2 = fabs(0.0); 00074 } 00075 00076 else 00077 { 00078 float u = 0.0f; 00079 PwmPin1 = fabs(u); 00080 } 00081 return 0; 00082 } 00083 00084 int Turn_Motor2() 00085 { 00086 if (!Knop2 && !Knop4 == true) 00087 { 00088 PwmPin2 = fabs(0.0); 00089 } 00090 00091 else if (Knop2==false) 00092 { 00093 float u = 0.8f; 00094 DirectionPin2 = u < 0.0f; 00095 PwmPin1 = fabs(0.0); 00096 PwmPin2 = fabs(u); 00097 } 00098 00099 else if (Knop4==false) 00100 { 00101 float u = 0.8f; 00102 DirectionPin2 = u > 0.0f; 00103 PwmPin1 = fabs(0.0); 00104 PwmPin2 = fabs(u); 00105 00106 } 00107 00108 else 00109 { 00110 float u = 0.0f; 00111 PwmPin2 = fabs(u); 00112 } 00113 return 0; 00114 } 00115 00116 int main()//Ticker toevoegen 00117 { 00118 pc.baud(115200); 00119 sample_timer.attach(&sample, 0.002); 00120 PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz 00121 00122 EMG_Read_Ticker.attach(&EMG_Read, 0.002); 00123 00124 while(true) 00125 { 00126 Turn_Motor1(); 00127 Turn_Motor2(); 00128 pc.printf("%f ", Bicep_Right); 00129 } 00130 }
Generated on Mon Jul 18 2022 14:18:50 by
1.7.2