4 directional EMG control of the XY table. Made during my bachelor end assignment.

Dependencies:   C12832_lcd HIDScope mbed-dsp mbed

Files at this revision

API Documentation at this revision

Comitter:
jessekaiser
Date:
Tue Jun 16 09:33:08 2015 +0000
Parent:
58:3ea066215c31
Child:
60:664f9b907c02
Commit message:
Eindconcept 8. Motor control in de while loop

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jun 16 09:29:43 2015 +0000
+++ b/main.cpp	Tue Jun 16 09:33:08 2015 +0000
@@ -131,8 +131,46 @@
     scope.set(3,filtered_deltoid);*/
 }
 
-void looper_motory()
+
+int main()
 {
+    // Attach the HIDScope::send method from the scope object to the timer at 500Hz. Hier wordt de sample freq aangegeven.
+    // scopeTimer.attach_us(&scope, &HIDScope::send, 2e3);
+
+    Ticker emgtimer;    //biceps
+    arm_biquad_cascade_df1_init_f32(&lowpass_biceps, 1 , lowpass_const, lowpass_biceps_states);
+    arm_biquad_cascade_df1_init_f32(&highnotch_biceps, 2 , highnotch_const, highnotch_biceps_states);
+    //triceps
+    arm_biquad_cascade_df1_init_f32(&lowpass_triceps, 1 , lowpass_const, lowpass_triceps_states);
+    arm_biquad_cascade_df1_init_f32(&highnotch_triceps, 2 , highnotch_const, highnotch_triceps_states);
+    //pectoralis major
+    arm_biquad_cascade_df1_init_f32(&lowpass_pect, 1 , lowpass_const, lowpass_pect_states);
+    arm_biquad_cascade_df1_init_f32(&highnotch_pect, 2 , highnotch_const, highnotch_pect_states);
+    //deltoid
+    arm_biquad_cascade_df1_init_f32(&lowpass_deltoid, 1 , lowpass_const, lowpass_deltoid_states);
+    arm_biquad_cascade_df1_init_f32(&highnotch_deltoid, 2 , highnotch_const, highnotch_deltoid_states);
+    emgtimer.attach(looper_emg, 0.01);
+
+    /*Ticker looptimer1;
+    looptimer1.attach(looper_motorx, 0.01); //X-Spindle motor, why this freq?
+
+    Ticker looptimer2;
+    looptimer2.attach(looper_motory, 0.01); //Y-Spindle motor*/
+
+    //Microstepping control, now configured as half stepping (MS1=1,MS2=0,MS3=0)
+    MS1 = 1;
+    MS2 = 0;
+    MS3 = 0;
+    Stepx.write(0.5); // Duty cycle of 50%
+    Stepy.write(0.5);
+
+    //if (Posx < 0.50) {
+    //  Stepx.period(1.0/3000); //if the speed and distance is known. The motor can be brought to a home position.
+    //Need to know rpm to m/s.
+
+
+    while (1) {
+
     //Forward
     force1 = (filtered_biceps/MAX_bi); //MAX_bi is used to normalize the signal
     force1 = force1 - damping1;
@@ -185,10 +223,6 @@
         Enabley = 0;
     }
 
-}
-
-void looper_motorx()
-{
     //To the left
     force3 = (filtered_pect/MAX_pect);
     force3 = force3 - damping3;
@@ -241,45 +275,6 @@
         Enablex = 0;
     }
 
-}
-int main()
-{
-    // Attach the HIDScope::send method from the scope object to the timer at 500Hz. Hier wordt de sample freq aangegeven.
-    // scopeTimer.attach_us(&scope, &HIDScope::send, 2e3);
-
-    Ticker emgtimer;    //biceps
-    arm_biquad_cascade_df1_init_f32(&lowpass_biceps, 1 , lowpass_const, lowpass_biceps_states);
-    arm_biquad_cascade_df1_init_f32(&highnotch_biceps, 2 , highnotch_const, highnotch_biceps_states);
-    //triceps
-    arm_biquad_cascade_df1_init_f32(&lowpass_triceps, 1 , lowpass_const, lowpass_triceps_states);
-    arm_biquad_cascade_df1_init_f32(&highnotch_triceps, 2 , highnotch_const, highnotch_triceps_states);
-    //pectoralis major
-    arm_biquad_cascade_df1_init_f32(&lowpass_pect, 1 , lowpass_const, lowpass_pect_states);
-    arm_biquad_cascade_df1_init_f32(&highnotch_pect, 2 , highnotch_const, highnotch_pect_states);
-    //deltoid
-    arm_biquad_cascade_df1_init_f32(&lowpass_deltoid, 1 , lowpass_const, lowpass_deltoid_states);
-    arm_biquad_cascade_df1_init_f32(&highnotch_deltoid, 2 , highnotch_const, highnotch_deltoid_states);
-    emgtimer.attach(looper_emg, 0.01);
-
-    Ticker looptimer1;
-    looptimer1.attach(looper_motorx, 0.01); //X-Spindle motor, why this freq?
-
-    Ticker looptimer2;
-    looptimer2.attach(looper_motory, 0.01); //Y-Spindle motor
-
-    //Microstepping control, now configured as half stepping (MS1=1,MS2=0,MS3=0)
-    MS1 = 1;
-    MS2 = 0;
-    MS3 = 0;
-    Stepx.write(0.5); // Duty cycle of 50%
-    Stepy.write(0.5);
-
-    //if (Posx < 0.50) {
-    //  Stepx.period(1.0/3000); //if the speed and distance is known. The motor can be brought to a home position.
-    //Need to know rpm to m/s.
-
-
-    while (1) {
 
         //lcd.printf("x %.2f, y %.2f \n", Posx.read(), Posy.read());
         lcd.printf("%.2f, %.2f %.2f %.2f \n", filtered_biceps, filtered_triceps, filtered_pect, filtered_deltoid); //Filtered EMG values