Projeto Mecatrônico
/
ProjetoMecatronico
testando
Diff: main_PM.cpp
- Revision:
- 32:2a9b30e1e7ab
- Parent:
- 31:acb062a05984
- Child:
- 33:a513498222c7
--- a/main_PM.cpp Wed May 27 13:14:36 2020 +0000 +++ b/main_PM.cpp Wed May 27 14:31:48 2020 +0000 @@ -39,7 +39,6 @@ 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); @@ -52,11 +51,18 @@ //eixo z BusOut eixoz(PC_9,PC_8,PB_8,PC_6); -//Funcao de iterrupcao -void emergencia() -{ +//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_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_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;}} + +//Funcao de interrupcao +void emergencia(){TextLCD lcd(D4, D5, D6, D7, D8, D9); while(emergencia_botao == 0){ - //rele1 = 0; + rele1 = 0; eixox = 0b0000; eixoy = 0b0000; eixoz = 0b0000; @@ -65,14 +71,8 @@ lcd.locate(0,1); lcd.printf(" acionado "); lcd.locate(0,2); - lcd.printf("Operacao pausada"); - //lcd.locate(0,3); - //lcd.printf("); - } -} - + lcd.printf("Operacao pausada");}} //Funcao de zeramento - void zeramento(){ 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;}} @@ -80,15 +80,15 @@ /* printf("\n%i",est_x); printf("\n%i",est_y); - printf("\n%i",est_z);*/ -} + printf("\n%i",est_z);*/} //Varioveis para operacao IHM #include <string> using std::string; -string status_tela = "inicio"; +string status_tela = "zeramento"; int main() { + TextLCD lcd(D4, D5, D6, D7, D8, D9); printf("\n%i",est_x); printf("\n%i",est_y); printf("\n%i",est_z); @@ -101,7 +101,6 @@ lcd.printf("de pipetagem"); wait(3); while(1) { - /* lcd.cls(); lcd.printf("Por favor, aceite"); lcd.locate(0,1); @@ -117,14 +116,13 @@ status_tela == "inicio"; printf("\n%s",status_tela); funcao_inicio();} - */ - 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);} + 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;} @@ -136,51 +134,37 @@ 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_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);} + + if(y_menos == 0){mov_y_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);} + + if(z_menos == 0){mov_z_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);} - 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 == 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);} + + if(y_mais == 0){mov_y_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);} - if (x_mais || x_menos || y_mais || y_menos || z_mais || z_menos != 0){ + if(z_mais == 0){mov_z_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);} + + 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];} @@ -200,107 +184,79 @@ funcao_pega1(); wait(1); funcao_pega2(); - status_tela = "novo"; - } + status_tela = "novo";} else if(tecla == '2' && status_tela == "inicio"){ funcao_salvo1(); wait(1); funcao_salvo2(); - status_tela = "salvo"; - } - tecla = teclado.ReadKey(); - if(tecla =='1' && status_tela =="novo"){ + status_tela = "salvo";} + if(tecla =='1' && status_tela =="novo"){ funcao_pega_forma(); - status_tela ="forma"; - } + status_tela ="forma";} else if(tecla =='2' && status_tela == "novo"){ funcao_pega_volume(); - status_tela = "volume"; - } + status_tela = "volume";} else if(tecla == '3' && status_tela == "novo"){ funcao_pega_pos_x(); - status_tela = "pos_x"; - } + status_tela = "pos_x";} else if(tecla == 'B' && status_tela == "novo"){ funcao_inicio(); - status_tela = "inicio"; - } + status_tela = "inicio";} else if(tecla == '1' && status_tela == "salvo"){ funcao_salvo_agree1(); - status_tela = "confirmacao"; - } + status_tela = "confirmacao";} else if(tecla =='2' && status_tela == "salvo"){ funcao_salvo_agree1(); - status_tela = "confirmacao"; - } + status_tela = "confirmacao";} else if(tecla =='B' && status_tela == "salvo"){ funcao_inicio(); - status_tela = "inicio"; - } - tecla = teclado.ReadKey(); + status_tela = "inicio";} if(tecla == '1' && status_tela == "forma"){ funcao_pega_forma_quad(); - status_tela ="forma_quad"; - } + status_tela ="forma_quad";} else if(tecla == '2' && status_tela == "forma"){ funcao_pega_forma_red(); - status_tela = "forma_quad"; - } + status_tela = "forma_quad";} else if(tecla == 'B' && status_tela == "forma"){ funcao_pega_forma(); - status_tela = "novo"; - } - - tecla = teclado.ReadKey(); + status_tela = "novo";} if(tecla == 'A' && status_tela == "forma_quad"){ funcao_pega1(); wait(1); funcao_pega2(); - status_tela ="inicio"; - } + status_tela ="inicio";} else if(tecla == 'B' && status_tela == "forma_quad"){ funcao_pega_forma(); - status_tela = "forma"; - } + status_tela = "forma";} else if(tecla == 'A' && status_tela == "forma_red"){ funcao_pega1(); wait(1); funcao_pega2(); - status_tela ="inicio"; - } + status_tela ="inicio";} else if(tecla == 'B' && status_tela == "forma_red"){ funcao_pega_forma(); - status_tela = "forma"; - } + status_tela = "forma";} else if(tecla == 'A' && status_tela == "volume"){ funcao_pega1(); wait(1); funcao_pega2(); - status_tela ="inicio"; - } + status_tela ="inicio";} else if( tecla == 'B' && status_tela == "volume"){ funcao_pega_forma(); - status_tela = "forma"; - } + status_tela = "forma";} else if(tecla == 'A' && status_tela == "pos_x"){ funcao_pega_pos_y(); //colocar programacao que contem o posicionamento do eixo y - status_tela = "pos_y"; - } + status_tela = "pos_y";} else if(tecla == 'B' && status_tela == "pos_x"){ funcao_pega_forma(); - status_tela = "forma"; - } - - tecla = teclado.ReadKey(); + status_tela = "forma";} if(tecla == 'A' && status_tela == "pos_y"){ funcao_pega1(); wait(1); funcao_pega2(); - status_tela ="inicio"; - } + status_tela ="inicio";} else if(tecla == 'B' && status_tela == "pos_y"){ funcao_pega_forma(); - status_tela = "forma"; - } + status_tela = "forma";} } }