Grupo T / Mbed OS GRUPOT
Revision:
12:801e58a7137c
Parent:
11:0e22a6fc7f87
Child:
13:0f385bfe3e0d
diff -r 0e22a6fc7f87 -r 801e58a7137c main.cpp
--- a/main.cpp	Fri May 04 17:48:15 2018 +0000
+++ b/main.cpp	Fri May 04 17:55:03 2018 +0000
@@ -50,6 +50,9 @@
 int z_plus = 1;
 int z_minus = 0;
 
+int x_limit_min = 0;
+int x_limit_max = 0;
+
 int y_limit_min = 0;
 int y_limit_max = 0;
 
@@ -87,6 +90,7 @@
 void endY2Int_press(void);
 void endY2Int_release(void);
 
+void zeroX(int pps);
 void zeroY(int pps);
 
 // MAIN PROGRAM ----------------------------------------------------------------
@@ -95,10 +99,14 @@
 
 int main(){
     printf("Starting...\r\n");
+ 
+    endX1.fall(&endX1Int_press);
+    endX1.rise(&endX1Int_release);
+    endX2.fall(&endX2Int_press);
+    endX2.rise(&endX2Int_release);
     
     endY1.fall(&endY1Int_press);
     endY1.rise(&endY1Int_release);
-    
     endY2.fall(&endY2Int_press);
     endY2.rise(&endY2Int_release);
     
@@ -198,33 +206,38 @@
 }  
 
 // FUNCTIONS ----------------------------------------------------------------
-
-void endY1Int_press(void){
-    //if(debounce.read_ms() > 50)
-    printf("Y1 - press\n\r");
-    y_limit_min = 1;
-    //debounce.reset();    
+void endX1Int_press(void){
+    printf("X1 - press\n\r");
+    x_limit_min = 1;  
+}
+void endX1Int_release(void){
+    printf("X1 - release\n\r");
+    x_limit_min = 0; 
+}
+void endX2Int_press(void){
+    printf("X2 - press\n\r");
+    x_limit_max = 1;   
+}
+void endX2Int_release(void){
+    printf("X2 - release\n\r");
+    x_limit_max = 0;   
 }
 
+void endY1Int_press(void){
+    printf("Y1 - press\n\r");
+    y_limit_min = 1;  
+}
 void endY1Int_release(void){
-    //if(debounce.read_ms() > 50)
     printf("Y1 - release\n\r");
-    y_limit_min = 0;
-    //debounce.reset();    
+    y_limit_min = 0; 
 }
-
 void endY2Int_press(void){
-    //if(debounce.read_ms() > 50)
     printf("Y2 - press\n\r");
-    y_limit_max = 1;
-    //debounce.reset();    
+    y_limit_max = 1;   
 }
-
 void endY2Int_release(void){
-    //if(debounce.read_ms() > 50)
     printf("Y2 - release\n\r");
-    y_limit_max = 0;
-    //debounce.reset();    
+    y_limit_max = 0;   
 }
 
 void move(int pps, int x_dir, int y_dir, int z_dir, int x_step, int y_step, int z_step){
@@ -234,6 +247,13 @@
     dirY = y_dir;
     dirZ = z_dir;
     
+    if((x_dir == x_minus) && x_limit_min){
+        x_step = 0;    
+    }
+    if((x_dir == x_plus) && x_limit_max){
+        x_step = 0;    
+    }
+    
     if((y_dir == y_minus) && y_limit_min){
         y_step = 0;    
     }
@@ -283,6 +303,24 @@
     }
 }
 
+void zeroX(int pps){
+    float time = 1.0/pps/2.0;
+    
+    while(!x_limit_min){
+        if(dirX != x_minus){
+            dirX = x_minus;    
+        }
+        stepX = 1;
+        wait(time);
+        stepX = 0;
+        wait(time);  
+    }
+    
+    printf("X zero\n\r");
+    
+    totalX = 0.0;
+}
+
 void zeroY(int pps){
     float time = 1.0/pps/2.0;