Grupo T / Mbed OS GRUPOT
Revision:
16:3adab04d42a6
Parent:
15:4604a7ee9c77
Child:
17:55e6270adab5
--- a/main.cpp	Mon May 07 19:54:12 2018 +0000
+++ b/main.cpp	Tue May 08 11:41:56 2018 +0000
@@ -16,16 +16,16 @@
 
 // hardware input signal
 // end-of-stroke sensors
-InterruptIn endX(D9);
-InterruptIn endY(D10);
-InterruptIn endZ(D11);
+InterruptIn endX(A2);
+InterruptIn endY(A3);
+InterruptIn endZ(A4);
 
 // IHM for development
 AnalogIn joyX(A0);
 AnalogIn joyY(A1);
 
-DigitalIn zUp(D12);
-DigitalIn zDwn(D13);
+DigitalIn zUp(D15);
+DigitalIn zDwn(D14);
 
 // variables definition
 int modeStatus = 1;
@@ -47,17 +47,20 @@
 int x_minus = 1;
 int y_plus = 1;
 int y_minus = 0;
-int z_plus = 1;
-int z_minus = 0;
+int z_plus = 0;
+int z_minus = 1;
 
 int x_limit = 0;
-int x_block = 0;
+int x_block_max = 0;
+int x_block_min = 0;
 
 int y_limit = 0;
-int y_block = 0;
+int y_block_max = 0;
+int y_block_min = 0;
 
 int z_limit = 0;
-int z_block = 0;
+int z_block_max = 0;
+int z_block_min = 0;
 
 float ppsMax = 600.0;
 
@@ -103,7 +106,7 @@
 int contador = 0;
 
 int main(){
-    printf("Starting...\r\n");
+    printf("\nStarting...\r\n");
     
     enable = 0;
  
@@ -118,7 +121,7 @@
     
     if(modeStatus){
         //Código de JOG
-        printf("JOG Selected\n");
+        printf("JOG Selected\n\r");
         while(1){        
             valX = joyX;
             valY = joyY;
@@ -147,15 +150,15 @@
             //----------------------------------------------------------------------
             
             if(valY > 0.7){
-                if(y_dir != y_plus){
-                    y_dir = y_plus;   
+                if(y_dir != y_minus){
+                    y_dir = y_minus;   
                 }
                 activeY = 1;  
                 totalY+=1;   
             }
             else if(valY < 0.3){
-                if(y_dir != y_minus){
-                    y_dir = y_minus;    
+                if(y_dir != y_plus){
+                    y_dir = y_plus;    
                 }
                 activeY = 1; 
                 totalY-=1;   
@@ -186,7 +189,7 @@
             
             //----------------------------------------------------------------------
 
-            //move(ppsMax, x_dir, y_dir, z_dir, activeX, activeY, activeZ);  
+            move(ppsMax, x_dir, y_dir, z_dir, activeX, activeY, activeZ);  
             X = distance(totalX, xPitch);
             Y = distance(totalY, yPitch);
             Z = distance(totalZ, zPitch);
@@ -201,7 +204,10 @@
     }
     
     else {
-        
+        while(1){
+            move(ppsMax, x_plus, y_plus, z_plus, 0, 0, 400);
+            move(ppsMax, x_plus, y_plus, z_minus, 0, 0, 400);    
+        }
     }  
 }  
 
@@ -209,34 +215,46 @@
 void endX_press(void){
     printf("X - press\n\r");
     if(dirX == x_plus){
-        x_limit = x_plus;
-        x_block = 1;
+        x_block_max = 1;
     }
     else {
-        x_limit = x_minus;
-        x_block = 1;
+        x_block_min = 1;
     }
 }
 void endX_release(void){
     printf("X - release\n\r");
-    x_block = 0;
+    x_block_min = 0;
+    x_block_max = 0;
 }
+
 void endY_press(void){
-    printf("Y - press\n\r");
-    y_limit = 1;   
+    printf("Y - press\n\r");  
+    if(dirY == y_plus){
+        y_block_max = 1;
+    }
+    else {
+        y_block_min = 1;
+    } 
 }
 void endY_release(void){
     printf("Y - release\n\r");
-    y_limit = 0;   
+    y_block_min = 0;   
+    y_block_max = 0;
 }
 
 void endZ_press(void){
     printf("Z - press\n\r");
-    z_limit = 1;  
+    if(dirZ == z_plus){
+        z_block_max = 1;
+    }
+    else {
+        z_block_min = 1;
+    }
 }
 void endZ_release(void){
     printf("Z - release\n\r");
-    z_limit = 0; 
+    z_block_min = 0;
+    z_block_max = 0;
 }
 
 void move(int pps, int x_dir, int y_dir, int z_dir, int x_step, int y_step, int z_step){
@@ -246,14 +264,27 @@
     dirY = y_dir;
     dirZ = z_dir;
     
-    if((x_dir == x_limit) && x_block){
+    // X
+    if((x_dir == x_plus) && x_block_max){
+        x_step = 0;    
+    }
+    if((x_dir == x_minus) && x_block_min){
         x_step = 0;    
     }
     
-    if((y_dir == y_limit) && y_block){
+    // Y
+    if((y_dir == y_plus) && y_block_max){
+        y_step = 0;    
+    }
+    if((y_dir == y_minus) && y_block_min){
         y_step = 0;    
     }
-    if((z_dir == z_limit) && z_block){
+    
+    // Z
+    if((z_dir == z_plus) && z_block_max){
+        z_step = 0;    
+    }
+    if((z_dir == z_minus) && z_block_min){
         z_step = 0;    
     }