Diferencia entre revisiones de «Grupo Bloque Enviar Butia Recibir Butia para Tortugarte»

De Proyecto Butiá
Saltar a: navegación, buscar
Línea 16: Línea 16:
 
Lo primero es realizar los bloques Recibir Butia y Enviar Butia que seran agregados a la paleta Butia.
 
Lo primero es realizar los bloques Recibir Butia y Enviar Butia que seran agregados a la paleta Butia.
 
Estos bloques modelaran una conexión vía socket utilizando UDP.  
 
Estos bloques modelaran una conexión vía socket utilizando UDP.  
El bloque Enviar Butia: este bloque modela el cliente en una conexión UDP. Tendrá el labor de conectarse a la IP de la XO que tenga el robot conectado y enviarle a la misma una mensage.
 
  
Codigo del Bloque y de su definición:
+
El bloque Enviar Butia: este bloque modela el cliente en una conexión UDP. Tendrá el labor de conectarse a la IP de la XO que tenga el robot conectado y enviarle a la misma una mensaje.
 +
 
 +
Código del Bloque:
  
 
  primitive_dictionary['EnviarButia'] = self.EnviarButia
 
  primitive_dictionary['EnviarButia'] = self.EnviarButia
Línea 26: Línea 27:
 
  default=[("127.0.0.1"), ""],   
 
  default=[("127.0.0.1"), ""],   
 
  prim_name='EnviarButia',  # code reference (see below)
 
  prim_name='EnviarButia',  # code reference (see below)
help_string=_('Conect Butia with a new xo and send a menssager'))
+
help_string=_('Conect Butia with a new xo and send a menssager'))
self.tw.lc.def_prim('EnviarButia', 2, lambda self, x, y: primitive_dictionary['EnviarButia'](x,y))
+
self.tw.lc.def_prim('EnviarButia', 2, lambda self, x, y: primitive_dictionary['EnviarButia'](x,y))
 +
 
 +
Definición del Bloque:
 +
 
 +
def EnviarButia(self, IP_SERVIDOR, message):
 +
        PUERTO_SERVIDOR = 2009
 +
        client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
 +
client.sendto(message, (IP_SERVIDOR, PUERTO_SERVIDOR))
 +
        client.close()
 +
 
 +
El bloque Recibir Butiá: este bloque modela el servidor en una conexión UDP. Tiene el cometido de esperar que un cliente le envíe datos y seleccionar que acción realizar de acuerdo al mensaje recibido.
 +
 
 +
Código del bloque:
 +
 
 +
primitive_dictionary['RecibirButia'] = self.RecibirButia
 +
palette.add_block('RecibirButia',  # the name of your block
 +
style='basic-style',  # the block style
 +
label=_('Recibir Butia'),  # the label for the block 
 +
prim_name='RecibirButia',  # code reference (see below)
 +
help_string=_('Ejecut the instruction that another xo send'))
 +
self.tw.lc.def_prim('RecibirButia', 0, lambda self: primitive_dictionary['RecibirButia']())
 +
 
 +
Definición del bloque:
 +
 
 +
def RecibirButia (self):
 +
 
 +
PUERTO = 2009
 +
BUFLEN = 512
 +
 +
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
 +
server.bind(('', PUERTO))
 +
bandera = True
 +
 
 +
while bandera:
 +
(message, address) = server.recvfrom(BUFLEN)
 +
        print 'Recibiendo paquete desde %s:%d' % (address[0], address[1])
 +
instruccion=message.split(':')
 +
if (instruccion[0] == 'adelante'):
 +
    self.forwardButia()
 +
if (instruccion[0] == 'adelanteDistancia'):
 +
    self.forwardDistance(int(instruccion[1]))
 +
if (instruccion[0] == 'esperar'):
 +
    self.delayButia(int(intruccion[1]))
 +
if (instruccion[0] == 'atras'):
 +
    self.backwardButia()
 +
if (instruccion[0] == 'atrasDistancia'):
 +
    self.backwardDistance(int(instruccion[1]))
 +
if (instruccion[0] == 'izquierda'):
 +
    self.leftButia()
 +
if (instruccion[0] == 'derecha'):
 +
    self.rightButia()
 +
if (instruccion[0] == 'girarXGrados'):
 +
    self.turnXdegree(int(instruccion[1]))
 +
if (instruccion[0] == 'parar'):
 +
    self.stopButia()
 +
if (instruccion[0] == 'boton'):
 +
    self.pushbuttonButia()
 +
if (instruccion[0] == 'bateria'):
 +
    self.batteryChargeButia()
 +
if (instruccion[0] == 'luzambiente'):
 +
    self.ambientlightButia(0)
 +
if (instruccion[0] == 'distancia'):
 +
    self.distanceButia(0)
 +
if (instruccion[0] == 'escaladegrises'):
 +
    self.grayscaleButia(0)
 +
if (instruccion[0] == 'temperatura'):
 +
    self.temperatureButia(0)
 +
if (instruccion[0] == 'vibracion'):
 +
    self.vibrationButia(0)
 +
if (instruccion[0] == 'inclinacion'):
 +
    self.tiltButia(0)
 +
if (instruccion[0] == 'induccionmagnetica'):
 +
    self.magneticinductionButia(0)
 +
if (instruccion[0] == 'displayLCD'):
 +
    self.LCDdisplayButia(instruccion[1])
 +
if (instruccion[0] == 'led'):
 +
    self.ledButia(int(instruccion[1]), 0)
 +
if (instruccion[0] == 'velocidad'):
 +
    self.speedButia(int(instruccion[1]))
 +
if (instruccion[0] == 'terminarConexion'):
 +
    bandera = False
 +
 
 +
Estas modificaciones se deben realizar sobre el archivo butia.py.
 +
Tener en cuenta que es necesario importar el modulo socket agregando junto al resto de las importaciones del archivo butia.py: import socket

Revisión del 12:54 28 feb 2012

Integrantes:

                 Alexandra Castelli

Tema elegido: Bloque Enviar_Butia Recibir_Butia para Tortugarte

Introducción:

Las experiencias dentro de los liceos o escuelas han mostrado que hay muchos niños y adolecentes interesados en experimentar con el robot Butiá. Unos de los problemas fue la escasez de recursos con los que se cuenta en el momento (hay solo un robot por escuela o liceo), lo que hacia muy difícil que todos los chicos interesados pudieran tener contacto con el mismo. El proyecto "Conectate a Butiá" tiene como cometido permitir el manejo de el robot Butiá no solo desde la XO conectada a èl sino también desde otras XO's y de esta forma disminuir el problema de la escasez de recursos. Este proyecto permitiría que más chicos puedan interactuar con el robot.


Desarrollo del Proyecto:

Modificaciones:

Lo primero es realizar los bloques Recibir Butia y Enviar Butia que seran agregados a la paleta Butia. Estos bloques modelaran una conexión vía socket utilizando UDP.

El bloque Enviar Butia: este bloque modela el cliente en una conexión UDP. Tendrá el labor de conectarse a la IP de la XO que tenga el robot conectado y enviarle a la misma una mensaje.

Código del Bloque:

primitive_dictionary['EnviarButia'] = self.EnviarButia
palette.add_block('EnviarButia',  # the name of your block
style='basic-style-2arg',  # the block style
label=_('Enviar Butia'),  # the label for the block
default=[("127.0.0.1"), ""],  
prim_name='EnviarButia',  # code reference (see below)
help_string=_('Conect Butia with a new xo and send a menssager'))
self.tw.lc.def_prim('EnviarButia', 2, lambda self, x, y: primitive_dictionary['EnviarButia'](x,y))

Definición del Bloque:

def EnviarButia(self, IP_SERVIDOR, message):
       PUERTO_SERVIDOR = 2009
       client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)

client.sendto(message, (IP_SERVIDOR, PUERTO_SERVIDOR))

       client.close()	

El bloque Recibir Butiá: este bloque modela el servidor en una conexión UDP. Tiene el cometido de esperar que un cliente le envíe datos y seleccionar que acción realizar de acuerdo al mensaje recibido.

Código del bloque:

primitive_dictionary['RecibirButia'] = self.RecibirButia palette.add_block('RecibirButia', # the name of your block style='basic-style', # the block style label=_('Recibir Butia'), # the label for the block prim_name='RecibirButia', # code reference (see below) help_string=_('Ejecut the instruction that another xo send')) self.tw.lc.def_prim('RecibirButia', 0, lambda self: primitive_dictionary['RecibirButia']())

Definición del bloque:

def RecibirButia (self):

PUERTO = 2009 BUFLEN = 512

server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) server.bind((, PUERTO))

	bandera = True

while bandera: (message, address) = server.recvfrom(BUFLEN) print 'Recibiendo paquete desde %s:%d' % (address[0], address[1]) instruccion=message.split(':') if (instruccion[0] == 'adelante'): self.forwardButia() if (instruccion[0] == 'adelanteDistancia'): self.forwardDistance(int(instruccion[1])) if (instruccion[0] == 'esperar'): self.delayButia(int(intruccion[1])) if (instruccion[0] == 'atras'): self.backwardButia() if (instruccion[0] == 'atrasDistancia'): self.backwardDistance(int(instruccion[1])) if (instruccion[0] == 'izquierda'): self.leftButia() if (instruccion[0] == 'derecha'): self.rightButia() if (instruccion[0] == 'girarXGrados'): self.turnXdegree(int(instruccion[1])) if (instruccion[0] == 'parar'): self.stopButia() if (instruccion[0] == 'boton'): self.pushbuttonButia() if (instruccion[0] == 'bateria'): self.batteryChargeButia() if (instruccion[0] == 'luzambiente'): self.ambientlightButia(0) if (instruccion[0] == 'distancia'): self.distanceButia(0) if (instruccion[0] == 'escaladegrises'): self.grayscaleButia(0) if (instruccion[0] == 'temperatura'): self.temperatureButia(0) if (instruccion[0] == 'vibracion'): self.vibrationButia(0) if (instruccion[0] == 'inclinacion'): self.tiltButia(0) if (instruccion[0] == 'induccionmagnetica'): self.magneticinductionButia(0) if (instruccion[0] == 'displayLCD'): self.LCDdisplayButia(instruccion[1]) if (instruccion[0] == 'led'): self.ledButia(int(instruccion[1]), 0) if (instruccion[0] == 'velocidad'): self.speedButia(int(instruccion[1])) if (instruccion[0] == 'terminarConexion'): bandera = False

Estas modificaciones se deben realizar sobre el archivo butia.py. Tener en cuenta que es necesario importar el modulo socket agregando junto al resto de las importaciones del archivo butia.py: import socket