Eindversie. LU: 07-11-13.

Dependencies:   MODSERIAL mbed Encoder

Files at this revision

API Documentation at this revision

Comitter:
Socrates
Date:
Thu Oct 24 12:48:06 2013 +0000
Parent:
12:100cbba6cd96
Child:
14:5746b1697ff4
Child:
15:ab236d7c32d2
Commit message:
Poging tot triceps-omdraaing;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Oct 23 15:04:34 2013 +0000
+++ b/main.cpp	Thu Oct 24 12:48:06 2013 +0000
@@ -7,7 +7,6 @@
 AnalogIn emgbl(PTB0);
 PwmOut pwm_x(PTA5);
 PwmOut pwm_y(PTA12);
-//AnalogOut pwm_x(PTE30);
 MODSERIAL pc(USBTX,USBRX);
 DigitalOut motordir1(PTD3);
 DigitalOut motordir2(PTD1);
@@ -19,13 +18,24 @@
     looptimerflag = true;
 }
 
+double ztr,zbr,xdir;
+
+void tricheck(void)
+{
+if (ztr>zbr) {
+            xdir = !xdir;
+        }
+}
+
 int main()
 {
-pwm_x.period(1.0/1000.0);
-pwm_y.period(1.0/1000.0);
+pwm_x.period(1.0/22000.0);
+pwm_y.period(1.0/22000.0);
     Ticker looptimer;
+    Ticker looptimer2;
     const double ts=0.001;
     looptimer.attach(setlooptimerflag,ts);
+    looptimer2.attach(tricheck,1);
     double numh1,numh2,denh2,numl1,numl2,numl3,denl2,denl3;
     double xtr,ytr,y1tr,x1tr,ztr,z1tr,z2tr,yabstr,yabs1tr,yabs2tr,ktr;
     double xbr,ybr,y1br,x1br,zbr,z1br,z2br,yabsbr,yabs1br,yabs2br,kbr;
@@ -56,7 +66,8 @@
     pc.baud(115200);
 
     while(1) {
-        while(looptimerflag != true);
+        while(looptimerflag != true);{
+        }
         looptimerflag = false;
 
 ktr=emgtr.read();
@@ -87,21 +98,18 @@
         zbl=yabsbl*numl1+yabs1bl*numl2+yabs2bl*numl3-z1bl*denl2-z2bl*denl3;
         x1bl=xbl;        y1bl=ybl;        z2bl=z1bl;        z1bl=zbl;        yabs2bl=yabs1bl;        yabs1bl=yabsbl;
         
+        zx=zbr*3.5;
         if (ztr>zbr) {
-            zx=ztr*3.5;
-            xdir=0;
-        } else {
-            zx=zbr*2.5;
-            xdir=1;
+            xdir = !xdir;
         }
 
-        if (ztl>zbl) {
-            zy=ztl*5.0;
-            ydir=0;
-        } else {
-            zy=zbl*5.0;
-            ydir=1;
-        }
+        //if (ztl>zbl) {
+        //    zy=ztl*5.0;
+        //    ydir=0;
+        //} else {
+        //    zy=zbl*5.0;
+        //    ydir=1;
+        //}
         
         if (zx>1.0) {
             zx=0.99999;
@@ -121,6 +129,6 @@
         motordir2.write(ydir);
         pwm_x.write(abs(zx));
         pwm_y.write(abs(zy));
-        pc.printf("%f\n\r",zx);
+        pc.printf("EMG: %f, Richting: %d \n\r",zx, xdir);
     }
 }
\ No newline at end of file