With this script a Ball-E robot can be made and be operative for the use.
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of Samenvoegen_7_5 by
Diff: main.cpp
- Revision:
- 7:d55569b92f30
- Parent:
- 6:1518fccc5616
- Child:
- 8:151e43b99156
diff -r 1518fccc5616 -r d55569b92f30 main.cpp --- a/main.cpp Mon Oct 26 11:13:37 2015 +0000 +++ b/main.cpp Mon Oct 26 12:07:05 2015 +0000 @@ -75,7 +75,6 @@ double cali_max2 = 0; // Declares max y2. double cali_array1[2560] = {}; // Array to store values in for the 5 seconds calibartion for y1. double cali_array2[2560] = {}; // Array to store values in for the 5 seconds calibartion for y2. -volatile bool sample_go; // Ticker EMG function. bool flag_calibration = true; // Flag to start the calibration. //**************************** VARIABLES FOR FASE SWITCH *********************************** @@ -175,7 +174,6 @@ if(flag_calibration == false) { hoog_laag_filter(); - sample_go = 1; } } @@ -202,16 +200,16 @@ //************************* CONTROL 1-EMG CALIBRATION **************************** while(1) { - if(sample_go) - { - sample_go = 0; - } - if (flag_calibration) // function to calibrate the emg signals from the user. It takes 5 seconds of measurements of maximum output, then takes the max and normalizes to that. { calibration_measurements ++; pc.printf(" \n\n EMG Signal starting up Calibration measurement........... \n"); + cali_max1 = 0; // declare max y1 + cali_max2 = 0; //declare max y2 + cali_fact1 = 0.9; // calibration factor to normalize filter output to a scale of 0 - 1 + cali_fact2 = 0.9; + wait(2); led_red.write(0); wait(0.2); @@ -229,6 +227,7 @@ pc.printf("\t.....Calibrating Signal of EMG 1 and 2 .......\n"); led_red.write(0); led_yellow.write(1); + wait(0.5); pc.printf("\t......contract muscles..... \n"); @@ -398,12 +397,12 @@ if (y2 > minimum_contract & y2 < medium_contract) { - speed_control_arm = ((v_arm/304) + 0.15*(1 -(v_arm/304))); + speed_control_arm = 1;//((v_arm/304) + 0.15*(1 -(v_arm/304))); motor1speed.write(speed_control_arm); } if (y2 > medium_contract) // Hoger dan drempelwaarde = Actief { - speed_control_arm = ((v_arm/304) + 0.15*(1 -(v_arm/304))); + speed_control_arm = 1;//((v_arm/304) + 0.15*(1 -(v_arm/304))); motor1speed.write(speed_control_arm); } if (y2 < minimum_contract) // Lager dan drempel = Rust @@ -421,8 +420,6 @@ { j++; wait(0.01); // Problemen met EMG metingen die te hoog zijn op het begin van script na calibratie. vandaar ff wachten en de sample loop een paar keer doorlopen. - Encoderread1 = wheel1.getPulses(); - pos_arm = (Encoderread1/((64.0*131.0)/360.0)); // Omrekenen naar graden van arm if( j > N) { @@ -476,6 +473,7 @@ if (y1> maximum_leftbiceps) { magnet.write(off); + wait(0.1); motor1speed.write(relax); fase = 3; pc.printf("Van fase 2 naar fase 3\n"); @@ -551,10 +549,10 @@ board = false; wait(2); games_played ++; - games_played1 = games_played - (3*calibration_measurements - 3); + games_played1 = games_played - (5*calibration_measurements - 5); pc.printf("Games played total count = %i and loop %i\n",games_played,games_played1); - if(games_played1 == 3) + if(games_played1 == 5) { flag_calibration = true; while(t)