Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope MODSERIAL QEI TextLCD mbed
Fork of TotalControlEmg2 by
Revision 17:cfe44346645c, committed 2015-10-09
- Comitter:
- Bartvaart
- Date:
- Fri Oct 09 11:27:58 2015 +0000
- Parent:
- 16:8f175d2a472f
- Child:
- 18:eec0880fcded
- Commit message:
- Bepaald een max en minimum (voor kalibratie) en gaat dan gewone programma runnen
Changed in this revision
--- a/Filterdesigns.cpp Fri Oct 09 09:57:09 2015 +0000
+++ b/Filterdesigns.cpp Fri Oct 09 11:27:58 2015 +0000
@@ -40,8 +40,9 @@
double gem = 0.4557; // gemiddelde waarde emgsignaal
+double y=0;
-void Filterdesigns(double u, double &y)
+double Filterdesigns(double u)
{
//u = input waarde
//y = output waarde
@@ -65,4 +66,6 @@
double yLP = Filter(y1, v1_LP, v2_LP, a1_LP, a2_LP, b0_LP, b1_LP, b2_LP, gain_LP);
y = 10 * yLP;
+
+ return y;
}
\ No newline at end of file
--- a/Filterdesigns.h Fri Oct 09 09:57:09 2015 +0000 +++ b/Filterdesigns.h Fri Oct 09 11:27:58 2015 +0000 @@ -1,3 +1,3 @@ #include "mbed.h" -void Filterdesigns(double u, double &y); \ No newline at end of file +double Filterdesigns(double u); \ No newline at end of file
--- a/Kalibratie.cpp Fri Oct 09 09:57:09 2015 +0000
+++ b/Kalibratie.cpp Fri Oct 09 11:27:58 2015 +0000
@@ -1,4 +1,61 @@
#include "Kalibratie.h"
+#include "Filterdesigns.h"
+
+Timer Timermax;
+Timer Timermin;
+AnalogIn emg2(A0); //Analog input van emg kabels
+
+DigitalOut LedGreen(LED2);
+DigitalOut LedRed(LED1);
+
+void Init()
+{
+ LedGreen = 1;
+ LedRed = 1;
+}
+
+double KalibratieMax(bool &readymax) //Kalibratie van de maximum waarde
+{
+ Timermax.start(); //Start de timer
+
+ LedGreen.write(0); //Led aan
+ double ymax = 0;
-void Kalibratie(){
-
\ No newline at end of file
+ while(Timermax <= 5) { //Als timer onder de 5 seconden is dit uitvoeren
+ double u = emg2.read();
+ double y = Filterdesigns(u);
+ if (y > ymax) { //Als de gemeten waarde groter is dan de opgeslagen waarde wordt dit de nieuwe opgeslagen waarde
+ ymax = y;
+ }
+ else {
+ }
+ }
+ Timermax.stop();
+ LedGreen.write(1); //Led aan
+ readymax = 1; // Zodat systeem weet wanneer kalibratie voltooid is
+ return ymax;
+}
+
+double KalibratieMin(bool &readymin) //Kalibratie van de minimum waarde
+{
+ Timermin.start();
+
+ LedRed.write(0);
+ double ymin = 10;
+
+ while(Timermin <= 5) {
+ double u = emg2.read();
+ double y = Filterdesigns(u);
+
+ if (y < ymin) {
+ ymin = y;
+ }
+ else {
+ }
+ }
+
+ Timermin.stop();
+ LedRed.write(1);
+ readymin = 1;
+ return ymin;
+}
\ No newline at end of file
--- a/Kalibratie.h Fri Oct 09 09:57:09 2015 +0000 +++ b/Kalibratie.h Fri Oct 09 11:27:58 2015 +0000 @@ -1,3 +1,7 @@ #include "mbed.h" -void Kalibratie(); +double KalibratieMax(bool &readymax); + +double KalibratieMin(bool &readymin); + +void Init(); \ No newline at end of file
--- a/main.cpp Fri Oct 09 09:57:09 2015 +0000
+++ b/main.cpp Fri Oct 09 11:27:58 2015 +0000
@@ -1,24 +1,26 @@
#include "mbed.h"
#include "HIDScope.h"
#include "Filterdesigns.h"
-#inlcude "Kalibratie.h"
-//#include "MODSERIAL.h" //bugfix
+#include "Kalibratie.h"
+#include "MODSERIAL.h" //bugfix
AnalogIn emg(A0); //Analog input van emg kabels
HIDScope scope(2); //2 scopes
Ticker EMGticker;
-//MODSERIAL pc(USBTX, USBRX); //bugfix
+MODSERIAL pc(USBTX, USBRX); //bugfix
+DigitalOut LedBlue(LED3);
//Sample frequentie
double Fs = 500; //Hz
double t = 1/ Fs; // voor EMGticker
-double y = 0;
+bool readymax = 0;
+bool readymin = 0;
void EMGfilter(){
//uitlezen emg signaal
double u = emg.read();
- Filterdesigns(u,y);
+ double y = Filterdesigns(u);
// pc.printf("%f \n",y); //bugfix
// Plotten in HIDscope
scope.set(0,u); //ongefilterde waarde naar scope 1
@@ -28,7 +30,17 @@
int main(){
- EMGticker.attach(&EMGfilter, t); //500Hz
- while(1){}
+ LedBlue = 1;
+ Init();
+ double ymax = KalibratieMax(readymax);
+ double ymin = KalibratieMin(readymin);
+
+ pc.printf("ymax = %f en ymin = %f \n",ymax, ymin); //bugfix
+
+ while(readymax == 1 && readymin == 1){
+ LedBlue = 0;
+ EMGticker.attach(&EMGfilter, t); //500H
+ while(1){}
+ }
}
\ No newline at end of file
