def __init__( self, **kwargs ): """ Corresponde al constructor de la clase. type port: string param port: la puerta a conectar con el S2 type bauds: integer param bauds: velocidad de la conexion type timeout: integer param timeout: timeout para cada comando """ self.mylock = threading.Lock() self.s2Inner = S2Inner( self ) self.s2IRSensors = S2IRSensors( self ) self.s2LEDs = S2LEDs( self ) self.s2LightSensors = S2LightSensors( self ) self.s2LineSensors = S2LineSensors( self ) self.s2Microphone = S2Microphone( self ) self.s2Motors = S2Motors( self ) self.s2Speaker = S2Speaker( self ) self.s2Path = S2Path( self ) #def __init__( self, port=None, bauds=9600, timeout=500, dtr=None ): if( len( kwargs ) != 0 ): self.conn = Serial( kwargs['port'], kwargs['bauds'], kwargs['timeout'] ) if( 'dtr' in kwargs ): self.conn.setDTR( kwargs['dtr'] ) Utils.pause( 2000 ) self.conn.ignoreInput( 1000 )
def __init__(self, port, speed, timeout): """ Corresponde al constructor de la clase. @type port: string @param port: la puerta a conectar con el S2 @type speed: integer @param speed: velocidad de la conexion @type timeout: integer @param timeout: timeout para cada comando """ self.mylock = threading.Lock() self.serial = Serial(port, speed, timeout) Utils.pause(1000) self.serial.flushRead(1000) self.s2Inner = S2Inner(self) self.s2IRSensors = S2IRSensors(self) self.s2LEDs = S2LEDs(self) self.s2LightSensors = S2LightSensors(self) self.s2LineSensors = S2LineSensors(self) self.s2Microphone = S2Microphone(self) self.s2Motors = S2Motors(self) self.s2Speaker = S2Speaker(self) self.s2Path = S2Path(self) self.f2Camera = F2Camera(self) self.f2Inner = F2Inner(self) self.f2IRSensors = F2IRSensors(self) self.f2LEDs = F2LEDs(self) self.f2Servos = F2Servos(self)
def main(): """Realiza las pruebas de los motores del S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2Motors = robot.getS2Motors() s2Motors.getMotorStats() s2Motors.getEncoders() s2Motors.getStall() s2Motors.setMotors() s2Motors.setMotorsOff() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) s2Motors = robot.getS2Motors() print("getMotorStats: " + str(s2Motors.getMotorStats())) print("getEncoders: " + str(s2Motors.getEncoders(1))) print("getStall: " + str(s2Motors.getStall())) print("setMotors 100, -100 : " + str(s2Motors.setMotors(100, -100))) Utils.pause(3000) print("setMotors -100, 100 : " + str(s2Motors.setMotors(-100, 100))) Utils.pause(3000) print("setMotorsOff: " + str(s2Motors.setMotorsOff())) robot.close()
def main(): """Realiza las pruebas de los motores del S2. Las pruebas consideran: #robot = Scribbler2( port="/dev/ttyUSB1", bauds=38400, timeout=500, dtr=False ) #robot = Fluke2( port="/dev/rfcomm2", bauds=9600, timeout=500 ) #robot = Net2( "192.168.145.1", 1500, 500 ) s2Motors = robot.getS2Motors() s2Motors.getMotorStats() s2Motors.getEncoders() s2Motors.getStall() s2Motors.setMotors() s2Motors.setMotorsOff() """ #robot = Scribbler2( port="/dev/ttyUSB1", bauds=38400, timeout=500, dtr=False ) robot = Fluke2( port="/dev/rfcomm2", bauds=9600, timeout=500 ) #robot = Net2( "192.168.145.1", 1500, 500 ) s2Motors = robot.getS2Motors() print( "getMotorStats: " + str( s2Motors.getMotorStats() ) ) print( "getEncoders: " + str( s2Motors.getEncoders( 1 ) ) ) print( "getStall: " + str( s2Motors.getStall() ) ) print( "setMotors 100, -100 : " + str( s2Motors.setMotors( 100, -100) ) ) Utils.pause( 3000 ) print( "setMotors -100, 100 : " + str( s2Motors.setMotors( -100, 100) ) ) Utils.pause( 3000 ) print( "setMotorsOff: " + str( s2Motors.setMotorsOff() ) ) robot.close()
def sendF2Command(self, packet, pause): """ Envia comando a la tarjeta F2. @type packet: bytearray @param packet: comando a enviar a la F2 @type pause: integer @param pause: pausa en ms a realizar una vez enviado el comando """ self.serial.write(packet) if (pause > 0): Utils.pause(pause)
def resetScribbler( self ): """Resetea el S2/F2.""" try: self.f2.lock() packet = bytearray( 1 ) packet[0] = 124 self.f2.sendF2Command( packet, 100 ) Utils.pause( 4000 ) except Exception as e: raise finally: self.f2.unlock()
def sendF2Command( self, packet, pause ): """ Envia comando a la tarjeta F2. @type packet: bytearray @param packet: comando a enviar a la F2 @type pause: integer @param pause: pausa en ms a realizar una vez enviado el comando """ self.conn.write( packet ) if( pause > 0 ): Utils.pause( pause )
def resetScribbler(self): """Resetea el S2.""" try: self.s2.lock() packet = bytearray(1) packet[0] = 124 self.s2.sendF2Command(packet, 100) Utils.pause(4000) except Exception as e: raise finally: self.s2.unlock()
def identifyRobot(self): """ Obtiene infromacion que identifica al S2. @rtype: string @return: identifiacion del S2 """ try: self.s2.lock() packet = bytearray(1) packet[0] = 156 self.s2.sendF2Command(packet, 100) id = self.s2.getLineResponse(128) Utils.pause(4000) return id except Exception as e: raise finally: self.s2.unlock()
def main(): """Realiza las pruebas de los motores servos de la tarjeta F2. Las pruebas consideran: robot = Fluke2( port="/dev/rfcomm2", bauds=9600, timeout=500 ) f2Servos = robot.getF2Servos() f2Servos.setServo() """ robot = Fluke2( port="/dev/rfcomm2", bauds=9600, timeout=500 ) f2Servos = robot.getF2Servos() id = 0; for value in range(0, 256, 5): print("setServo(%d, %d)" % (id, value)) f2Servos.setServo(id, value) Utils.pause(60) robot.close()
def identifyRobot( self ): """ Obtiene infromacion que identifica al S2/F2. @rtype: string @return: identifiacion del S2/F2 """ try: self.f2.lock() packet = bytearray( 1 ) packet[0] = 156 self.f2.sendF2Command( packet, 100 ) id = self.f2.getLineResponse( 128 ) Utils.pause( 4000 ) return id except Exception as e: raise finally: self.f2.unlock()
def main(): """Realiza las pruebas de los motores servos de la tarjeta F2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) f2Servos = robot.getF2Servos() f2Servos.setServo() """ robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) f2Servos = robot.getF2Servos() id = 0; for value in range(0, 256, 5): print("setServo(%d, %d)" % (id, value)) f2Servos.setServo(id, value) Utils.pause(60) robot.close()
def sendS2Command(self, packet, pause): """ Envia un comando al S2. @type packet: bytearray @param packet: comando a enviar @type pause: integer @param pause: tiempo en ms a esperar por la respuesta luego de enviar el comando @rtype: bool @return: Verdadero si el ACK enviado por el S2 corresponde al esperado """ self.serial.write(packet) if (pause > 0): Utils.pause(pause) if (packet[0] != 0x50): b = self.serial.read(self.PACKET_LENGTH) if (packet != b): Utils.debug("Packet Mismatch:") Utils.debug(packet) Utils.debug(b) return False return True
def sendS2Command( self, packet, pause ): """ Envia un comando al S2. @type packet: bytearray @param packet: comando a enviar @type pause: integer @param pause: tiempo en ms a esperar por la respuesta luego de enviar el comando @rtype: bool @return: Verdadero si el ACK enviado por el S2 corresponde al esperado """ self.conn.write( packet ) if( pause > 0 ): Utils.pause( pause ) if( packet[0] != 0x50 ): b = self.conn.read( self.PACKET_LENGTH ) if( packet != b ): Utils.debug( "Packet Mismatch:" ) Utils.debug( packet ) Utils.debug( b ) return False return True
def main(): """Realiza las pruebas de los LEDs de la tarjeta F2. Las pruebas consideran: robot = Fluke2( port="/dev/rfcomm2", bauds=9600, timeout=500 ) f2LEDs = robot.getF2LEDs() f2LEDs.setBrightLed() """ robot = Fluke2( port="/dev/rfcomm2", bauds=9600, timeout=500 ) f2LEDs = robot.getF2LEDs() print( "setBrightLed: " ) f2LEDs.setBrightLed( 255 ) Utils.pause( 2000 ) print( "setBrightLed: " ) f2LEDs.setBrightLed( 128 ) Utils.pause( 2000 ) print( "setBrightLed: " ) f2LEDs.setBrightLed( 0 ) robot.close()
def main(): """Realiza las pruebas del los LEDs del S2. Las pruebas consideran: #robot = Scribbler2( port="/dev/ttyUSB1", bauds=38400, timeout=500, dtr=False ) #robot = Fluke2( port="/dev/rfcomm2", bauds=9600, timeout=500 ) #robot = Net2( "192.168.145.1", 1500, 500 ) s2LEDs = robot.getS2LEDs() s2LEDs.setLeftLed() s2LEDs.setCenterLed() s2LEDs.setRightLed() s2LEDs.setAllLed() """ #robot = Scribbler2( port="/dev/ttyUSB1", bauds=38400, timeout=500, dtr=False ) robot = Fluke2( port="/dev/rfcomm2", bauds=9600, timeout=500 ) #robot = Net2( "192.168.145.1", 1500, 500 ) s2LEDs = robot.getS2LEDs() print( "setLeftLed: " + str( s2LEDs.setLeftLed( True ) ) ) Utils.pause( 2000 ) print( "setLeftLed: " + str( s2LEDs.setLeftLed( False ) ) ) Utils.pause( 2000 ) print( "setCenterLed: " + str( s2LEDs.setCenterLed( True ) ) ) Utils.pause( 2000 ) print( "setCenterLed: " + str( s2LEDs.setCenterLed( False ) ) ) Utils.pause( 2000 ) print( "setRightLed: " + str( s2LEDs.setRightLed( True ) ) ) Utils.pause( 2000 ) print( "setRightLed: " + str( s2LEDs.setRightLed( False ) ) ) Utils.pause( 2000 ) print( "setAllLed: " + str( s2LEDs.setAllLed( 1, 1, 1 ) ) ) Utils.pause( 2000 ) print( "setAllLed: " + str( s2LEDs.setAllLed( 0, 0, 0 ) ) ) Utils.pause( 2000 ) robot.close()
def main(): """Realiza las pruebas del los LEDs del S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2LEDs = robot.getS2LEDs() s2LEDs.setLeftLed() s2LEDs.setCenterLed() s2LEDs.setRightLed() s2LEDs.setAllLed() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) s2LEDs = robot.getS2LEDs() print("setLeftLed: " + str(s2LEDs.setLeftLed(True))) Utils.pause(2000) print("setLeftLed: " + str(s2LEDs.setLeftLed(False))) Utils.pause(2000) print("setCenterLed: " + str(s2LEDs.setCenterLed(True))) Utils.pause(2000) print("setCenterLed: " + str(s2LEDs.setCenterLed(False))) Utils.pause(2000) print("setRightLed: " + str(s2LEDs.setRightLed(True))) Utils.pause(2000) print("setRightLed: " + str(s2LEDs.setRightLed(False))) Utils.pause(2000) print("setAllLed: " + str(s2LEDs.setAllLed(1, 1, 1))) Utils.pause(2000) print("setAllLed: " + str(s2LEDs.setAllLed(0, 0, 0))) Utils.pause(2000) robot.close()