Projeto_Mecatronico_Team / Mbed 2 deprecated Projeto_Mecatronico

Dependencies:   mbed filesystem TextLCD

Fork of Projeto_Mecatronico by Fernando Sakabe

Revision:
27:cb310c1d2353
Parent:
26:6be302ad0278
Child:
28:84a60377564e
--- a/main.cpp	Wed May 25 11:33:16 2022 +0000
+++ b/main.cpp	Mon May 30 11:26:46 2022 +0000
@@ -5,54 +5,54 @@
 #include <iostream>
 #include "posicao.h"
 #include "SD.h"
-
-InterruptIn velocidade(PB_15);
+bool velo = 1;
+InterruptIn velocidade(PB_11); //PA_12
+InterruptIn emergencia (PC_13);
 void mudar_velocidade()
 {
-    wait(1);
-    if(tempo==0.002) {
+    velo = !velo;
+    if(velo==0) {
         tempo=0.006;
-        printf("mudo para 06");
-    } else if (tempo == 0.006) {
+    } else {
         tempo=0.002;
-        printf("mudo para 02");
     }
 }
 
 int main()
 {
-//    int posicoes_x[] = {0, 1024, 512, 800, 0, 0, 0, 0, 0, 0, 0, 0};
-//    int posicoes_y[] = {0, 1024, 512, 800, 0, 0, 0, 0, 0, 0, 0, 0};
-//    int posicoes_z[] = {0, 1024, 512, 800, 0, 0, 0, 0, 0, 0, 0, 0};
-//    int pegas[] = {0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0};
-//    int referenciar = 0;
-//    char tempo_no_lcd[80];
+    int posicoes_x[] = {0, 1024, 512, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+    int posicoes_y[] = {0, 1024, 512, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+    int posicoes_z[] = {0, 1024, 512, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+    int pegas[] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+    int referenciar = 0;
+    char tempo_no_lcd[80];
+//    printf("%f",tempo);
+//
+//    velocidade.rise(&mudar_velocidade);
+//
+//    setar_posicoes();
+//    printf("%f",tempo);
+//    ler_SD();
 
 
-    while(1) {
-        
-        velocidade.rise(mudar_velocidade);
-        setar_posicoes();
-        ler_SD();
-        
-        
-        /*display_to_lcd("Bem vindo /n");
-        display_to_lcd("Prosseguir");
-        if(arrow_right == 1){
-            display_to_lcd("Setar nova posição /n");
-            display_to_lcd("Utilizar a última posição");
-            if(arrow_up == 1) {
-                home();
-                referenciamento();
-                adquirir_posições();
-                }
-            if(arrow_down == 1 {
-                last_update()
-                }
-        }*/
+    /*display_to_lcd("Bem vindo /n");
+    display_to_lcd("Prosseguir");
+    if(arrow_right == 1){
+        display_to_lcd("Setar nova posição /n");
+        display_to_lcd("Utilizar a última posição");
+        if(arrow_up == 1) {
+            home();
+            referenciamento();
+            adquirir_posições();
+            }
+        if(arrow_down == 1 {
+            last_update()
+            }
+    }*/
+    while (1) {
 //    home();
 // JOG
-//        int numero_pegas = 0;
+ //       int numero_pegas = 0;
 //        int x_pega = posicoes_x[1];
 //        int y_pega = posicoes_y[1];
 //        int z_pega = posicoes_z[1];
@@ -64,32 +64,72 @@
 //                int y_posicao = posicoes_y[i];
 //                int z_posicao = posicoes_z[i];
 //                numero_pegas = pegas[i];
-//                if (x_posicao == 0 && y_posicao == 0 && counter == 0) {
+//                if (posicoes_x[i+1] == 0 && posicoes_y[i+1] == 0 && counter == 0) {
 //                    voltar_home = 1;
 //                    counter = 1;
+//                    jog (x_posicao, y_posicao, z_posicao, x_pega, y_pega, z_pega, numero_pegas, voltar_home);
+//                    mover_HOME (x_posicao, y_posicao);
 //                } else if (i == 1) {
 //                    voltar_home = 1;
+//                    jog (x_posicao, y_posicao, z_posicao, x_pega, y_pega, z_pega, numero_pegas, voltar_home);
+//                } else {
+//                    jog (x_posicao, y_posicao, z_posicao, x_pega, y_pega, z_pega, numero_pegas, voltar_home);
 //                }
-//                jog (x_posicao, y_posicao, z_posicao, x_pega, y_pega, z_pega, numero_pegas, voltar_home);
 //            }
 //            referenciar = 1;
 //        }
 
 // JOG PREVIEW
 
-        //if (referenciar == 0) {
-//            for (int i=0; i < 11; i++) {
-//                int posicao_anterior_x = posicoes_x[i];
-//                int posicao_anterior_y = posicoes_y[i];
-//                int posicao_anterior_z = posicoes_z[i];
-//                int posicao_atual_x = posicoes_x[i+1];
-//                int posicao_atual_y = posicoes_y[i+1];
-//                int posicao_atual_z = posicoes_z[i+1];
-//                jog_preview (posicao_atual_x, posicao_atual_y, posicao_atual_z, posicao_anterior_x, posicao_anterior_y, posicao_anterior_z);
+if (referenciar == 0) {
+            for (int i=0; i < 11; i++) {
+                int posicao_anterior_x = posicoes_x[i];
+                int posicao_anterior_y = posicoes_y[i];
+                int posicao_anterior_z = posicoes_z[i];
+                int posicao_atual_x = posicoes_x[i+1];
+                int posicao_atual_y = posicoes_y[i+1];
+                int posicao_atual_z = posicoes_z[i+1];
+                jog_preview (posicao_atual_x, posicao_atual_y, posicao_atual_z, posicao_anterior_x, posicao_anterior_y, posicao_anterior_z);
+            }
+            referenciar = 1;
+        }
+
+// TEMPO JOG PREVIEW
+//        float tempo_total = 0;
+//        float mover = 0;
+//        if (referenciar == 0) {
+//            for (int i=1; i < 12; i++) {
+//                int posicao_atual_x = posicoes_x[i];
+//                int posicao_atual_y = posicoes_y[i];
+//                int posicao_atual_z = posicoes_z[i];
+//                int posicao_anterior_x = posicoes_x[i-1];
+//                int posicao_anterior_y = posicoes_y[i-1];
+//                mover = tempo_jog_preview (posicao_anterior_x, posicao_anterior_y, posicao_atual_x, posicao_atual_y, posicao_atual_z);
+//                tempo_total += mover;
 //            }
 //            referenciar = 1;
+//            if (tempo_total >= 60 && tempo_total < 3600) {
+//                int min = abs(tempo_total/60);
+//                int seg = abs((tempo_total/60 - min)*60);
+//                printf(" %d minutos e %d segundos \n", min, seg);
+//                sprintf(tempo_no_lcd, "Deseja iniciar o ciclo?\n\n             %imin%is \n", min, seg);
+//                mostrar_no_lcd(tempo_no_lcd);
+//
+//            } else if (tempo_total < 60) {
+//                int seg = abs(tempo_total);
+//                printf("%d segundos \n", seg);
+//                sprintf(tempo_no_lcd, "Deseja iniciar o ciclo?\n\n             %is \n", seg);
+//                mostrar_no_lcd(tempo_no_lcd);
+//            } else if (tempo_total >= 3600) {
+//                int hora = abs(tempo_total/3600);
+//                int min = abs(tempo_total/3600 - hora)*60;
+//                printf("%d horas e %d minutos \n", hora, min);
+//                sprintf(tempo_no_lcd, "Deseja iniciar o ciclo?\n\n             %ih%imin\n", hora, min);
+//                mostrar_no_lcd(tempo_no_lcd);
+//            }
 //        }
 
+
 // TEMPO DE CICLO
 //        int numero_pegas = 0;
 //        float tempo_total = 0;
@@ -97,13 +137,17 @@
 //        int x_pega = posicoes_x[1];
 //        int y_pega = posicoes_y[1];
 //        int z_pega = posicoes_z[1];
+//        int ultimo = 0;
 //        if (referenciar == 0) {
 //            for (int i=1; i < 12; i++) {
 //                int posicao_atual_x = posicoes_x[i];
 //                int posicao_atual_y = posicoes_y[i];
 //                int posicao_atual_z = posicoes_z[i];
 //                numero_pegas = pegas[i];
-//                mover = tempo_de_ciclo (posicao_atual_x, posicao_atual_y, posicao_atual_z, x_pega, y_pega, z_pega, numero_pegas, i);
+//                if (posicoes_x[i+1] == 0 && posicoes_y[i+1] == 0) {
+//                    ultimo == 1;
+//                }
+//                mover = tempo_de_ciclo (posicao_atual_x, posicao_atual_y, posicao_atual_z, x_pega, y_pega, z_pega, numero_pegas, i, ultimo);
 //                tempo_total += mover;
 //            }
 //            referenciar = 1;
@@ -111,16 +155,20 @@
 //                int min = abs(tempo_total/60);
 //                int seg = abs((tempo_total/60 - min)*60);
 //                printf(" %d minutos e %d segundos \n", min, seg);
-//                sprintf(tempo_no_lcd, "Deseja iniciar o JOG?\n\n             %imin%is \n", min, seg);
+//                sprintf(tempo_no_lcd, "Deseja iniciar o ciclo?\n\n             %imin%is \n", min, seg);
 //                mostrar_no_lcd(tempo_no_lcd);
 //
 //            } else if (tempo_total < 60) {
 //                int seg = abs(tempo_total);
 //                printf("%d segundos \n", seg);
+//                sprintf(tempo_no_lcd, "Deseja iniciar o ciclo?\n\n             %is \n", seg);
+//                mostrar_no_lcd(tempo_no_lcd);
 //            } else if (tempo_total >= 3600) {
 //                int hora = abs(tempo_total/3600);
 //                int min = abs(tempo_total/3600 - hora)*60;
 //                printf("%d horas e %d minutos \n", hora, min);
+//                sprintf(tempo_no_lcd, "Deseja iniciar o ciclo?\n\n             %ih%imin\n", hora, min);
+//                mostrar_no_lcd(tempo_no_lcd);
 //            }
 //        }
     }