Eindversie. LU: 07-11-13.

Dependencies:   MODSERIAL mbed Encoder

Files at this revision

API Documentation at this revision

Comitter:
Socrates
Date:
Sat Nov 02 20:13:06 2013 +0000
Parent:
29:8600b02ab223
Child:
31:5c90e931dbfe
Commit message:
Zaterdag nog wat comments gemaakt.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Nov 01 15:18:14 2013 +0000
+++ b/main.cpp	Sat Nov 02 20:13:06 2013 +0000
@@ -37,12 +37,13 @@
     dirflagy=true;
 }
 
+volatile bool startflag=true;
+volatile bool calA=true, calB=true;
+volatile bool frictionflag=true;
+
 volatile bool calflag=true;
-volatile bool frictionflag=true;
 volatile bool meetflag=true;
-volatile bool calA, calB;
 volatile bool patroonflag=false;
-volatile bool startflag=true;
 
 int main()
 {
@@ -139,22 +140,19 @@
     //denl3=0.982385450614126;
 
 //Opzetje voor calibratie
-    wait(3);
-    calA=true;
-    calB=true;
+    wait(4);
 
-if(startflag==true);
-{
-    motor1.setPosition(0);
-    motor2.setPosition(1200);
-    startflag=false;
+    if(startflag==true);
+    {
+        motor1.setPosition(0);
+        motor2.setPosition(1200);
+        startflag=false;
     }
-    
+
     while(calflag==true) {
-    
         while(looptimerflag != true);
         looptimerflag = false;
-        //515,3536 voor rechtsonder.
+        //515 - 3536 voor rechtsonder.
         refA=515;
         refB=3536;
         while(calB==true) {
@@ -167,27 +165,27 @@
             Bi1=Bi;
             ctrlB=(Bi+Bp+Bd);
             for_B=(ctrlB)/1000.0;
-            if(ctrlB<0) {
+            if(ctrlB<0.0) {
                 Bdir=0;
             } else {
                 Bdir=1;
             }
-            keep_in_range(&for_B, -1,1);
+            keep_in_range(&for_B, -1.0,1.0);
             if (frictionflag==true) {
                 for_B=abs(for_B)+friction;
-                keep_in_range(&for_B, 0,0.1);
+                keep_in_range(&for_B, 0.0,0.1);
             }
             pwm_B.write(abs(for_B));
             motordirB.write(Bdir);
             //pc.printf("B %f %i \n\r",for_B,errB);
             if(errB<10) {
                 calB=false;
-                pwm_B.write(0);
+                pwm_B.write(0.0);
             }
         }
 
         while(calA==true) {
-            ticka=-motor1.getPosition();
+            ticka=-motor1.getPosition();  //NOTE: deze moet volgens mij gewoon weer positief zijn.
             errA=refA-ticka;
             Ap=errA*kpc;
             Ad=(errA-Ad1)*kdc/ts;
@@ -196,7 +194,7 @@
             Ai1=Ai;
             ctrlA=(Ai+Ap+Ad);
             for_A=(ctrlA)/1000.0;
-            if(ctrlA<0) {
+            if(ctrlA<0) { //NOTE: als ticka weer +get is, kan deze weer 0 else 1 zijn.
                 Adir=1;
             } else {
                 Adir=0;
@@ -300,13 +298,13 @@
         if (ztr>0.15 && dirflagx == true) {
             dirflagx = false;
             xdir ^= 1;
-            zx=0;
+            //zx=0;  //NOTE: deze weghalen kan schelen?
             dirtimeout.attach(tricheck,1.0);
         }
         if (ztl>0.15 && dirflagy == true) {
             dirflagy = false;
             ydir ^= 1;
-            zy=0;
+            //zy=0;
             dirtimeout.attach(tricheck,1.0);
         }
 
@@ -314,21 +312,21 @@
         if (ydir==0) {
             zy=-1.0*zy;
         }
-        if (xdir==1) {
+        if (xdir==1) { //NOTE: moet dit geen 0 zijn?
             zx=-1.0*zx;
         }
 
-        ticka=-1*motor1.getPosition();
+        ticka=-1*motor1.getPosition(); //NOTE:  -1 weghalen?
         tickb=motor2.getPosition();
 
         //Begrenzing.
-        vxuit=zx*4.0*pow(10.0,-1.0); // 4cm/s
+        vxuit=zx*4.0*pow(10.0,-1.0); // 4cm/s //NOTE: deze shizzle kan er misschien uit. In ieder geval de vier. En anders moet het /1000 zijn.
         vyuit=zy*4.0*pow(10.0,-2.0); // 4cm/s
         xuit += ts*vxuit;
         yuit += ts*vyuit;
 
-keep_in_range(&xuit,-4.5,2.75); //Iets met de grenzen. En de richtingpins. 
-keep_in_range(&yuit,-4.5,2.8);
+        keep_in_range(&xuit,-4.5,2.75); //NOTE: Iets met de grenzen. En de richtingpins.
+        keep_in_range(&yuit,-4.5,2.8); //NOTE: als bovenstaande weer klopt moeten de grenzen voor x zijn: .125 en 0.422. Voor y is dat 0.125 en 0.335.
 
         refA=4123.0*atan2(yuit,xuit)/(2.0*PI);
         refB=4123.0*sqrt(xuit*xuit+yuit*yuit)/(2.0*PI*rt);
@@ -347,7 +345,7 @@
         Ad1=Ad;
         Ai1=Ai;
         ctrlA=(Ai+Ap+Ad);
-        for_A=(ctrlA)/700.0;
+        for_A=(ctrlA)/700.0; //NOTE: maak eens een plot van ctrlA en ctrlB. Kan leerzaam zijn voor deze gains.
 
         Bp=errB*kp;
         Bd=(errB-Bd1)*kd/ts;
@@ -360,7 +358,7 @@
         for_B=(ctrlB)/7000.0;
         //x en y uit emg in meters. IK naar radialen. dan radialen naar ticks.
 
-        if(ctrlA<0) {
+        if(ctrlA<0) { //NOTE: zeker gezien de vorige omdraaiingen moet deze volgens mij weer 0 else 1 zijn.
             Adir=1;
         } else {
             Adir=0;
@@ -378,7 +376,7 @@
             for_A=abs(for_A)+friction;
             for_B=abs(for_B)+friction;
 
-            keep_in_range(&for_A, 0,1.0);
+            keep_in_range(&for_A, 0,1.0); //NOTE: misschien valt hier nog wat te begrenzen, maar dan wel op ondergrens friction.
             keep_in_range(&for_B, 0,1.0);
         }
         motordirA.write(Adir);