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()
def main(): """Realiza las pruebas de los elementos internos de la tarjeta F2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) f2Inner = robot.getF2Inner() f2Inner.getVersion() f2Inner.identifyRobot() f2Inner.getBattery() f2Inner.setForwardness() f2Inner.getErrors() f2Inner.resetScribbler() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) f2Inner = robot.getF2Inner() print("getVersion: " + str(f2Inner.getVersion())) print("identifyRobot: " + str(f2Inner.identifyRobot())) print("getBattery: " + str(f2Inner.getBattery())) print("setForwardness: ") f2Inner.setForwardness(f2Inner.SCRIBBLER_FORWARD) print("setForwardness: ") f2Inner.setForwardness(f2Inner.FLUKE_FORWARD) print("setForwardness: ") f2Inner.setForwardness(f2Inner.SCRIBBLER_FORWARD) print("getErrors: ") print(f2Inner.getErrors()) f2Inner.resetScribbler() robot.close()
def main(): """Realiza las pruebas de la camara de la tarjeta de la F2. Las pruebas utilizan las librerias numpy y opencv, y consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) f2Camera = robot.getF2Camera() f2Camera.setPicSize) f2Camera.getImage() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) f2Camera = robot.getF2Camera() cv2.namedWindow('Frames', cv2.WINDOW_AUTOSIZE) f2Camera.setPicSize(f2Camera.IMAGE_SMALL) for i in range(10): image = f2Camera.getImage(f2Camera.IMAGE_GRAYJPEG_FAST) print("Image:" + str(image)) img = cv2.imdecode(np.fromstring(str(image.image), np.uint8), cv2.IMREAD_ANYCOLOR) cv2.imshow('Frames', img) k = cv2.waitKey(5) cv2.destroyAllWindows() robot.close()
def main(): """Realiza las pruebas de movimiento en plano cartesiano del S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2Path = robot.getS2Path() s2Path.beginPath() s2Path.setPosn() s2Path.getPosn() s2Path.setAngle() s2Path.getAngle() s2Path.moveTo() s2Path.moveBy() s2Path.turnTo() s2Path.turnBy() s2Path.arcTo() s2Path.arcBy() s2Path.endPath() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) s2Path = robot.getS2Path() print("beginPath: " + str(s2Path.beginPath(15))) print("setPosn -100, -200: " + str(s2Path.setPosn(-100, -200))) print("getPosn: " + str(s2Path.getPosn())) print("setPosn 0, 0: " + str(s2Path.setPosn(0, 0))) print("getPosn: " + str(s2Path.getPosn())) print("setAngle -90: " + str(s2Path.setAngle(-90))) print("getAngle: " + str(s2Path.getAngle())) print("setAngle 90: " + str(s2Path.setAngle(90))) print("getAngle: " + str(s2Path.getAngle())) print("moveTo 0, 100: " + str(s2Path.moveTo(0, 100))) print("moveTo 0, -1000: " + str(s2Path.moveTo(0, -1000))) print("moveTo 0, 1000: " + str(s2Path.moveTo(0, 1000))) print("moveTo 0, 2000: " + str(s2Path.moveTo(0, 2000))) print("getPosn: " + str(s2Path.getPosn())) print("getAngle: " + str(s2Path.getAngle())) print("moveBy 0, 50: " + str(s2Path.moveBy(0, 50))) print("getPosn: " + str(s2Path.getPosn())) print("getAngle: " + str(s2Path.getAngle())) print("turnTo 45: " + str(s2Path.turnTo(45))) print("getPosn: " + str(s2Path.getPosn())) print("getAngle: " + str(s2Path.getAngle())) print("turnBy 45: " + str(s2Path.turnBy(45))) print("getPosn: " + str(s2Path.getPosn())) print("getAngle: " + str(s2Path.getAngle())) print("arcTo 100, 100, 45: " + str(s2Path.arcTo(100, 100, 45))) print("getPosn: " + str(s2Path.getPosn())) print("getAngle: " + str(s2Path.getAngle())) print("arcBy 100 : " + str(s2Path.arcBy(100, 100, 45))) print("getPosn: " + str(s2Path.getPosn())) print("getAngle: " + str(s2Path.getAngle())) print("endPath: " + str(s2Path.endPath())) robot.close()
def main(): """Demo de control del S2 utilizando un controlador MIDI.""" print("Creando puerta MIDI") midiIn = rtmidi.RtMidiIn() midiIn.openVirtualPort("S2 Control Port") print("Conectando con el Scribbler2") robot = Scribbler2("/dev/rfcomm2", 9600, 500) s2Motors = robot.getS2Motors() print("Conecte la puerta del Controlador Midi a la puerta virtual creada") while (True): cmd = None while (True): message = midiIn.getMessage() if (message == None): continue if (message.isNoteOn()): note = message.getNoteNumber() print(note) if (note == 48): s2Motors.setMotors(100, -100) elif (note == 52): s2Motors.setMotors(-100, 100) elif (note == 55): s2Motors.setMotors(100, 100) elif (note == 59): s2Motors.setMotors(-100, -100) elif (note == 83): s2Motors.setMotorsOff() midiIn.close() robot.close()
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(): global mqtt_client, MQTT_SERVER, messages print('[S2] Iniciando aplicación') mqtt_client = paho.Client('S2-' + uuid.uuid4().hex) mqtt_client.on_connect = mqtt_on_connect mqtt_client.on_message = mqtt_on_message mqtt_client.connect(MQTT_SERVER, 1883) mqtt_client.loop_start() s2 = None abort = False try: s2 = Scribbler2("/dev/rfcomm2", 9600, 500) sendToSpeak('Control de robot S2 iniciado') except Exception as e: sendToSpeak(' No existe puerto de comunicaciones con el robot') abort = True while (not abort): message = messages.get() print("[S2] Mensaje recibido:", message.payload) words = message.payload.split() cmd = words[0] if (cmd == 'exit'): abort = True elif (cmd == 'name'): sendToSpeak('El robot conectado es ' + s2.s2Inner.getName()) else: delay = 0 try: delay = float(words[1]) except Exception as e: print("[S2]", e) continue if (delay <= 0): continue elif (cmd == 'left'): s2.getS2Motors().setMotors(-100, 100) time.sleep(delay) s2.getS2Motors().setMotors(0, 0) elif (cmd == 'right'): s2.getS2Motors().setMotors(100, -100) time.sleep(delay) s2.getS2Motors().setMotors(0, 0) elif (cmd == 'forward'): s2.getS2Motors().setMotors(100, 100) time.sleep(delay) s2.getS2Motors().setMotors(0, 0) elif (cmd == 'backward'): s2.getS2Motors().setMotors(-100, -100) time.sleep(delay) s2.getS2Motors().setMotors(0, 0) sendToSpeak('Control de robot S2 finalizado') mqtt_client.loop_stop() print('[S2] Aplicación finalizada')
def main(): """Realiza pruebas del S2 recibiendo comandos via MQTT.""" global mqtt_client, MQTT_SERVER, messages, Queue mqtt_client = paho.Client() mqtt_client.on_connect = mqtt_on_connect mqtt_client.on_message = mqtt_on_message mqtt_client.connect(MQTT_SERVER, 1883) mqtt_client.loop_start() s2 = None abort = False try: s2 = Scribbler2("/dev/rfcomm2", 9600, 500) except Exception as e: print(e) abort = True while (not abort): message = messages.get() print("[S2] Mensaje recibido:", message.payload) words = message.payload.split() cmd = words[0] if (cmd == 'exit'): abort = True elif (cmd == 'name'): print(s2.s2Inner.getName()) else: delay = 0 try: delay = float(words[1]) except Exception as e: print("[S2]", e) continue if (delay <= 0): continue elif (cmd == 'left'): s2.getS2Motors().setMotors(-100, 100) time.sleep(delay) s2.getS2Motors().setMotors(0, 0) elif (cmd == 'right'): s2.getS2Motors().setMotors(100, -100) time.sleep(delay) s2.getS2Motors().setMotors(0, 0) elif (cmd == 'forward'): s2.getS2Motors().setMotors(100, 100) time.sleep(delay) s2.getS2Motors().setMotors(0, 0) elif (cmd == 'backward'): s2.getS2Motors().setMotors(-100, -100) time.sleep(delay) s2.getS2Motors().setMotors(0, 0) mqtt_client.loop_stop()
def OnConnect(self, *args): """Procesa el evento OnConnect del boton On/Off tipo switch.""" if(self.Connect.get_active()): self._SbSetMessage("Conectando...") try: self.rob = Scribbler2(self.Port.get_text(), 9600, 500) except Exception as e: self.Connect.set_active(False) self._SbSetMessage("Error al conectar con el Scribbler2") return self._StoreSensors( self.rob.getS2Inner().getAllSensors() ) self.MoveButtons.set_sensitive(True) self.Speed.set_sensitive(True) self.Port.set_sensitive(False) self._SbSetMessage("Conectado a %s - Mi nombre es '%s'" % (self.Port.get_text(), self.rob.getS2Inner().getName())) self.Info.set_label(self.rob.getS2Inner().getInfo()) self.Connect.set_label("Desconectar") # Inicia el hilo de los sensores self.TSensors = Thread(target=self._Sensors, args=()) self.TSensors.start() # Inicia el hilo del joystick pygame.init() if(pygame.joystick.get_count()>0): self.TJoystick = Thread(target=self._Joystick, args=()) self.TJoystick.start() else: if(self.rob!=None): self.rob.close() self.rob = None self.MoveButtons.set_sensitive(False) self.Speed.set_sensitive(False) self.Port.set_sensitive(True) self.Info.set_label("") self._SbSetMessage("Desconectado") self.Connect.set_label("Conectar") # Detiene el hilo de sensors if(self.TSensors!=None): self.TSensors.join() self.TSensors = None # Detiene el hilo del joystick if(self.TJoystick!=None): self.TJoystick.join() self.TJoystick = None pygame.quit() return
def main(): """Realiza las pruebas del microfono del S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2Microphone = robot.getS2Microphone() s2Microphone.getMicEnv() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) s2Microphone = robot.getS2Microphone() for i in range(50): print("getMicEnv: " + str(s2Microphone.getMicEnv())) robot.close()
def connect( port='rfcomm2' ): """Conecta al S2 que se encuentra en la puerta especificada.""" global s2 if( s2 != None ): try: print( 'S2 connect(): Cerrando conexion anterior' ) s2.close() except: pass try: print( 'S2 connect(): Estableciendo conexion con el S2 ... ', end='' ) s2 = Scribbler2( '/dev/' + port, 9600, 500 ) print( 'OK' ) except Exception as e: print( 'Exception' ) print( e ) finally: sys.stdout.flush()
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 main(): """Realiza las pruebas de los sensores infrarojos de la tarjeta F2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) f2IRSensors = robot.getF2IRSensors() f2IRSensors.setIRPower() f2IRSensors.getIR() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) f2IRSensors = robot.getF2IRSensors() print("setIRPower: ") f2IRSensors.setIRPower(255) for i in range(20): print("getIR: " + str(f2IRSensors.getIR())) robot.close()
def main(): """Realiza las pruebas de los sensores de luz del S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2LightSensors = robot.getS2LightSensors() s2LightSensors.getLeftLight() s2LightSensors.getCenterLight() s2LightSensors.getRightLed() s2LightSensors.getAllLights() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) s2LightSensors = robot.getS2LightSensors() for i in range(10): print("getLeftLight: " + str(s2LightSensors.getLeftLight())) print("getCenterLight: " + str(s2LightSensors.getCenterLight())) print("getRightLight: " + str(s2LightSensors.getRightLight())) print("getAllLights: " + str(s2LightSensors.getAllLights())) robot.close()
def main(): """Realiza las pruebas de los elementos internos del S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2Inner = robot.getS2Inner() s2Inner.getInfo() s2Inner.getAllSensors() s2Inner.setPass() s2Inner.getPass() s2Inner.setName() s2Inner.getName() s2Inner.getState() s2Inner.setData() s2Inner.setSingleData() """ robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2Inner = robot.getS2Inner() print( "getInfo: " + str( s2Inner.getInfo() ) ) print( "getAllSensors: " + str( s2Inner.getAllSensors() ) ) print( "setPass: "******"1234567898765432" ) ) ) print( "getPass: "******"setPass: "******"ABCDEFGHIHGFRDCB" ) ) ) print( "getPass: "******"setName: " + str( s2Inner.setName( "NAME1234" ) ) ) print( "getName: " + str( s2Inner.getName() ) ) print( "setName: " + str( s2Inner.setName( "LilyBot" ) ) ) print( "getName: " + str( s2Inner.getName() ) ) print( "getState: " + str( s2Inner.getState() ) ) print( "setData: " + str( s2Inner.setData( bytearray( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ) ) ) ) print( "getData: " + str( Utils.bytesToHex( s2Inner.getData() ) ) ) print( "setData: " + str( s2Inner.setData( bytearray( [ 8, 7, 6, 5, 4, 3, 2, 1 ] ) ) ) ) print( "getData: " + str( Utils.bytesToHex( s2Inner.getData() ) ) ) print( "setSingleData: " + str( s2Inner.setSingleData( 4, 44 ) ) ) print( "getData: " + str( Utils.bytesToHex( s2Inner.getData() ) ) ) robot.close()
def main(): """Realiza las pruebas de los sensores infrarojos del S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2IRSensors = robot.getS2IRSensors() s2IRSensors.getIRLeft() s2IRSensors.getIRRight() s2IRSensors.getAllIR() s2IRSensors.getIrEx() """ robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2IRSensors = robot.getS2IRSensors() for i in range( 10 ): print( "getIRLeft: " + str( s2IRSensors.getIRLeft() ) ) print( "getIRRight: " + str( s2IRSensors.getIRRight() ) ) print( "getAllIR: " + str( s2IRSensors.getAllIR() ) ) print( "getIrEx(0): " + str( s2IRSensors.getIrEx( 0, 128 ) ) ) print( "getIrEx(1): " + str( s2IRSensors.getIrEx( 1, 128 ) ) ) robot.close()
def main(): """Realiza pruebas de sonido soportados por el S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2Speaker = robot.getS2Speaker() s2Speaker.setQuiet() s2Speaker.setLoud() s2Speaker.setVolume() s2Speaker.setSpeaker() s2Speaker.setSpeaker() """ robot = Scribbler2("/dev/rfcomm2", 9600, 500) s2Speaker = robot.getS2Speaker() print("setQuiet: " + str(s2Speaker.setQuiet())) print("setLoud: " + str(s2Speaker.setLoud())) print("setVolume: " + str(s2Speaker.setVolume(50))) print("setSpeaker: " + str(s2Speaker.setSpeaker(2000, 440, 880))) print("setSpeaker: " + str(s2Speaker.setSpeaker(2000, 650, 0))) robot.close()
def main(): """Realiza las pruebas de los sensores de linea del S2. Las pruebas consideran: robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2LineSensors = robot.getS2LineSensors() s2LineSensors.getLineEx() s2LineSensors.getAllLines() s2LineSensors.getLeftLine() s2LineSensors.getRightLine() """ robot = Scribbler2( "/dev/rfcomm2", 9600, 500 ) s2LineSensors = robot.getS2LineSensors() for i in range( 10 ): print( "getLineEx 0: " + str( s2LineSensors.getLineEx( 0, 128 ) ) ) print( "getLineEx 1: " + str( s2LineSensors.getLineEx( 1, 128 ) ) ) print( "getAllLines: " + str( s2LineSensors.getAllLines() ) ) print( "getLeftLine: " + str( s2LineSensors.getLeftLine() ) ) print( "getRightLine: " + str( s2LineSensors.getRightLine() ) ) robot.close()
from rcr.robots.scribbler2.Scribbler2 import Scribbler2 robot = Scribbler2("/dev/rfcomm2", 9600, 500) snd = robot.getS2Speaker() snd.setLoud() snd.setVolume(100) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 370, 0) snd.setSpeaker(125, 330, 0) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 0, 0) snd.setSpeaker(500, 523, 0) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 370, 0) snd.setSpeaker(125, 330, 0) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 0, 0) snd.setSpeaker(500, 370, 0) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 370, 0) snd.setSpeaker(125, 330, 0) snd.setSpeaker(125, 440, 0) snd.setSpeaker(125, 587, 0) snd.setSpeaker(125, 622, 0) snd.setSpeaker(125, 659, 0) snd.setSpeaker(063, 622, 0) snd.setSpeaker(063, 659, 0) snd.setSpeaker(063, 622, 0) snd.setSpeaker(063, 659, 0)
import time import io from PIL import Image from rcr.robots.scribbler2.Scribbler2 import Scribbler2 robot = Scribbler2("COM3", 9600, 500) motors = robot.getS2Motors() cam = robot.getF2Camera() cam.setPicSize(cam.IMAGE_SMALL) motors.setMotors(30, -30) time.sleep(2) motors.setMotorsOff() data = cam.getImage(cam.IMAGE_GRAYJPEG_FAST) image = Image.open(io.BytesIO(data.image)) image.show() motors.setMotors(30, -30) time.sleep(2) motors.setMotorsOff() data = cam.getImage(cam.IMAGE_JPEG_FAST) image = Image.open(io.BytesIO(data.image)) image.show() robot.close()