![](/media/cache/profiles/e32084632d369461572832e6582aac36.50x50_q85.jpg)
Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>
Dependencies: EthernetNetIf HTTPServer QEI_hw RPCInterface mbed
main.cpp@34:bdf918bc9b59, 2014-07-05 (annotated)
- Committer:
- Yo_Robot
- Date:
- Sat Jul 05 04:11:35 2014 +0000
- Revision:
- 34:bdf918bc9b59
- Parent:
- 33:e6ff02c3e0f5
- Child:
- 35:92b0f1b75a51
- Child:
- 36:a99dcd4d8f65
Aumentada una funcion para consultar alarma en ethernet, aun falta la solucion para la posici?n
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yo_Robot | 20:4b154134ab20 | 1 | /*******************************************************************\ |
Yo_Robot | 20:4b154134ab20 | 2 | * * |
Yo_Robot | 20:4b154134ab20 | 3 | * DESLIZADOR LINEAL UTN * |
Yo_Robot | 20:4b154134ab20 | 4 | * * |
Yo_Robot | 20:4b154134ab20 | 5 | * Archivo: main.cpp * |
Yo_Robot | 20:4b154134ab20 | 6 | * Autor: Ernesto Palacios <meacatronica.mid@gmail.com> * |
Yo_Robot | 30:413d1a6648b5 | 7 | * Version: v2.3 * |
Yo_Robot | 20:4b154134ab20 | 8 | * Dependencias: setup.h, setup.cpp * |
Yo_Robot | 22:d5431fff164b | 9 | * Descripcion: Este es el archivo principal para el microcon- * |
Yo_Robot | 23:2126e38bb48c | 10 | * trolador mbed para la comunicacion y control * |
Yo_Robot | 20:4b154134ab20 | 11 | * del deslizador * |
Yo_Robot | 20:4b154134ab20 | 12 | * Fecha: Ibarra, 05 de junio de 2012 * |
Yo_Robot | 20:4b154134ab20 | 13 | * * |
Yo_Robot | 20:4b154134ab20 | 14 | *******************************************************************/ |
Yo_Robot | 3:8d5a9e3cd680 | 15 | |
Yo_Robot | 3:8d5a9e3cd680 | 16 | #include "mbed.h" |
Yo_Robot | 25:1910a55ff0a3 | 17 | #include "qeihw.h" |
Yo_Robot | 3:8d5a9e3cd680 | 18 | #include "setup.h" |
Yo_Robot | 8:958dfe5052b9 | 19 | #include "EthernetNetIf.h" |
Yo_Robot | 8:958dfe5052b9 | 20 | #include "HTTPServer.h" |
Yo_Robot | 8:958dfe5052b9 | 21 | #include "RPCFunction.h" |
Yo_Robot | 8:958dfe5052b9 | 22 | #include "RPCVariable.h" |
Yo_Robot | 20:4b154134ab20 | 23 | |
Yo_Robot | 30:413d1a6648b5 | 24 | |
Yo_Robot | 23:2126e38bb48c | 25 | // Configuraci�n de Entradas / Salidas |
Yo_Robot | 9:6976ac1a430e | 26 | |
Yo_Robot | 25:1910a55ff0a3 | 27 | Serial pc( USBTX, USBRX ); //Comunicacion Serial directa al computador |
Yo_Robot | 25:1910a55ff0a3 | 28 | Serial RS_232(p13, p14); //Comunicacion Serial para MAX232 |
Yo_Robot | 31:7e2cdd547cb2 | 29 | |
Yo_Robot | 32:4483d6c225e5 | 30 | QEIHW encoder( QEI_DIRINV_CMPL, // CW = postive; CCW = negative |
Yo_Robot | 31:7e2cdd547cb2 | 31 | QEI_SIGNALMODE_QUAD, // Absolute encoder |
Yo_Robot | 33:e6ff02c3e0f5 | 32 | QEI_CAPMODE_2X, // PhA anb PhB |
Yo_Robot | 31:7e2cdd547cb2 | 33 | QEI_INVINX_NONE // Not inverted index |
Yo_Robot | 31:7e2cdd547cb2 | 34 | ); |
Yo_Robot | 31:7e2cdd547cb2 | 35 | |
Yo_Robot | 23:2126e38bb48c | 36 | Timer crono; // Reloj Interno de mbed |
Yo_Robot | 18:cf1e07d82630 | 37 | |
Yo_Robot | 18:cf1e07d82630 | 38 | DigitalOut pin_son( p7 ); // SON |
Yo_Robot | 18:cf1e07d82630 | 39 | DigitalOut pin_dir( p26 ); // SIGN+ |
Yo_Robot | 18:cf1e07d82630 | 40 | InterruptIn pin_alm( p8 ); // ALM |
Yo_Robot | 20:4b154134ab20 | 41 | AnalogOut aout( p18 ); // VOUT |
Yo_Robot | 24:a1d16835201c | 42 | //PIN_06 pto_generator // PULS+ |
Yo_Robot | 9:6976ac1a430e | 43 | |
Yo_Robot | 16:d50665706f21 | 44 | DigitalIn isHTTP( p15 ); // Modo Ethernet/Serial |
Yo_Robot | 16:d50665706f21 | 45 | DigitalIn isFast( p16 ); // Serial Alta velocidad/Baja Velocidad |
Yo_Robot | 18:cf1e07d82630 | 46 | DigitalIn isPC ( p17 ); // Salida a compuador o MAX232 |
Yo_Robot | 18:cf1e07d82630 | 47 | |
Yo_Robot | 19:c26cf8a48986 | 48 | DigitalOut led_verde( p21 ); // Led verde del conector Ethernet |
Yo_Robot | 19:c26cf8a48986 | 49 | DigitalOut led_rojo( p22 ); // Led naranja del conector Ethernet |
Yo_Robot | 19:c26cf8a48986 | 50 | |
Yo_Robot | 30:413d1a6648b5 | 51 | // Alarmas en los optoacopladores |
Yo_Robot | 30:413d1a6648b5 | 52 | InterruptIn limite_1( p23 ); |
Yo_Robot | 31:7e2cdd547cb2 | 53 | InterruptIn limite_2( p24 ); |
Yo_Robot | 31:7e2cdd547cb2 | 54 | InterruptIn limite_3( p25 ); |
Yo_Robot | 30:413d1a6648b5 | 55 | InterruptIn limite_4( p29 ); |
Yo_Robot | 30:413d1a6648b5 | 56 | |
Yo_Robot | 30:413d1a6648b5 | 57 | |
Yo_Robot | 20:4b154134ab20 | 58 | // Objetos Ethernet |
Yo_Robot | 18:cf1e07d82630 | 59 | |
Yo_Robot | 18:cf1e07d82630 | 60 | EthernetNetIf eth; |
Yo_Robot | 18:cf1e07d82630 | 61 | HTTPServer svr; |
Yo_Robot | 17:a4f380bc2516 | 62 | LocalFileSystem fs("local"); |
Yo_Robot | 5:c5aea1eb10bb | 63 | |
Yo_Robot | 8:958dfe5052b9 | 64 | |
Yo_Robot | 20:4b154134ab20 | 65 | // Anadir funciones al Protocolo RPC: |
Yo_Robot | 20:4b154134ab20 | 66 | // |
Yo_Robot | 20:4b154134ab20 | 67 | // estas son las funciones de acceso de la libreria HTTP_ASM sobre |
Yo_Robot | 20:4b154134ab20 | 68 | // el Protocolo RPC |
Yo_Robot | 12:c02b08dacc45 | 69 | RPCFunction SetFQ (&setPTO_eth, "PTO"); |
Yo_Robot | 12:c02b08dacc45 | 70 | RPCFunction SetAOUT(&setAout_eth, "AOUT"); |
Yo_Robot | 12:c02b08dacc45 | 71 | RPCFunction SetDIR (&setDir_eth, "DIR"); |
Yo_Robot | 12:c02b08dacc45 | 72 | RPCFunction SetSON (&setSON_eth, "SON"); |
Yo_Robot | 16:d50665706f21 | 73 | RPCFunction SetANG (&setANG_eth, "ANG"); |
Yo_Robot | 16:d50665706f21 | 74 | RPCFunction SetSpd (&setSPD_eth, "VAN"); |
Yo_Robot | 22:d5431fff164b | 75 | RPCFunction ReadEnc(&getENC_eth, "ENC"); |
Yo_Robot | 22:d5431fff164b | 76 | RPCFunction ClrEnc (&setENC_eth, "CLR"); |
Yo_Robot | 23:2126e38bb48c | 77 | RPCFunction ReadRPM(&getRPM_eth, "RPM"); |
Yo_Robot | 32:4483d6c225e5 | 78 | RPCFunction GoHome(&setHOME_eth, "INI"); |
Yo_Robot | 34:bdf918bc9b59 | 79 | RPCFunction GetAlm( &getALM_eth, "ALM"); |
Yo_Robot | 3:8d5a9e3cd680 | 80 | |
Yo_Robot | 30:413d1a6648b5 | 81 | |
Yo_Robot | 3:8d5a9e3cd680 | 82 | int main() { |
Yo_Robot | 30:413d1a6648b5 | 83 | |
Yo_Robot | 31:7e2cdd547cb2 | 84 | pin_alm.fall( &ISR_Alarm ); // Entrada de la alarma driver |
Yo_Robot | 31:7e2cdd547cb2 | 85 | |
Yo_Robot | 32:4483d6c225e5 | 86 | limite_1.rise( &ISR_Alm_encoder ); // Alarma de colisión 1 |
Yo_Robot | 32:4483d6c225e5 | 87 | limite_2.rise( &ISR_Adv_encoder ); // Alarma de colisión 1 |
Yo_Robot | 32:4483d6c225e5 | 88 | limite_3.rise( &ISR_Adv_motor ); // Alarma de colisión 1 |
Yo_Robot | 32:4483d6c225e5 | 89 | limite_4.rise( &ISR_Alm_motor ); // Alarma de colisión 1 |
Yo_Robot | 31:7e2cdd547cb2 | 90 | |
Yo_Robot | 31:7e2cdd547cb2 | 91 | encoder.SetDigiFilter(480UL); // number of clock cycles the signal must be at high to sense it |
Yo_Robot | 31:7e2cdd547cb2 | 92 | encoder.SetMaxPosition(0xFFFFFFFF); // max number before overflow - may be changed for 360 or a multiple |
Yo_Robot | 33:e6ff02c3e0f5 | 93 | encoder.SetVelocityTimerReload( 0xFFFFF ); |
Yo_Robot | 30:413d1a6648b5 | 94 | |
Yo_Robot | 30:413d1a6648b5 | 95 | |
Yo_Robot | 20:4b154134ab20 | 96 | //*************** Configura Red Ethernet **************************************************// |
Yo_Robot | 20:4b154134ab20 | 97 | if( isHTTP ) |
Yo_Robot | 13:649543aa8b1d | 98 | { |
Yo_Robot | 20:4b154134ab20 | 99 | |
Yo_Robot | 22:d5431fff164b | 100 | // Anade clases base al protocolo RPC |
Yo_Robot | 13:649543aa8b1d | 101 | Base::add_rpc_class<AnalogIn>(); |
Yo_Robot | 13:649543aa8b1d | 102 | Base::add_rpc_class<AnalogOut>(); |
Yo_Robot | 13:649543aa8b1d | 103 | Base::add_rpc_class<DigitalIn>(); |
Yo_Robot | 13:649543aa8b1d | 104 | Base::add_rpc_class<DigitalOut>(); |
Yo_Robot | 13:649543aa8b1d | 105 | Base::add_rpc_class<DigitalInOut>(); |
Yo_Robot | 13:649543aa8b1d | 106 | Base::add_rpc_class<PwmOut>(); |
Yo_Robot | 13:649543aa8b1d | 107 | Base::add_rpc_class<Timer>(); |
Yo_Robot | 13:649543aa8b1d | 108 | Base::add_rpc_class<BusOut>(); |
Yo_Robot | 13:649543aa8b1d | 109 | Base::add_rpc_class<BusIn>(); |
Yo_Robot | 13:649543aa8b1d | 110 | Base::add_rpc_class<BusInOut>(); |
Yo_Robot | 13:649543aa8b1d | 111 | Base::add_rpc_class<Serial>(); |
Yo_Robot | 17:a4f380bc2516 | 112 | |
Yo_Robot | 24:a1d16835201c | 113 | led_verde = 0; //Esperando configuracion |
Yo_Robot | 24:a1d16835201c | 114 | led_rojo = 1; |
Yo_Robot | 24:a1d16835201c | 115 | |
Yo_Robot | 22:d5431fff164b | 116 | // Configura conexion Ethernet |
Yo_Robot | 19:c26cf8a48986 | 117 | printf("Configurando...\n"); |
Yo_Robot | 18:cf1e07d82630 | 118 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 18:cf1e07d82630 | 119 | if(ethErr) |
Yo_Robot | 13:649543aa8b1d | 120 | { |
Yo_Robot | 21:353b0fe8fc54 | 121 | printf("Error %d en la configuracion.\n", ethErr); |
Yo_Robot | 24:a1d16835201c | 122 | led_rojo = 0; |
Yo_Robot | 18:cf1e07d82630 | 123 | return -1; |
Yo_Robot | 18:cf1e07d82630 | 124 | } |
Yo_Robot | 24:a1d16835201c | 125 | printf("Configuracion correcta!\n"); |
Yo_Robot | 24:a1d16835201c | 126 | |
Yo_Robot | 24:a1d16835201c | 127 | led_verde = 1; //Configuracion correcta led verde encendido |
Yo_Robot | 24:a1d16835201c | 128 | led_rojo = 0; |
Yo_Robot | 24:a1d16835201c | 129 | |
Yo_Robot | 18:cf1e07d82630 | 130 | FSHandler::mount("/local", "/files"); //Monta /local en /files que es el directorio web |
Yo_Robot | 18:cf1e07d82630 | 131 | FSHandler::mount("/local", "/"); //Mount /local en / que es el directorio raiz |
Yo_Robot | 13:649543aa8b1d | 132 | |
Yo_Robot | 18:cf1e07d82630 | 133 | //Handles para la comunicacion |
Yo_Robot | 13:649543aa8b1d | 134 | svr.addHandler<SimpleHandler>("/hello"); |
Yo_Robot | 13:649543aa8b1d | 135 | svr.addHandler<RPCHandler>("/rpc"); |
Yo_Robot | 13:649543aa8b1d | 136 | svr.addHandler<FSHandler>("/files"); |
Yo_Robot | 18:cf1e07d82630 | 137 | svr.addHandler<FSHandler>("/"); |
Yo_Robot | 18:cf1e07d82630 | 138 | |
Yo_Robot | 18:cf1e07d82630 | 139 | svr.bind(80); // Puerto de comunicacion. |
Yo_Robot | 18:cf1e07d82630 | 140 | |
Yo_Robot | 18:cf1e07d82630 | 141 | printf("Listo para comunicacion...\n"); |
Yo_Robot | 13:649543aa8b1d | 142 | |
Yo_Robot | 18:cf1e07d82630 | 143 | // Para probar la correcta configuracion acceder a mbed.htm |
Yo_Robot | 18:cf1e07d82630 | 144 | // http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
Yo_Robot | 18:cf1e07d82630 | 145 | |
Yo_Robot | 13:649543aa8b1d | 146 | } |
Yo_Robot | 20:4b154134ab20 | 147 | |
Yo_Robot | 20:4b154134ab20 | 148 | |
Yo_Robot | 20:4b154134ab20 | 149 | //*************** Configura Comunicacion Serial **************************************************// |
Yo_Robot | 15:a1ffa32ce9d1 | 150 | else // Caso Contrario Anadir modo Serial |
Yo_Robot | 8:958dfe5052b9 | 151 | { |
Yo_Robot | 22:d5431fff164b | 152 | int fast_baud = getBaud(); |
Yo_Robot | 20:4b154134ab20 | 153 | if( isPC ) // Utiliza el Puerto Virtual Incluido. |
Yo_Robot | 19:c26cf8a48986 | 154 | { |
Yo_Robot | 19:c26cf8a48986 | 155 | pc.attach( &ISR_Serial ); |
Yo_Robot | 20:4b154134ab20 | 156 | if( isFast ) //Configurar Serial a alta velocidad |
Yo_Robot | 21:353b0fe8fc54 | 157 | pc.baud( fast_baud ); |
Yo_Robot | 19:c26cf8a48986 | 158 | } |
Yo_Robot | 20:4b154134ab20 | 159 | else // Utiiliza el puerto serial hacia MAX232 |
Yo_Robot | 19:c26cf8a48986 | 160 | { |
Yo_Robot | 19:c26cf8a48986 | 161 | RS_232.attach( &ISR_Serial ); |
Yo_Robot | 20:4b154134ab20 | 162 | if( isFast ) //Configurar Serial a alta velocidad |
Yo_Robot | 21:353b0fe8fc54 | 163 | RS_232.baud( fast_baud ); |
Yo_Robot | 19:c26cf8a48986 | 164 | } |
Yo_Robot | 8:958dfe5052b9 | 165 | } |
Yo_Robot | 8:958dfe5052b9 | 166 | |
Yo_Robot | 20:4b154134ab20 | 167 | //*******************************************************************************************************// |
Yo_Robot | 20:4b154134ab20 | 168 | |
Yo_Robot | 20:4b154134ab20 | 169 | |
Yo_Robot | 24:a1d16835201c | 170 | //________ Ajustes iniciales del Driver _________// |
Yo_Robot | 24:a1d16835201c | 171 | |
Yo_Robot | 30:413d1a6648b5 | 172 | |
Yo_Robot | 30:413d1a6648b5 | 173 | |
Yo_Robot | 20:4b154134ab20 | 174 | setTimer2(); // Configurar PTO |
Yo_Robot | 20:4b154134ab20 | 175 | pin_son = 0; // Servo Apagado por defecto |
Yo_Robot | 13:649543aa8b1d | 176 | aout = 0.5; // Voltaje de salida 0V por defecto( +-10V! ) |
Yo_Robot | 33:e6ff02c3e0f5 | 177 | |
Yo_Robot | 30:413d1a6648b5 | 178 | |
Yo_Robot | 13:649543aa8b1d | 179 | while(1) |
Yo_Robot | 13:649543aa8b1d | 180 | { |
Yo_Robot | 13:649543aa8b1d | 181 | if( isHTTP ) |
Yo_Robot | 24:a1d16835201c | 182 | { |
Yo_Robot | 15:a1ffa32ce9d1 | 183 | Net::poll(); // Revisa la red solo si la coneccion es HTTP |
Yo_Robot | 24:a1d16835201c | 184 | led_verde = led_verde ^ 1; // Toggle Led Verde... esperando transmicion |
Yo_Robot | 24:a1d16835201c | 185 | } |
Yo_Robot | 13:649543aa8b1d | 186 | } |
Yo_Robot | 8:958dfe5052b9 | 187 | } |