Projeto Mecatrônico
/
ProjetoMecatronico
testando
main_PM.cpp
- Committer:
- enricoan
- Date:
- 2020-05-27
- Revision:
- 32:2a9b30e1e7ab
- Parent:
- 31:acb062a05984
- Child:
- 33:a513498222c7
File content as of revision 32:2a9b30e1e7ab:
//local para inclusao de bibliotecas #include "mbed.h" #include "TextLCD.h" #include "Keypad.h" #include "funcoes_ihm.h" //local para a declaracao de varioveis float t_motor = 0.002; //delay entre o acionamento de uma bobina do motor e a outra float t_teclado = 0.01; //delay entre a leitura de um botão do teclado, necessário para que um click nao gere mais de uma saída int hor[] = {12,6,3,9}; //valores que, ao serem convertidos em binário, geram a sequência de acionamento do motor no sentido horário enviando a sequência de 0's e 1's às bobinas int antihor[] = {3,6,12,9}; //valores que, ao serem convertidos em binário, geram a sequência de acionamento do motor no sentido anti-horário enviando a sequência de 0's e 1's às bobinas int parado[] = {0,0,0,0}; //valores enviados às bobinas do motor para deixá-lo parado char tecla; //variável que guarda a tecla apertada no teclado float coord_x = 0; //variável que guardará a posição linear do eixo x, ela é incrementada com a conta do deslocamento linear dado um deslocamento angular sempre que o eixo é movimentado depois do referencimaneto float coord_y = 0; //variável que guardará a posição linear do eixo y, ela é incrementada com a conta do deslocamento linear dado um deslocamento angular sempre que o eixo é movimentado depois do referencimaneto float coord_z = 0; //variável que guardará a posição linear do eixo z, ela é incrementada com a conta do deslocamento linear dado um deslocamento angular sempre que o eixo é movimentado depois do referencimaneto int est_x = 0; //variável que indicará o estado do eixo x, pemitindo ou não que ele possa ser avançado depois de atingir o fim de curso int est_y = 0; //variável que indicará o estado do eixo y, pemitindo ou não que ele possa ser avançado depois de atingir o fim de curso int est_z = 0; //variável que indicará o estado do eixo z, pemitindo ou não que ele possa ser avançado depois de atingir o fim de curso //pinos usados pelos botoes de fim de curso DigitalIn fdc_x(PC_10); DigitalIn fdc_y(PC_11); DigitalIn fdc_z(PC_12); //Iterrupcao botao de emergência InterruptIn emergencia_botao(PC_13); //trocar esse botao para onde esto o botao de fato //pinos do rele DigitalOut rele1(PC_5); DigitalOut rele2(PB_9); //botoes para movimentacao 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 //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); //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; eixox = 0b0000; eixoy = 0b0000; eixoz = 0b0000; lcd.cls(); lcd.printf("Botao Emergencia"); lcd.locate(0,1); lcd.printf(" acionado "); lcd.locate(0,2); 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;}} 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);*/} //Varioveis para operacao IHM #include <string> using std::string; 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); 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"); wait(3); while(1) { lcd.cls(); lcd.printf("Por favor, aceite"); lcd.locate(0,1); lcd.printf("o zeramento do seu"); lcd.locate(0,2); lcd.printf("sistema"); lcd.locate(0,3); lcd.printf("A - proximo"); tecla = teclado.ReadKey(); if(tecla == 'A' && status_tela == "zeramento"){ zeramento(); printf("\n%s",status_tela); 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);} /* 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){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){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(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];} } /* 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); */ tecla = teclado.ReadKey(); if(tecla =='1' && status_tela == "inicio"){ funcao_pega1(); wait(1); funcao_pega2(); status_tela = "novo";} else if(tecla == '2' && status_tela == "inicio"){ funcao_salvo1(); wait(1); funcao_salvo2(); status_tela = "salvo";} if(tecla =='1' && status_tela =="novo"){ funcao_pega_forma(); status_tela ="forma";} else if(tecla =='2' && status_tela == "novo"){ funcao_pega_volume(); status_tela = "volume";} else if(tecla == '3' && status_tela == "novo"){ funcao_pega_pos_x(); status_tela = "pos_x";} else if(tecla == 'B' && status_tela == "novo"){ funcao_inicio(); status_tela = "inicio";} else if(tecla == '1' && status_tela == "salvo"){ funcao_salvo_agree1(); status_tela = "confirmacao";} else if(tecla =='2' && status_tela == "salvo"){ funcao_salvo_agree1(); status_tela = "confirmacao";} else if(tecla =='B' && status_tela == "salvo"){ funcao_inicio(); status_tela = "inicio";} if(tecla == '1' && status_tela == "forma"){ funcao_pega_forma_quad(); status_tela ="forma_quad";} else if(tecla == '2' && status_tela == "forma"){ funcao_pega_forma_red(); status_tela = "forma_quad";} else if(tecla == 'B' && status_tela == "forma"){ funcao_pega_forma(); status_tela = "novo";} if(tecla == 'A' && status_tela == "forma_quad"){ funcao_pega1(); wait(1); funcao_pega2(); status_tela ="inicio";} else if(tecla == 'B' && status_tela == "forma_quad"){ funcao_pega_forma(); status_tela = "forma";} else if(tecla == 'A' && status_tela == "forma_red"){ funcao_pega1(); wait(1); funcao_pega2(); status_tela ="inicio";} else if(tecla == 'B' && status_tela == "forma_red"){ funcao_pega_forma(); status_tela = "forma";} else if(tecla == 'A' && status_tela == "volume"){ funcao_pega1(); wait(1); funcao_pega2(); status_tela ="inicio";} else if( tecla == 'B' && status_tela == "volume"){ funcao_pega_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";} else if(tecla == 'B' && status_tela == "pos_x"){ funcao_pega_forma(); status_tela = "forma";} if(tecla == 'A' && status_tela == "pos_y"){ funcao_pega1(); wait(1); funcao_pega2(); status_tela ="inicio";} else if(tecla == 'B' && status_tela == "pos_y"){ funcao_pega_forma(); status_tela = "forma";} } }