4 directional EMG control of the XY table. Made during my bachelor end assignment.
Dependencies: C12832_lcd HIDScope mbed-dsp mbed
Revision 36:d6e0a835bb2d, committed 2015-05-27
- Comitter:
- jessekaiser
- Date:
- Wed May 27 14:49:14 2015 +0000
- Parent:
- 35:b0737ee24b43
- Child:
- 37:3b9b18450612
- Commit message:
- The K_gain and Max_emg are configured for a normalized emg signal and speed should be between 0 and 1. Can go a bit higher.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed May 27 14:20:06 2015 +0000 +++ b/main.cpp Wed May 27 14:49:14 2015 +0000 @@ -3,11 +3,11 @@ #include "arm_math.h" #include "HIDScope.h" -#define K_Gain 65 //Gain of the filtered EMG signal -#define Damp 2 //Deceleration of the motor +#define K_Gain 8 //Gain of the filtered EMG signal +#define Damp 4 //Deceleration of the motor #define Mass 1 // Mass value #define dt 0.002 //Sample frequency -#define MAX_emg //Can be used for normalisation of the EMG signal +#define MAX_emg 0.05 //Can be used for normalisation of the EMG signal #define MIN_freq 900 //The motor turns off below this frequency //Motor control @@ -35,7 +35,7 @@ C12832_LCD lcd; //Variables for motor control -float setpoint = 9000; //Frequentie +float setpoint = 9000; //Frequentie setpint float step_freq = 1; //EMG filter @@ -61,29 +61,25 @@ void looper_emg() { - /*variable to store value in*/ - volatile uint16_t emg_value1; + float emg_value1_f32; - - /*put raw emg value both in red and in emg_value*/ - emg_value1 = emg0.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) (KAN weg?) emg_value1_f32 = emg0.read(); //process emg biceps arm_biquad_cascade_df1_f32(&highnotch_biceps, &emg_value1_f32, &filtered_biceps, 1 ); filtered_biceps = fabs(filtered_biceps); arm_biquad_cascade_df1_f32(&lowpass_biceps, &filtered_biceps, &filtered_biceps, 1 ); - + /*send value to PC. */ - scope.set(0,emg0.read()); //Filtered EMG signal + scope.set(0,filtered_biceps); //Filtered EMG signal } void looper_motor() { Dir = 0; - force = K_Gain*filtered_biceps; + force = K_Gain*(filtered_biceps/MAX_emg); force = force - D; acc = force/Mass; speed = speed_old + (acc * dt); @@ -111,7 +107,7 @@ Ticker looptimer; looptimer.attach(looper_motor, 0.01); //Uitzoeken waarom deze frequentie! - + //Microstepping control MS1 = 1; MS2 = 0; @@ -120,8 +116,8 @@ while (1) { - lcd.printf("Freq %.0f Hz \n", step_freq); //snelheid meting op lcd - //pc.printf("%.3f \n", emg0.read()); + lcd.printf("Freq %.0f Hz, %.2f \n", step_freq, speed); //snelheid meting op lcd + //pc.printf("%.3f \n", emg0.read()); wait(0.01); } }