Projeto_Mecatronico_Team / Mbed 2 deprecated Projeto_Mecatronico

Dependencies:   mbed filesystem TextLCD

Fork of Projeto_Mecatronico by Fernando Sakabe

main.cpp

Committer:
ricardoparanhos
Date:
2022-06-02
Revision:
28:84a60377564e
Parent:
27:cb310c1d2353
Child:
29:2ec7b2213197

File content as of revision 28:84a60377564e:

#include "JOG.h"
#include "home.h"
#include "LCD.h"
#include "tempo_de_ciclo.h"
#include <iostream>
#include "posicao.h"
#include "SD.h"
#include "perifericos.h"

extern bool emerg = 0;
char mensagem_emergencia[80];
bool flag=0;
bool flag_main=0;
bool velo = 1;
InterruptIn velocidade(PB_11);
DigitalIn vel_inicial(PB_11);
InterruptIn emergencia (PC_13);

void abaixar_velocidade()
{
    tempo=0.004;
}

void aumentar_velocidade()
{
    tempo=0.002;
}

void estado_emergencia_funcao ()
{
    int apitou = 0;
    while (emergencia == 1) {
        if (apitou == 0) {
            acionar_perifericos (2, 2);
            apitou = 1;
        }
        acionar_perifericos(2, 3);
    }
    emerg = 1;
    NVIC_SystemReset();

}



int main()
{
    if(vel_inicial==0) {
        tempo=0.002;
    } else {
        tempo=0.004;
    }
    velocidade.fall(&aumentar_velocidade);
    velocidade.rise(&abaixar_velocidade);
    emergencia.rise(&estado_emergencia_funcao);
    printf("oi");
    while(1) {
        acionar_perifericos (1, 0);
        wait(2);
        acionar_perifericos (0, 0);
        wait(20);
        
        if(flag==0) {
            mostrar_no_lcd("Bem-Vindo!\nAperte Prosseguir   para comecar.");
            acionar_perifericos (0, 0);
            flag=1;
        }
        if(arrow_right_button==0) {
            wait(0.5);
            while(flag_main==0) {
                if(flag==1) {
                    mostrar_no_lcd("Ir para home?\nPressione Prosseguir");
                    acionar_perifericos (0, 0);
                    flag=0;

                }
                wait(0.5);
                if(arrow_right_button==0) {
                    mostrar_no_lcd("Indo para home...");
                    acionar_perifericos (1, 0);
                    // home();
                    wait(0.5);
                    flag_main=1;
                }
            }
            wait(0.5);
            while(flag_main==1) {
                if(flag==0) {
                    acionar_perifericos (0, 0);
                    mostrar_no_lcd("Deseja utilizar posicoes salvas no SD? Enter para sim, Prosseguir para nao");
                    flag=1;
                }
                if(arrow_right_button==0) {
                    acionar_perifericos (1, 0);
                    setar_posicoes();
                    flag_main=0;

                } else if(enter_button==0) {
                    if(flag==1) {
                        acionar_perifericos (0, 0);
                        mostrar_no_lcd("Lendo SD...");
                        flag=0;
                    }

                    ler_SD();
                    flag_main=0;
                }

            }
            wait(0.5);
            while(flag_main==0) {

                if(flag==1) {
                    acionar_perifericos (0, 0);
                    mostrar_tempo_jog_preview();
                    flag=0;
                }
                wait(1);
                if(arrow_right_button==0) {
                    acionar_perifericos (1, 0);
                    mostrar_no_lcd("Executando JOG PREVIEW...");
                    jog_preview_completo ();
                    flag_main=1;
                } else if(enter_button==0) {
                    flag_main=1;
                }
            }
            wait(0.5);
            while(flag_main==1) {
                if(flag==0) {
                    acionar_perifericos (0, 0);
                    mostrar_tempo_jog();
                    flag=1;
                }

                if(arrow_right_button==0) {
                    acionar_perifericos (1, 0);
                    mostrar_no_lcd("Executando JOG...");

                    jog_completo();
                    mostrar_no_lcd("JOG finalizado. Para recomecar aperte Prosseguir.");
                    flag_main=0;
                }

            }
        }
    }
}





//int main()
//{
//    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();
//
//    emergencia.rise(&estado_emergencia_funcao);
//    while (1) {
//        emerg = 0;
//        while (emerg == 0) {
//            acionar_perifericos (0, 0);
//            wait(0.2);
//    home();
// JOG
//int numero_pegas = 0;
//        int x_pega = posicoes_x[1];
//        int y_pega = posicoes_y[1];
//        int z_pega = posicoes_z[1];
//        int counter = 0;
//            if (referenciar == 0) {
//                for (int i=1; i < 12; i++) {
//                    acionar_perifericos (1, 0);
//                    wait(0.5);
//                    if (emerg == 1) {
//                        break;
//                    }
//                int voltar_home = 0;
//                int x_posicao = posicoes_x[i];
//                int y_posicao = posicoes_y[i];
//                int z_posicao = posicoes_z[i];
//                numero_pegas = pegas[i];
//                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);
//                }
//                }
//                if (emerg == 1) {
//                    referenciar = 1;
//                    emerg = 0;
//                } else {
//                    acionar_perifericos (1, 1);
//                    referenciar = 1;
//                }
//            }

// JOG PREVIEW
//            referenciar = 0;
//            if (referenciar == 0) {
//                for (int i=0; i < 11; i++) {
//                    acionar_perifericos (1, 0);
//                    wait(0.5);
//                    if (emerg == 1) {
//                        break;
//                    }
//                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 (emerg == 1) {
//                    referenciar = 1;
//                    emerg = 0;
//                } else {
//                    acionar_perifericos (1, 1);
//                    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 JOG Preview?\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 JOG preview?\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 JOG preview?\n\n             %ih%imin\n", hora, min);
//                mostrar_no_lcd(tempo_no_lcd);
//            }
//        }


// TEMPO DE CICLO
//        int numero_pegas = 0;
//        float tempo_total = 0;
//        float mover = 0;
//        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];
//                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;
//            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);
//            }
//        }
//    }
//}