Projeto Mecatrônico - 2020 - G3 / Mbed 2 deprecated Movimentacao

Dependencies:   mbed

Revision:
0:92a99259dafa
Child:
1:2e9e37f35e3f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/movimentacao.cpp	Mon Jun 22 01:01:47 2020 +0000
@@ -0,0 +1,300 @@
+
+int PosicaoRecipiente[3];
+PosicaoRecipiente[0] = 40;
+PosicaoRecipiente[1] = 35;
+PosicaoRecipiente[2] = 10;
+
+void ativa_pipeta() {
+    }
+
+void recebe_comandos(){
+    
+    }
+
+void avaliar_distancia(){ //Função para detectar e movimentar a pipeta até o local da pega
+    int x = 0;
+    int y = 0;
+    int z = 0;
+    
+    int x_2 = 0;
+    int y_2 = 0;
+    int z_2 = 0;
+    
+    while (x == 0){ // Checa se a pipeta está na posição de pega, se n estiver ela se movimenta até lá
+        if (Posicao_inicial[0] < PosicaoFrasco[0]) {
+            Fase_M1_A = 1;
+            wait(tempo);
+            Fase_M1_A = 0;
+            Fase_M1_B = 1;
+            wait(tempo);
+            Fase_M1_B = 0;
+            Fase_M1_C = 1;
+            wait(tempo);
+            Fase_M1_C = 0;
+            Fase_M1_D = 1;
+            wait(tempo);
+            Fase_M1_D = 0;
+            Posicao_inicial[0] = Posicao_inicial[0] + 5;
+            
+            }
+            
+        if (Posicao_inicial[0] > PosicaoFrasco[0]) {
+            Fase_M1_D = 1;
+            wait(tempo);
+            Fase_M1_D = 0;
+            Fase_M1_C = 1;
+            wait(tempo);
+            Fase_M1_C = 0;
+            Fase_M1_B = 1;
+            wait(tempo);
+            Fase_M1_B = 0;
+            Fase_M1_A = 1;
+            wait(tempo);
+            Fase_M1_A = 0;
+            Posicao_inicial[0] = Posicao_inicial[0] - 5;
+            
+            }
+        
+        if (Posicao_inicial[0] == PosicaoFrasco[0]) {
+            x = 1;
+            }
+        }
+        
+    while (y == 0){ // Checa se a pipeta está na posição de pega, se n estiver ela se movimenta até lá
+     if (Posicao_inicial[1] < PosicaoFrasco[1]) {
+         Fase_M2_A = 1;
+         wait(tempo);
+         Fase_M2_A = 0;
+         Fase_M2_B = 1;
+         wait(tempo);
+         Fase_M2_B = 0;
+         Fase_M2_C = 1;
+         wait(tempo);
+         Fase_M2_C = 0;
+         Fase_M2_D = 1;
+         wait(tempo);
+         Fase_M2_D = 0;
+         Posicao_inicial[1] = Posicao_inicial[1] + 5;
+        
+         }
+         
+     if (Posicao_inicial[1] > PosicaoFrasco[1]) {
+         Fase_M2_D = 1;
+         wait(tempo);
+         Fase_M2_D = 0;
+         Fase_M2_C = 1;
+         wait(tempo);
+         Fase_M2_C = 0;
+         Fase_M2_B = 1;
+         wait(tempo);
+         Fase_M2_B = 0;
+         Fase_M2_A = 1;
+         wait(tempo);
+         Fase_M2_A = 0;
+         Posicao_inicial[1] = Posicao_inicial[1] - 5;
+        
+         }
+     
+     if (Posicao_inicial[1] == PosicaoFrasco[1]) {
+         y = 1;
+         }
+      }
+    
+    while (z == 0){ // Checa se a pipeta está na posição de pega, se n estiver ela se movimenta até lá
+     if (Posicao_inicial[2] < PosicaoFrasco[2]) {
+         Fase_M3_A = 1;
+         wait(tempo);
+         Fase_M3_A = 0;
+         Fase_M3_B = 1;
+         wait(tempo);
+         Fase_M3_B = 0;
+         Fase_M3_C = 1;
+         wait(tempo);
+         Fase_M3_C = 0;
+         Fase_M3_D = 1;
+         wait(tempo);
+         Fase_M3_D = 0;
+         Posicao_inicial[2] = Posicao_inicial[2] + 5;
+        
+         }
+         
+     if (Posicao_inicial[2] > PosicaoFrasco[2]) {
+         Fase_M3_D = 1;
+         wait(tempo);
+         Fase_M3_D = 0;
+         Fase_M3_C = 1;
+         wait(tempo);
+         Fase_M3_C = 0;
+         Fase_M3_B = 1;
+         wait(tempo);
+         Fase_M3_B = 0;
+         Fase_M3_A = 1;
+         wait(tempo);
+         Fase_M3_A = 0;
+         Posicao_inicial[2] = Posicao_inicial[2] - 5;
+        
+         }
+    
+     if (Posicao_inicial[2] == PosicaoFrasco[2]) {
+         z = 1;
+         }
+     } 
+    
+    ativa_pipeta();
+    
+    while (Posicao_inicial[2] != 0) { //Depois de sugar o líquido a pipeta é levada para cima para evitar possíveis colisões
+        Fase_M3_D = 1;
+        wait(tempo);
+        Fase_M3_D = 0;
+        Fase_M3_C = 1;
+        wait(tempo);
+        Fase_M3_C = 0;
+        Fase_M3_B = 1;
+        wait(tempo);
+        Fase_M3_B = 0;
+        Fase_M3_A = 1;
+        wait(tempo);
+        Fase_M3_A = 0;
+        Posicao_inicial[2] = Posicao_inicial[2] - 5;
+        }
+    
+    while (x_2 == 0){ // Checa se a pipeta está na posição de solta, se n estiver ela se movimenta até lá
+        if (Posicao_inicial[0] < PosicaoRecipiente[0]) {
+            Fase_M1_A = 1;
+            wait(tempo);
+            Fase_M1_A = 0;
+            Fase_M1_B = 1;
+            wait(tempo);
+            Fase_M1_B = 0;
+            Fase_M1_C = 1;
+            wait(tempo);
+            Fase_M1_C = 0;
+            Fase_M1_D = 1;
+            wait(tempo);
+            Fase_M1_D = 0;
+            Posicao_inicial[0] = Posicao_inicial[0] + 5;
+            
+            }
+            
+        if (Posicao_inicial[0] > PosicaoRecipiente[0]) {
+            Fase_M1_D = 1;
+            wait(tempo);
+            Fase_M1_D = 0;
+            Fase_M1_C = 1;
+            wait(tempo);
+            Fase_M1_C = 0;
+            Fase_M1_B = 1;
+            wait(tempo);
+            Fase_M1_B = 0;
+            Fase_M1_A = 1;
+            wait(tempo);
+            Fase_M1_A = 0;
+            Posicao_inicial[0] = Posicao_inicial[0] - 5;
+            
+            }
+        
+        if (Posicao_inicial[0] == PosicaoRecipiente[0]) {
+            x_2 = 1;
+            }
+        }
+        
+    while (y_2 == 0){ // Checa se a pipeta está na posição de solta, se n estiver ela se movimenta até lá
+     if (Posicao_inicial[1] < PosicaoRecipiente[1]) {
+         Fase_M2_A = 1;
+         wait(tempo);
+         Fase_M2_A = 0;
+         Fase_M2_B = 1;
+         wait(tempo);
+         Fase_M2_B = 0;
+         Fase_M2_C = 1;
+         wait(tempo);
+         Fase_M2_C = 0;
+         Fase_M2_D = 1;
+         wait(tempo);
+         Fase_M2_D = 0;
+         Posicao_inicial[1] = Posicao_inicial[1] + 5;
+        
+         }
+         
+     if (Posicao_inicial[1] > PosicaoRecipiente[1]) {
+         Fase_M2_D = 1;
+         wait(tempo);
+         Fase_M2_D = 0;
+         Fase_M2_C = 1;
+         wait(tempo);
+         Fase_M2_C = 0;
+         Fase_M2_B = 1;
+         wait(tempo);
+         Fase_M2_B = 0;
+         Fase_M2_A = 1;
+         wait(tempo);
+         Fase_M2_A = 0;
+         Posicao_inicial[1] = Posicao_inicial[1] - 5;
+        
+         }
+     
+     if (Posicao_inicial[1] == PosicaoRecipiente[1]) {
+         y_2 = 1;
+         }
+      }
+    
+    while (z_2 == 0){ // Checa se a pipeta está na posição de solta, se n estiver ela se movimenta até lá
+     if (Posicao_inicial[2] < PosicaoRecipiente[2]) {
+         Fase_M3_A = 1;
+         wait(tempo);
+         Fase_M3_A = 0;
+         Fase_M3_B = 1;
+         wait(tempo);
+         Fase_M3_B = 0;
+         Fase_M3_C = 1;
+         wait(tempo);
+         Fase_M3_C = 0;
+         Fase_M3_D = 1;
+         wait(tempo);
+         Fase_M3_D = 0;
+         Posicao_inicial[2] = Posicao_inicial[2] + 5;
+        
+         }
+         
+     if (Posicao_inicial[2] > PosicaoRecipiente[2]) {
+         Fase_M3_D = 1;
+         wait(tempo);
+         Fase_M3_D = 0;
+         Fase_M3_C = 1;
+         wait(tempo);
+         Fase_M3_C = 0;
+         Fase_M3_B = 1;
+         wait(tempo);
+         Fase_M3_B = 0;
+         Fase_M3_A = 1;
+         wait(tempo);
+         Fase_M3_A = 0;
+         Posicao_inicial[2] = Posicao_inicial[2] - 5;
+        
+         }
+    
+     if (Posicao_inicial[2] == PosicaoRecipiente[2]) {
+         z_2 = 1;
+         }
+     } 
+    
+}
+
+void repetir(){
+    
+    }
+
+int main() {
+    zeramento();
+    Joystick();
+    
+    int verdade = 1;
+    
+    while (verdade == 1) {
+        repetir();
+        }
+    
+    }
+        
+    
+    
\ No newline at end of file