Projeto Mecatrônico
/
ProjetoMecatronico
testando
main_PM.cpp
- Committer:
- amandarm
- Date:
- 2020-05-26
- Revision:
- 22:dd336b95db5d
- Parent:
- 20:81a44a25b21d
- Child:
- 25:b0db528c1985
File content as of revision 22:dd336b95db5d:
//local para inclusão de bibliotecas #include "mbed.h" #include "TextLCD.h" #include "Keypad.h" //local para a declaração de variáveis float t_motor = 0.002; float t_teclado = 0.01; int hor[] = {12,6,3,9}; int antihor[] = {3,6,12,9}; int parado[] = {0,0,0,0}; char tecla; float coord_x = 0; float coord_y = 0; float coord_z = 0; int est_x = 0; int est_y = 0; int est_z = 0; //pinos usados pelos botões de fim de curso DigitalIn fdc_x(PC_10); DigitalIn fdc_y(PC_11); DigitalIn fdc_z(PC_12); //botões para movimentação eixo a eixo DigitalIn x_mais(PA_0); DigitalIn x_menos(PA_1); DigitalIn y_mais(PC_0); DigitalIn y_menos(PC_1); DigitalIn z_mais(PC_2); DigitalIn z_menos(PC_3); //pinos da placa usados na biblioteca do LCD TextLCD lcd(D4, D5, D6, D7, D8, D9); //pinos do teclado Keypad teclado(PA_6, PA_7, PB_6, PC_7, PB_7, PC_13, PC_14, PC_15); //pinos de saída para os motores //eixo x BusOut eixox(PA_15,PA_14,PA_13,PA_12); //eixo y BusOut eixoy(PA_11,PA_10,PB_2,PB_1); //eixo z BusOut eixoz(PC_9,PC_8,PB_8,PC_6); //funções para as telas da IHM void funcao_inicio(){ lcd.printf("1-Novo programa"); lcd.locate(0,1); lcd.printf("2-Usar programa salvo"); lcd.locate(0,2); } void funcao_tela_zera(){ lcd.printf("Zeramento:"); lcd.locate(0,1); lcd.printf("Confira se não há"); lcd.locate(0,2); lcd.printf("objetos sobre a mesa"); lcd.locate(0,3); lcd.printf("A-Próximo B-Voltar"); } void funcao_pega1(){ lcd.printf("Configuração de pega"); lcd.locate(0,1); lcd.printf("1-Forma do pega"); lcd.locate(0,2); lcd.printf("2-Volume do pega"); lcd.locate(0,3); lcd.printf(" B-Voltar"); } void funcao_pega2(){ lcd.printf("Configuração de pega"); lcd.locate(0,1); lcd.printf("3-Posição do pega"); lcd.locate(0,2); lcd.printf(""); lcd.locate(0,3); lcd.printf(" B-Voltar"); } void funcao_pega_forma(){ lcd.printf("Forma do pega"); lcd.locate(0,1); lcd.printf("1 - Quadrado"); lcd.locate(0,2); lcd.printf("2 - Circular"); lcd.locate(0,3); lcd.printf(" B-Voltar"); } void funcao_pega_volume(){ lcd.printf("Insira o volume"); lcd.locate(0,1); lcd.printf("Em ml:"); lcd.locate(0,2); lcd.printf(""); lcd.locate(0,3); lcd.printf("A-Próximo B-Voltar"); } void funcao_pega_forma_quad(){ lcd.printf("Dimensões do pega"); lcd.locate(0,1); lcd.printf("Comprimento em mm"); lcd.locate(0,2); lcd.printf(""); lcd.locate(0,3); lcd.printf("A-Próximo B-Voltar"); } void funcao_pega_forma_red(){ lcd.printf("Dimensões do pega"); lcd.locate(0,1); lcd.printf("Diamentro em mm"); lcd.locate(0,2); lcd.printf(""); lcd.locate(0,3); lcd.printf("A-Próximo B-Voltar"); } void funcao_pega_pos_x(){ //desativar os botões de Y lcd.printf("Posicione pega em X"); lcd.locate(0,1); lcd.printf("Use botões até chegar"); lcd.locate(0,2); lcd.printf("na posição desejada"); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_pega_pos_y(){ //desativar os botões de X lcd.printf("Posicione pega em Y"); lcd.locate(0,1); lcd.printf("Use botões até chegar"); lcd.locate(0,2); lcd.printf("na posição desejada"); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_solta1(){ lcd.printf("Configuração solta"); lcd.locate(0,1); lcd.printf("1-Dimensão solta"); lcd.locate(0,2); lcd.printf("2-Volume da solta"); lcd.locate(0,3); lcd.printf(" B-Voltar"); } void funcao_solta2(){ lcd.printf("Configuração solta"); lcd.locate(0,1); lcd.printf("3-Posição solta"); lcd.locate(0,2); lcd.printf(""); lcd.locate(0,3); lcd.printf(" B-Voltar"); } void funcao_solta_dimensao(){ lcd.printf("Insira o diametro"); lcd.locate(0,1); lcd.printf("de solta, em mm:"); lcd.locate(0,2); lcd.printf(""); lcd.printf(0,3); lcd.printf("A-Próximo B-Voltar"); } void funcao_solta_vol(){ lcd.printf("Determinar volume"); lcd.locate(0,1); lcd.printf("1-Todos mesmo volume"); lcd.locate(0,2); lcd.printf("2-Pino a pino"); lcd.locate(0,3); lcd.printf("A-Próximo B-Voltar"); } void funcao_solta_vol_igual(){ lcd.printf("Insira o volume"); lcd.locate(0,1); lcd.printf("em ml:"); lcd.locate(0,2); lcd.printf(""); lcd.locate(0,3); lcd.printf("A-Próximo B-Voltar"); } void funcao_solta_vol_cada(){ lcd.printf("Seleção: * * * "); lcd.locate(0,1); lcd.printf("Volume: * * * "); lcd.locate(0,2); lcd.printf("A-Confirma * * * "); lcd.locate(0,3); lcd.printf("B-Corrigir C-Próximo"); } void funcao_solta_pos_x(){ //desativar os botões de Y lcd.printf("Posicione pega em X"); lcd.locate(0,1); lcd.printf("Use botões até chegar"); lcd.locate(0,2); lcd.printf("na posição desejada"); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_solta_pos_y(){ //desativar os botões de X lcd.printf("Posicione pega em Y"); lcd.locate(0,1); lcd.printf("Use botões até chegar"); lcd.locate(0,2); lcd.printf("na posição desejada"); lcd.printf(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_confirma(){ lcd.printf("Revisão Parametros"); lcd.locate(0,1); lcd.printf("1-Pega:"); lcd.locate(0,2); lcd.printf("2-Pinos solta:"); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_nome_prog(){ lcd.printf("Nome do programa"); lcd.locate(0,1); lcd.printf("Insira um código"); lcd.locate(0,2); lcd.printf("para seu programa:"); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_acomp(){ //colocar os valores adequados na tela lcd.printf("Prog em execução"); lcd.locate(0,1); lcd.printf("Tempo: xx min yy s"); lcd.locate(0,2); lcd.printf("Progresso: zz%"); lcd.locate(0,3); lcd.printf("A-Pausar"); } void funcao_pausa(){ lcd.printf("Prog pausado"); lcd.locate(0,1); lcd.printf("Progresso: zz%"); lcd.locate(0,2); lcd.printf(""); lcd.locate(0,3); lcd.printf("A-Continuar B-Parar"); } void funcao_salvo1(){ lcd.printf("1-xx"); lcd.locate(0,1); lcd.printf("2-yy"); lcd.locate(0,2); lcd.printf("3-zz"); lcd.locate(0,3); lcd.printf("A-Próxima B-Anterior"); } void funcao_salvo2(){ lcd.printf("4-xx"); lcd.locate(0,1); lcd.printf("5-yy"); lcd.locate(0,2); lcd.printf("6-zz"); lcd.locate(0,3); lcd.printf("A-Próxima B-Anterior"); } void funcao_salvo_agree1(){ lcd.printf("Confirmar programa"); lcd.locate(0,1); lcd.printf("1-Posição pega"); lcd.locate(0,2); lcd.printf("2-Posição solta"); lcd.locate(0,3); lcd.printf(" B-Voltar"); } void funcao_salvo_agree2(){ lcd.printf("Confirmar programa"); lcd.locate(0,1); lcd.printf("3-Volume pega"); lcd.locate(0,2); lcd.printf("4-Volume solta"); lcd.locate(0,3); lcd.printf(" B-Voltar"); } void funcao_salvo_agree_pos_aviso(){ lcd.printf("A pipeta irá na pega"); lcd.locate(0,1); lcd.printf("Certifique-se que não"); lcd.locate(0,2); lcd.printf("há objetos na mesa"); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_salvo_agree_pos_certo(){ lcd.printf("Posicão correta?"); lcd.locate(0,1); lcd.printf("1-Sim"); lcd.locate(0,2); lcd.printf("2-Ajustar"); lcd.locate(0,3); lcd.printf(" B-Voltar"); } void funcao_salvo_agree_solta_aviso(){ lcd.printf("A pipeta irá na solta"); lcd.locate(0,1); lcd.printf("Certifique-se que não"); lcd.locate(0,2); lcd.printf("há objetos na mesa"); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_salvo_agree_pega_vol(){ lcd.printf("Insira o volume pega"); lcd.locate(0,1); lcd.printf("Em ml:"); lcd.locate(0,2); lcd.printf(""); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } void funcao_salvo_agree_solta_vol(){ lcd.printf("1-x 2-y 3-z"); lcd.locate(0,1); lcd.printf("4-x 5-y 6-z"); lcd.locate(0,2); lcd.printf("7-x 8-y 9-z"); lcd.locate(0,3); lcd.printf("A-Confirma B-Voltar"); } int main() { printf("\n%i",est_x); printf("\n%i",est_y); printf("\n%i",est_z); lcd.printf("Bem-vindo ao Pipemax"); lcd.locate(0,1); lcd.printf("o seu sistema"); lcd.locate(0,2); lcd.printf("automatizado"); lcd.locate(0,3); lcd.printf("de pipetagem"); while (fdc_x != 0){for(int i = 0; i < 4; i++){eixox = hor[i];wait(t_motor);est_x = 1;}} while (fdc_y != 0){for(int i = 0; i < 4; i++){eixoy = hor[i];wait(t_motor);est_y = 1;}} while (fdc_z != 0){for(int i = 0; i < 4; i++){eixoz = hor[i];wait(t_motor);est_z = 1;}} printf("\n%i",est_x); printf("\n%i",est_y); printf("\n%i",est_z); while(1) { int solta = 1; tecla = teclado.ReadKey(); //read the current key pressed if(tecla == '\0') solta = 1; //set the flag when all keys are released if((tecla != '\0') && (solta == 1)) { //if a key is pressed AND previous key was released printf("%c\n", tecla); solta = 0; //clear the flag to indicate that key is still pressed wait(0.1);} /* tentativa de fazer o motor parar ao apertar algum dos fins de curso if(fdc_x == 0 || fdc_y == 0 || fdc_z == 0){ for(int i = 0; i < 4; i++){eixox = parado[i];wait(t_motor);est_x = 1;} for(int i = 0; i < 4; i++){eixoy = parado[i];wait(t_motor);est_y = 1;} for(int i = 0; i < 4; i++){eixoz = parado[i];wait(t_motor);est_z = 1;} */ 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_menos == 0){for(int i = 0; i < 4; i++){eixox = antihor[i];wait(t_motor);coord_x -= (5.625*5/32)/360;est_x = 0; 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);}} if (y_menos == 0){for(int i = 0; i < 4; i++){eixoy = antihor[i];wait(t_motor);coord_y -= (5.625*5/32)/360;est_y = 0; 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);}} if (z_menos == 0){for(int i = 0; i < 4; i++){eixoz = antihor[i];wait(t_motor);coord_z -= (5.625*5/32)/360;est_z = 0; 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);}} if (x_mais == 0){for(int i = 0; i < 4; i++){eixox = hor[i];wait(t_motor);coord_x += (5.625*5/32)/360;est_x = 0; 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);}} if (y_mais == 0){for(int i = 0; i < 4; i++){eixoy = hor[i];wait(t_motor);coord_y += (5.625*5/32)/360;est_y = 0; 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);}} if (z_mais == 0){for(int i = 0; i < 4; i++){eixoz = hor[i];wait(t_motor);coord_z += (5.625*5/32)/360;est_z = 0; 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);}} if (x_mais || x_menos || y_mais || y_menos || z_mais || z_menos != 0){ for(int i = 0; i < 4; i++){eixox = parado[i];} for(int i = 0; i < 4; i++){eixoy = parado[i];} for(int i = 0; i < 4; i++){eixoz = parado[i];} } /* 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); */ } }