testando

Dependencies:   mbed TextLCD2

Revision:
63:32ba7c4becfc
Parent:
61:be02d7d4e208
Child:
65:5a759e3014dd
Child:
66:ebc2a21cd514
--- a/main_PM.cpp	Mon Jun 01 18:29:19 2020 +0000
+++ b/main_PM.cpp	Mon Jun 01 20:03:17 2020 +0000
@@ -26,7 +26,7 @@
 DigitalIn fdc_z(PC_12);
 
 //Iterrupcao botao de emergência
-InterruptIn interrupcao(PC_14);
+InterruptIn interrupcao(PB_11);
 
 //pinos do rele, saida digital para acionar o rele se necessario, dada uma entrada no pino da emergencia 
 DigitalOut rele1(PC_5);
@@ -82,10 +82,10 @@
         return('k');}
 
 //funcao de movimentacao dos motores
-void mov_x_menos(){for(int i = 0; i < 4; i++){eixox = antihor[i];wait(t_motor);coord_x -= (5.625*5/32)/360;est_x = 0;}}
+void mov_x_menos(){for(int i = 0; i < 4; i++){eixox = antihor[i];wait(t_motor);coord_x -= (5.625*5/32)/360;}}
 void mov_y_menos(){for(int i = 0; i < 4; i++){eixoy = antihor[i];wait(t_motor);coord_y -= (5.625*5/32)/360;est_y = 0;}}
 void mov_z_menos(){for(int i = 0; i < 4; i++){eixoz = antihor[i];wait(t_motor);coord_z -= (5.625*5/32)/360;est_z = 0;}}
-void mov_x_mais() {for(int i = 0; i < 4; i++){eixox =     hor[i];wait(t_motor);coord_x += (5.625*5/32)/360;est_x = 0;}}
+void mov_x_mais() {for(int i = 0; i < 4; i++){eixox =     hor[i];wait(t_motor);coord_x += (5.625*5/32)/360;}}
 void mov_y_mais() {for(int i = 0; i < 4; i++){eixoy =     hor[i];wait(t_motor);coord_y += (5.625*5/32)/360;est_y = 0;}}
 void mov_z_mais() {for(int i = 0; i < 4; i++){eixoz =     hor[i];wait(t_motor);coord_z += (5.625*5/32)/360;est_z = 0;}}
 
@@ -139,6 +139,7 @@
 //main
 
 int main() {
+        
         interrupcao.fall(&emergencia);    
         int volume;
         int volume_solta;
@@ -173,14 +174,14 @@
             status_tela = "inicio";
             funcao_inicio();}
 
-        if (x_mais == 0 && est_x == 1){for(int i = 0; i < 4; i++){eixox = parado[i];wait(t_motor);coord_x += 0;lcd.cls();lcd.printf("Limite de x atingido");}}
-        if (y_mais == 0 && est_y == 1){for(int i = 0; i < 4; i++){eixoy = parado[i];wait(t_motor);coord_y += 0;lcd.cls();lcd.printf("Limite de y atingido");}}
-        if (z_mais == 0 && est_z == 1){for(int i = 0; i < 4; i++){eixoz = parado[i];wait(t_motor);coord_z += 0;lcd.cls();lcd.printf("Limite de z atingido");}}     
+//      if (x_mais == 0 && est_x == 1){for(int i = 0; i < 4; i++){eixox = parado[i];wait(t_motor);coord_x += 0;lcd.cls();lcd.printf("Limite de x atingido");}}
+//      if (y_mais == 0 && est_y == 1){for(int i = 0; i < 4; i++){eixoy = parado[i];wait(t_motor);coord_y += 0;lcd.cls();lcd.printf("Limite de y atingido");}}
+//      if (z_mais == 0 && est_z == 1){for(int i = 0; i < 4; i++){eixoz = parado[i];wait(t_motor);coord_z += 0;lcd.cls();lcd.printf("Limite de z atingido");}}     
                  
-//        while(x_menos == 0){mov_x_menos();
-//            lcd.cls();      lcd.printf("X: %4.1f", coord_x);
-//            lcd.locate(0,1);lcd.printf("Y: %4.1f", coord_y);
-//            lcd.locate(0,2);lcd.printf("Z: %4.1f", coord_z);}
+       while(x_menos == 0){mov_x_menos();
+           lcd.cls();      lcd.printf("X: %4.1f", coord_x);
+           lcd.locate(0,1);lcd.printf("Y: %4.1f", coord_y);
+            lcd.locate(0,2);lcd.printf("Z: %4.1f", coord_z);}
             
         while(y_menos == 0){mov_y_menos();
             lcd.cls();      lcd.printf("X: %4.1f", coord_x);
@@ -192,10 +193,10 @@
             lcd.locate(0,1);lcd.printf("Y: %4.1f", coord_y);
             lcd.locate(0,2);lcd.printf("Z: %4.1f", coord_z);}
 
-//        while(x_mais == 0){mov_x_mais();
-//            lcd.cls();      lcd.printf("X: %4.1f", coord_x);
-//            lcd.locate(0,1);lcd.printf("Y: %4.1f", coord_y);
-//            lcd.locate(0,2);lcd.printf("Z: %4.1f", coord_z);}
+        while(x_mais == 0){mov_x_mais();
+            lcd.cls();      lcd.printf("X: %4.1f", coord_x);
+            lcd.locate(0,1);lcd.printf("Y: %4.1f", coord_y);
+            lcd.locate(0,2);lcd.printf("Z: %4.1f", coord_z);}
             
         while(y_mais == 0){mov_y_mais();
             lcd.cls();      lcd.printf("X: %4.1f", coord_x);
@@ -387,7 +388,22 @@
         }
         else if(tecla == '3' && status_tela == "novo"){
             funcao_pega_pos_x();
-            pos_x_pega = 12.5;
+            pos_x_pega = coord_x;
+            continuar = 1;
+            while(continuar){
+                 tecla = pega_tecla();
+                 if(x_menos == 0){mov_x_menos();
+                    lcd.cls();      
+                    lcd.printf("X: %4.1f", coord_x);}
+                 else if(x_mais == 0){mov_x_mais();
+                    lcd.cls();
+                    lcd.printf("X: %4.1f", coord_x);}
+                if(tecla=='A'){
+                    continuar = 0;
+                    lcd.printf("Posicao de x salva!");
+                    printf("Posicao X: %4.1f", coord_x);
+                }
+            }
             status_tela = "pos_x";}
         else if(tecla == 'B' && status_tela == "novo"){
             funcao_inicio();
@@ -402,8 +418,7 @@
             funcao_inicio();
             status_tela = "inicio";}
             
-        tecla = 'F';
-        wait(1);
+        wait(0.5);
         tecla = pega_tecla();    
         if(tecla == '1' && status_tela == "forma"){
             funcao_pega_forma_quad();
@@ -413,11 +428,11 @@
             status_tela ="forma_quad";
             continuar = 1;
             comprimento_quad = 0;
+            lcd.locate(0,2);
             while(continuar){
                 printf("\n%c",pega_tecla()); 
                 tecla = pega_tecla();
                 wait(1);
-                lcd.locate(0,2);
                 if(tecla!= 'A' && tecla!='B' && tecla!= 'k'){
                     comprimento_quad = multiplicador*comprimento_quad + ((int)tecla - 48);
                     lcd.printf("%c",tecla);
@@ -441,10 +456,10 @@
             continuar = 1;
             diametro = 0;
             status_tela = "forma_red";
+            lcd.locate(0,2);
             while(continuar){
                 tecla = pega_tecla();
                 wait(1);
-                lcd.locate(0,2);
                 if(tecla!= 'A' && tecla!='B' && tecla!= 'k'){
                     diametro = multiplicador*diametro + ((int)tecla - 48);
                     lcd.printf("%c",tecla);
@@ -469,7 +484,7 @@
         tecla = pega_tecla();
         if(tecla == 'A' && status_tela == "forma_quad"){
             funcao_pega1();
-            medida_lado_pega = 10;
+            medida_lado_pega = comprimento_quad;
             if(pos_y_pega !=0){
             lcd.locate(18,1);lcd.printf("OK");   
             }
@@ -486,7 +501,7 @@
             funcao_pega_forma();
             status_tela = "forma";}
         else if(tecla == 'A' && status_tela == "forma_red"){
-            medida_lado_pega = 10;
+            medida_lado_pega = diametro;
             funcao_pega1();
             if(pos_y_pega !=0){
             lcd.locate(18,1);lcd.printf("OK");   
@@ -524,12 +539,17 @@
         else if(tecla == 'A' && status_tela == "pos_x"){
             funcao_pega_pos_y();  //colocar programacao que contem o posicionamento do eixo y
             pos_y_pega = 12.5;
-            status_tela = "pos_y";}
+            status_tela = "pos_y";
+            }
         else if(tecla == 'B' && status_tela == "pos_x"){
-            funcao_pega_forma();
-            status_tela = "forma";}
+            funcao_pega1();
+            wait(1);
+            funcao_pega2();
+            status_tela = "novo";}
             
-        tecla = pega_tecla();    
+        tecla = pega_tecla();
+        wait(0.5);
+        //passando direto
         if(tecla == 'A' && status_tela == "pos_y"){
             funcao_pega1();
             if(pos_y_pega !=0){
@@ -623,10 +643,11 @@
             status_tela="solta_pos_x";
             continuar = 1;
             while(continuar){
-                 while(x_menos == 0){mov_x_menos();
+                    tecla = pega_tecla();
+                 if(x_menos == 0){mov_x_menos();
                     lcd.cls();      
                     lcd.printf("X: %4.1f", coord_x);}
-                 while(x_mais == 0){mov_x_mais();
+                 else if(x_mais == 0){mov_x_mais();
                     lcd.cls();
                     lcd.printf("X: %4.1f", coord_x);}
                 if(tecla=='A'){