De hele robot in 1 keer bam
Dependencies: mbed QEI Servo HIDScope biquadFilter MODSERIAL FastPWM
Diff: main.cpp
- Revision:
- 12:70f0710400c2
- Parent:
- 11:042170a9b93a
- Child:
- 13:2724d2e747f1
- Child:
- 15:421d3d9c563b
--- a/main.cpp Mon Oct 21 14:07:30 2019 +0000 +++ b/main.cpp Mon Oct 21 14:36:24 2019 +0000 @@ -27,13 +27,16 @@ // Buttons InterruptIn button1(D11); InterruptIn button2(D10); +InterruptIn button3(SW3); //variablen voor EMG double emg1; double emg2; double emg3; -double emg1_mean; -double emg1_stdev; +double emg1_MVC; +double emg1_MVC_stdev; +double emg1_rest; +double emg1_rest_stdev; vector<double> emg1_cal; @@ -41,6 +44,7 @@ // Initialize tickers Ticker tickSample; Timeout timeoutCalibrationMVC; +Timeout timeoutCalibrationRest; Ticker tickSampleCalibration; // Sample rate @@ -163,8 +167,8 @@ { tickSampleCalibration.detach(); - emg1_mean = getMean(emg1_cal); - emg1_stdev = getStdev(emg1_cal, emg1_mean); + emg1_MVC = getMean(emg1_cal); + emg1_MVC_stdev = getStdev(emg1_cal, emg1_MVC); emg1_cal.clear(); @@ -178,7 +182,33 @@ led_b = 0; } +void calibrationRestFinished() +{ + tickSampleCalibration.detach(); + + emg1_rest = getMean(emg1_cal); + emg1_rest_stdev = getStdev(emg1_cal, emg1_rest); + + emg1_cal.clear(); + led_b = 1; +} + +void calibrationRest() +{ + timeoutCalibrationRest.attach( &calibrationRestFinished, Tcal); + tickSampleCalibration.attach( &sampleCalibration, Ts ); + led_b = 0; +} + +void makeScale() +{ + double margin_percentage = 10; + double factor1 = 1 / emg1_MVC; + double emg1_th = emg1_rest * factor1 + margin_percentage/100; + + pc.printf("Factor: %f TH: %f\r\n", factor1, emg1_th); +} void main() { @@ -203,12 +233,14 @@ } button1.fall( &calibrationMVC ); + button2.fall( &calibrationRest ); + button3.fall( &makeScale ); while(true) { // Show that system is running // led_g = !led_g; - pc.printf("EMG Mean: %f stdev: %f\r\n", emg1_mean, emg1_stdev); + pc.printf("EMG MVC: %f stdev: %f\r\nEMG Rest: %f stdev: %f\r\n", emg1_MVC, emg1_MVC_stdev, emg1_rest, emg1_rest_stdev); wait(0.5); } } \ No newline at end of file