Grupo T / Mbed OS GRUPOT
Revision:
11:0e22a6fc7f87
Parent:
10:cd868ca9997c
Child:
12:801e58a7137c
--- a/main.cpp	Fri May 04 16:01:07 2018 +0000
+++ b/main.cpp	Fri May 04 17:48:15 2018 +0000
@@ -77,12 +77,18 @@
 void move(int pps, int x_dir, int y_dir, int z_dir, int x_step, int y_step, int z_step);
 float distance(int steps, float pitch);
 
+void endX1Int_press(void);
+void endX1Int_release(void);
+void endX2Int_press(void);
+void endX2Int_release(void);
+
 void endY1Int_press(void);
 void endY1Int_release(void);
-
 void endY2Int_press(void);
 void endY2Int_release(void);
 
+void zeroY(int pps);
+
 // MAIN PROGRAM ----------------------------------------------------------------
 
 int contador = 0;
@@ -182,31 +188,16 @@
     }
     
     else {
-        printf("X\n\r");
-        move(ppsMax, x_plus, y_plus, z_plus, 1600, 0, 0);
-        move(ppsMax, x_minus, y_plus, z_plus, 1600, 0, 0);
-        
-        wait(2);
+        zeroY(ppsMax);
         
-        printf("Y\n\r");
-        move(ppsMax, x_plus, y_plus, z_plus, 0, 1600, 0);
-        move(ppsMax, x_minus, y_minus, z_plus, 0, 1600, 0);
-        
-        wait(2);
+        X = distance(totalX, xPitch);
+        Y = distance(totalY, yPitch);
         
-        printf("Z\n\r");
-        move(ppsMax, x_plus, y_plus, z_plus, 0, 0, 600);
-        move(ppsMax, x_minus, y_minus, z_minus, 0, 0, 600);
-        
-        printf("Finished");
+        printf("X: %.2f     Y: %.2f\r\n", X, Y);
     }  
 }  
 
 // FUNCTIONS ----------------------------------------------------------------
-void setupPins(){
-    //endX1.mode(PullUp);
-    //endX2.mode(PullUp);
-}
 
 void endY1Int_press(void){
     //if(debounce.read_ms() > 50)
@@ -243,6 +234,13 @@
     dirY = y_dir;
     dirZ = z_dir;
     
+    if((y_dir == y_minus) && y_limit_min){
+        y_step = 0;    
+    }
+    if((y_dir == y_plus) && y_limit_max){
+        y_step = 0;    
+    }
+    
     int max_val;
     
     // maior número de passos -------
@@ -269,7 +267,8 @@
         if(i >= y_step){
             stepY = 0;
         }
-        else { stepY = 1; }
+        else {
+            stepY = 1;}
         
         if(i >= z_step){
             stepZ = 0;
@@ -284,6 +283,24 @@
     }
 }
 
+void zeroY(int pps){
+    float time = 1.0/pps/2.0;
+    
+    while(!y_limit_min){
+        if(dirY != y_minus){
+            dirY = y_minus;    
+        }
+        stepY = 1;
+        wait(time);
+        stepY = 0;
+        wait(time);  
+    }
+    
+    printf("Y zero\n\r");
+    
+    totalY = 0.0;
+}
+
 float distance(int steps, float pitch){
     float delta_S = (((float)steps)/steps_by_rotation)*pitch;
     return delta_S;