Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>

Dependencies:   EthernetNetIf HTTPServer QEI_hw RPCInterface mbed

Committer:
Yo_Robot
Date:
Fri Jul 06 17:34:16 2012 +0000
Revision:
23:2126e38bb48c
Parent:
22:d5431fff164b
Child:
24:a1d16835201c
Version 2.0 Encoder listo -  faltan alarmas externas de proximidad

Who changed what in which revision?

UserRevisionLine numberNew 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 22:d5431fff164b 7 * Version: v2.2 *
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 3:8d5a9e3cd680 17 #include "setup.h"
Yo_Robot 8:958dfe5052b9 18 #include "EthernetNetIf.h"
Yo_Robot 8:958dfe5052b9 19 #include "HTTPServer.h"
Yo_Robot 8:958dfe5052b9 20 #include "RPCFunction.h"
Yo_Robot 8:958dfe5052b9 21 #include "RPCVariable.h"
Yo_Robot 20:4b154134ab20 22
Yo_Robot 23:2126e38bb48c 23 // Configuraci&#65533;n de Entradas / Salidas
Yo_Robot 9:6976ac1a430e 24
Yo_Robot 18:cf1e07d82630 25 Serial pc( USBTX, USBRX ); //Comunicacion Serial directa al computador
Yo_Robot 18:cf1e07d82630 26 Serial RS_232(p9, p10); //Comunicacion Serial para MAX232
Yo_Robot 22:d5431fff164b 27 I2C encoder(p28, p27, "i2c_mbed"); //Comunicacion I2C para los encoders
Yo_Robot 23:2126e38bb48c 28 Timer crono; // Reloj Interno de mbed
Yo_Robot 18:cf1e07d82630 29
Yo_Robot 18:cf1e07d82630 30 DigitalOut pin_son( p7 ); // SON
Yo_Robot 18:cf1e07d82630 31 DigitalOut pin_dir( p26 ); // SIGN+
Yo_Robot 18:cf1e07d82630 32 InterruptIn pin_alm( p8 ); // ALM
Yo_Robot 20:4b154134ab20 33 AnalogOut aout( p18 ); // VOUT
Yo_Robot 9:6976ac1a430e 34
Yo_Robot 16:d50665706f21 35 DigitalIn isHTTP( p15 ); // Modo Ethernet/Serial
Yo_Robot 16:d50665706f21 36 DigitalIn isFast( p16 ); // Serial Alta velocidad/Baja Velocidad
Yo_Robot 18:cf1e07d82630 37 DigitalIn isPC ( p17 ); // Salida a compuador o MAX232
Yo_Robot 18:cf1e07d82630 38
Yo_Robot 19:c26cf8a48986 39 DigitalOut led_verde( p21 ); // Led verde del conector Ethernet
Yo_Robot 19:c26cf8a48986 40 DigitalOut led_rojo( p22 ); // Led naranja del conector Ethernet
Yo_Robot 19:c26cf8a48986 41
Yo_Robot 20:4b154134ab20 42 // Objetos Ethernet
Yo_Robot 18:cf1e07d82630 43
Yo_Robot 18:cf1e07d82630 44 EthernetNetIf eth;
Yo_Robot 18:cf1e07d82630 45 HTTPServer svr;
Yo_Robot 17:a4f380bc2516 46 LocalFileSystem fs("local");
Yo_Robot 5:c5aea1eb10bb 47
Yo_Robot 8:958dfe5052b9 48
Yo_Robot 20:4b154134ab20 49 // Anadir funciones al Protocolo RPC:
Yo_Robot 20:4b154134ab20 50 //
Yo_Robot 20:4b154134ab20 51 // estas son las funciones de acceso de la libreria HTTP_ASM sobre
Yo_Robot 20:4b154134ab20 52 // el Protocolo RPC
Yo_Robot 12:c02b08dacc45 53 RPCFunction SetFQ (&setPTO_eth, "PTO");
Yo_Robot 12:c02b08dacc45 54 RPCFunction SetAOUT(&setAout_eth, "AOUT");
Yo_Robot 12:c02b08dacc45 55 RPCFunction SetDIR (&setDir_eth, "DIR");
Yo_Robot 12:c02b08dacc45 56 RPCFunction SetSON (&setSON_eth, "SON");
Yo_Robot 16:d50665706f21 57 RPCFunction SetANG (&setANG_eth, "ANG");
Yo_Robot 16:d50665706f21 58 RPCFunction SetSpd (&setSPD_eth, "VAN");
Yo_Robot 22:d5431fff164b 59 RPCFunction ReadEnc(&getENC_eth, "ENC");
Yo_Robot 22:d5431fff164b 60 RPCFunction ClrEnc (&setENC_eth, "CLR");
Yo_Robot 23:2126e38bb48c 61 RPCFunction ReadRPM(&getRPM_eth, "RPM");
Yo_Robot 8:958dfe5052b9 62
Yo_Robot 3:8d5a9e3cd680 63
Yo_Robot 3:8d5a9e3cd680 64 int main() {
Yo_Robot 20:4b154134ab20 65 //*************** Configura Red Ethernet **************************************************//
Yo_Robot 20:4b154134ab20 66 if( isHTTP )
Yo_Robot 13:649543aa8b1d 67 {
Yo_Robot 20:4b154134ab20 68
Yo_Robot 22:d5431fff164b 69 // Anade clases base al protocolo RPC
Yo_Robot 13:649543aa8b1d 70 Base::add_rpc_class<AnalogIn>();
Yo_Robot 13:649543aa8b1d 71 Base::add_rpc_class<AnalogOut>();
Yo_Robot 13:649543aa8b1d 72 Base::add_rpc_class<DigitalIn>();
Yo_Robot 13:649543aa8b1d 73 Base::add_rpc_class<DigitalOut>();
Yo_Robot 13:649543aa8b1d 74 Base::add_rpc_class<DigitalInOut>();
Yo_Robot 13:649543aa8b1d 75 Base::add_rpc_class<PwmOut>();
Yo_Robot 13:649543aa8b1d 76 Base::add_rpc_class<Timer>();
Yo_Robot 13:649543aa8b1d 77 Base::add_rpc_class<BusOut>();
Yo_Robot 13:649543aa8b1d 78 Base::add_rpc_class<BusIn>();
Yo_Robot 13:649543aa8b1d 79 Base::add_rpc_class<BusInOut>();
Yo_Robot 13:649543aa8b1d 80 Base::add_rpc_class<Serial>();
Yo_Robot 17:a4f380bc2516 81
Yo_Robot 22:d5431fff164b 82 // Configura conexion Ethernet
Yo_Robot 19:c26cf8a48986 83 printf("Configurando...\n");
Yo_Robot 18:cf1e07d82630 84 EthernetErr ethErr = eth.setup();
Yo_Robot 18:cf1e07d82630 85 if(ethErr)
Yo_Robot 13:649543aa8b1d 86 {
Yo_Robot 21:353b0fe8fc54 87 printf("Error %d en la configuracion.\n", ethErr);
Yo_Robot 18:cf1e07d82630 88 return -1;
Yo_Robot 18:cf1e07d82630 89 }
Yo_Robot 18:cf1e07d82630 90 printf("Setup OK\n");
Yo_Robot 18:cf1e07d82630 91
Yo_Robot 18:cf1e07d82630 92 FSHandler::mount("/local", "/files"); //Monta /local en /files que es el directorio web
Yo_Robot 18:cf1e07d82630 93 FSHandler::mount("/local", "/"); //Mount /local en / que es el directorio raiz
Yo_Robot 13:649543aa8b1d 94
Yo_Robot 18:cf1e07d82630 95 //Handles para la comunicacion
Yo_Robot 13:649543aa8b1d 96 svr.addHandler<SimpleHandler>("/hello");
Yo_Robot 13:649543aa8b1d 97 svr.addHandler<RPCHandler>("/rpc");
Yo_Robot 13:649543aa8b1d 98 svr.addHandler<FSHandler>("/files");
Yo_Robot 18:cf1e07d82630 99 svr.addHandler<FSHandler>("/");
Yo_Robot 18:cf1e07d82630 100
Yo_Robot 18:cf1e07d82630 101 svr.bind(80); // Puerto de comunicacion.
Yo_Robot 18:cf1e07d82630 102
Yo_Robot 18:cf1e07d82630 103 printf("Listo para comunicacion...\n");
Yo_Robot 13:649543aa8b1d 104
Yo_Robot 18:cf1e07d82630 105 // Para probar la correcta configuracion acceder a mbed.htm
Yo_Robot 18:cf1e07d82630 106 // http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
Yo_Robot 18:cf1e07d82630 107
Yo_Robot 13:649543aa8b1d 108 }
Yo_Robot 20:4b154134ab20 109
Yo_Robot 20:4b154134ab20 110
Yo_Robot 20:4b154134ab20 111 //*************** Configura Comunicacion Serial **************************************************//
Yo_Robot 15:a1ffa32ce9d1 112 else // Caso Contrario Anadir modo Serial
Yo_Robot 8:958dfe5052b9 113 {
Yo_Robot 22:d5431fff164b 114 int fast_baud = getBaud();
Yo_Robot 20:4b154134ab20 115 if( isPC ) // Utiliza el Puerto Virtual Incluido.
Yo_Robot 19:c26cf8a48986 116 {
Yo_Robot 19:c26cf8a48986 117 pc.attach( &ISR_Serial );
Yo_Robot 20:4b154134ab20 118 if( isFast ) //Configurar Serial a alta velocidad
Yo_Robot 21:353b0fe8fc54 119 pc.baud( fast_baud );
Yo_Robot 19:c26cf8a48986 120 }
Yo_Robot 20:4b154134ab20 121 else // Utiiliza el puerto serial hacia MAX232
Yo_Robot 19:c26cf8a48986 122 {
Yo_Robot 19:c26cf8a48986 123 RS_232.attach( &ISR_Serial );
Yo_Robot 20:4b154134ab20 124 if( isFast ) //Configurar Serial a alta velocidad
Yo_Robot 21:353b0fe8fc54 125 RS_232.baud( fast_baud );
Yo_Robot 19:c26cf8a48986 126 }
Yo_Robot 8:958dfe5052b9 127 }
Yo_Robot 8:958dfe5052b9 128
Yo_Robot 20:4b154134ab20 129 //*******************************************************************************************************//
Yo_Robot 20:4b154134ab20 130
Yo_Robot 20:4b154134ab20 131
Yo_Robot 17:a4f380bc2516 132 // Ajustes iniciales del Driver
Yo_Robot 20:4b154134ab20 133 setTimer2(); // Configurar PTO
Yo_Robot 20:4b154134ab20 134 pin_son = 0; // Servo Apagado por defecto
Yo_Robot 13:649543aa8b1d 135 aout = 0.5; // Voltaje de salida 0V por defecto( +-10V! )
Yo_Robot 8:958dfe5052b9 136
Yo_Robot 21:353b0fe8fc54 137
Yo_Robot 21:353b0fe8fc54 138 pin_alm.fall( &ISR_Alarm ); // Entrada de la alarma driver
Yo_Robot 14:039d070732d5 139
Yo_Robot 13:649543aa8b1d 140 while(1)
Yo_Robot 13:649543aa8b1d 141 {
Yo_Robot 13:649543aa8b1d 142 if( isHTTP )
Yo_Robot 15:a1ffa32ce9d1 143 Net::poll(); // Revisa la red solo si la coneccion es HTTP
Yo_Robot 13:649543aa8b1d 144 }
Yo_Robot 8:958dfe5052b9 145 }
Yo_Robot 8:958dfe5052b9 146