Projeto Mecatrônico / Mbed 2 deprecated LCD_IHM

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IHM.cpp Source File

IHM.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 
00004 TextLCD lcd(D8, D9, D4, D5, D6, D7); // rs, e, d4-d7
00005 Serial pc (USBTX, USBRX);
00006 AnalogIn eixo_Z(PC_2);
00007 AnalogIn botao_SELECT(A0);
00008 InterruptIn posicao_salva(PA_15);
00009 InterruptIn botao_emergencia(PC_4);
00010 DigitalIn botao_indicador_fonte_externa(PC_10);
00011 
00012 BusOut motor_z(PB_1, PB_15, PB_14, PB_13);
00013 float tempo_horario, tempo_anti_horario; //Segundos
00014 int pulsos_horario, pulsos_anti_horario;
00015 int i;
00016 int J_Z;
00017 float deslocamento_horario_Z, deslocamento_anti_horario_Z, deslocamento_total_Z;
00018 float velocidade_Z;
00019 float passo_motor = 18;//5.625/32;
00020 int passo_fuso = 5;
00021 int pegaZ;
00022 int posicao_salva_estado, botao_emergencia_estado;
00023 int fonte_externa;
00024 int SELECT, valor_SELECT;
00025 
00026 void rotina_posicao_salva(void);
00027 void rotina_emergencia(void);
00028 void rotida_velocidade_eixo_Z(void);
00029 void rotida_deslocamento_eixo_Z (void);
00030 void rotida_aciona_motor (void);
00031 void rotida_botoes_IHM (void);
00032 
00033 
00034 int main()
00035 {
00036 
00037     pc.baud(115200);
00038     motor_z = 0x00;
00039     posicao_salva.rise(&rotina_posicao_salva);
00040     botao_emergencia.rise(&rotina_emergencia);
00041     lcd.locate(0,0);
00042     lcd.printf("PosicaoZ:");
00043 
00044 
00045     while(1) {
00046 
00047         posicao_salva_estado = posicao_salva.read();
00048         botao_emergencia_estado = botao_emergencia.read();
00049         J_Z = eixo_Z.read_u16();
00050         fonte_externa = botao_indicador_fonte_externa.read();
00051         SELECT = botao_SELECT.read_u16();
00052         rotida_botoes_IHM();
00053         
00054         pc.printf("Select=%d\r\n", valor_SELECT);
00055         //pc.printf("Z=%4d, PegaZ=%4d, Posicao_salva_estado=%d, Botao_emergencia_estado=%d, Tempo1=%4f, Tempo2=%4f, Pulsos=%d, Deslocamento_Z=%f, Velocidade_Z=%f\r\n", J_Z, pegaZ, posicao_salva_estado, botao_emergencia_estado, tempo_horario, tempo_anti_horario, pulsos_anti_horario, deslocamento_total_Z, velocidade_Z);
00056 
00057         if(fonte_externa == 0) {
00058             lcd.locate(0,1);
00059             lcd.printf("%4fmm",deslocamento_total_Z);
00060 //            pc.printf("Fonte=%d\r\n", fonte_externa);
00061             rotida_aciona_motor();
00062 
00063         }
00064     }
00065 }
00066 
00067 
00068 void rotina_posicao_salva()
00069 {
00070     if(posicao_salva_estado == 0) pegaZ = J_Z;
00071     else pegaZ = 0;
00072 }
00073 
00074 void rotina_emergencia()
00075 {
00076     if(botao_emergencia_estado == 0) motor_z = 0x00;
00077 }
00078 
00079 void rotida_velocidade_eixo_Z()
00080 {
00081     tempo_horario = -1*J_Z*0.0000028 +0.1875;
00082     tempo_anti_horario = J_Z*0.000002785 +0.0025;
00083 }
00084 
00085 void rotida_deslocamento_eixo_Z()
00086 {
00087     deslocamento_horario_Z = (passo_fuso*pulsos_horario*passo_motor)/360;
00088     deslocamento_anti_horario_Z = (passo_fuso*pulsos_anti_horario*passo_motor)/360;
00089     deslocamento_total_Z = deslocamento_anti_horario_Z - deslocamento_horario_Z;
00090 }
00091 
00092 void rotida_botoes_IHM()
00093 {
00094 
00095     if(SELECT > 60000 & SELECT < 65000) valor_SELECT = 1;
00096     else valor_SELECT = 0;
00097 
00098 
00099 }
00100 
00101 
00102 void rotida_aciona_motor()
00103 {
00104 
00105     if(31000 <= J_Z &  J_Z <= 35000) {
00106 
00107         motor_z = 0x00;
00108 
00109     } else {
00110         if (J_Z > 31000) {
00111             for(i = 0; i < 4; i++) {
00112                 motor_z = 1 << i;
00113                 rotida_velocidade_eixo_Z();
00114                 rotida_deslocamento_eixo_Z();
00115                 wait(tempo_horario);
00116                 pulsos_horario+=1;
00117                 velocidade_Z = deslocamento_horario_Z/tempo_horario;
00118 
00119             }
00120         }
00121 
00122         if(J_Z < 35000) {
00123             for(i = 3; i > -1; i--) {
00124                 motor_z = 1 << i;
00125                 rotida_velocidade_eixo_Z();
00126                 rotida_deslocamento_eixo_Z();
00127                 wait(tempo_anti_horario);
00128                 pulsos_anti_horario+=1;
00129                 velocidade_Z = deslocamento_horario_Z/tempo_horario;
00130 
00131             }
00132         }
00133     }
00134 
00135 
00136 }