def numberGame(stop=100, maxGuesses=10): from myro import ask count = 1 secret = int(random.random() * 100) + 1 ok = False guess = 0 while not ok: try: guess = int( ask("Number", title="Try #%d: Guess a number between 1 and %d" % (count, stop))) ok = True except KeyboardInterrupt: raise except: ok = False while (guess != secret and count <= maxGuesses): if guess < secret: speak("On try number %d you guessed %d and that is too low." % (count, guess), async=1) else: speak("On try number %d you guessed %d and that is too high." % (count, guess), async=1) guess = 0 ok = False while not ok: try: guess = int( ask("Number", title="Try #%d: Guess a number between 1 and %d" % (count, stop))) ok = True except KeyboardInterrupt: raise except: ok = False count += 1 if count > maxGuesses: speak("Sorry, but you didn't guess it in %d tries. My number was %d." % (maxGuesses, secret), async=1) else: speak("You guessed my secret number in %d tries! It was %d." % (count, secret), async=1)
def numberGame(stop=100, maxGuesses=10): from myro import ask count = 1 secret = int(random.random() * 100) + 1 ok = False guess = 0 while not ok: try: guess = int(ask("Number", title = "Try #%d: Guess a number between 1 and %d" % (count, stop) )) ok = True except KeyboardInterrupt: raise except: ok = False while (guess != secret and count <= maxGuesses): if guess < secret: speak("On try number %d you guessed %d and that is too low." % (count, guess), async=1) else: speak("On try number %d you guessed %d and that is too high." % (count, guess), async=1) guess = 0 ok = False while not ok: try: guess = int(ask("Number", title = "Try #%d: Guess a number between 1 and %d" % (count, stop))) ok = True except KeyboardInterrupt: raise except: ok = False count += 1 if count > maxGuesses: speak("Sorry, but you didn't guess it in %d tries. My number was %d." % (maxGuesses, secret), async=1) else: speak("You guessed my secret number in %d tries! It was %d." % (count, secret), async=1)
def __init__(self, port = None, simulator = 0, rate = None, subtype = "Roomba"): # simulator = 0 makes it real PyroRobot.__init__(self) # robot constructor self.lock = threading.Lock() self.buffer = '' self.debug = 0 if simulator == 1: raise AttributeError, "simulator no longer supported" else: if subtype == "Roomba": if port == None: port = ask("Port", useCache = 1) if rate == None: rate = 57600 if type(port) == str and port.lower().startswith("com"): portnum = int(port[3:]) if portnum >= 10: port = r'\\.\COM%d' % (portnum) print "Roomba opening port '%s' with baudrate %s ..." % (port, rate) try: myro.globvars.robot.sc.close() except KeyboardInterrupt: raise except: pass self.sc = serial.Serial(port) #, xonxoff=0, rtscts=0) self.sc.setTimeout(0.5) self.sc.baudrate = rate self.sc.readlines() # to clear out the line self.lastTranslate = 0 self.lastRotate = 0 self.subtype = subtype self.radius = .16 #meters self._newline = "\r" self.type = "Roomba" self.port = port self.simulated = simulator self.sendMsg('\x80') #Start Sci self.sendMsg('\x82') #Give user control self.sendMsg('\x8E\x02') # reset sensors, useful for distance self.sensorData = {} # Holds all of the sensor data self.builtinDevices = ["ir", "bumper", "battery"] for name in self.builtinDevices: self.startDevice(name) self.update() print "Done loading Roomba."
def makeStory(story): from myro import ask # go through story, get "items" variables = re.findall('"(.*?)"', story) variables = list(set(variables)) variables.sort() variables = map(lambda v: "%s =" % v, variables) values = ask(variables, useDict=1, title = "For each variable below, fill in a value:") for variable in variables: value = values[variable] if value == "": value = '"%s"' % variable.replace(" =", "") variable = variable.replace(" =", "") story = story.replace('"%s"' % variable, value) return story
def makeStory(story): from myro import ask # go through story, get "items" variables = re.findall('"(.*?)"', story) variables = list(set(variables)) variables.sort() variables = map(lambda v: "%s =" % v, variables) values = ask(variables, useDict=1, title="For each variable below, fill in a value:") for variable in variables: value = values[variable] if value == "": value = '"%s"' % variable.replace(" =", "") variable = variable.replace(" =", "") story = story.replace('"%s"' % variable, value) return story
def __init__(self, serialport=None, baudrate=38400): from myro import ask if serialport == None: serialport = ask("Port", useCache=0) # Deal with requirement that Windows "COM#" names where # >= 9 needs to # be in the format "\\.\COM#" if type(serialport) == str and serialport.lower().startswith("com"): portnum = int(serialport[3:]) if portnum >= 10: serialport = r'\\.\COM%d' % (portnum) self.serialPort = serialport self.baudRate = baudrate try: myro.globvars.robot.ser.close() except KeyboardInterrupt: raise except: pass self.ser = myro.serial.Serial(self.serialPort, timeout = 2)
def __init__(self, serialport=None, baudrate=38400): from myro import ask self.robotinfo = {} if serialport == None: serialport = ask("Port", useCache=0) # Deal with requirement that Windows "COM#" names where # >= 9 needs to # be in the format "\\.\COM#" if type(serialport) == str and serialport.lower().startswith("com"): portnum = int(serialport[3:]) if portnum >= 10: serialport = r'\\.\COM%d' % (portnum) self.serialPort = serialport self.baudRate = baudrate try: myro.globvars.robot.ser.close() except KeyboardInterrupt: raise except: pass self.ser = serial.Serial(self.serialPort, timeout = 2)
def __init__(self, serialport = None, baudrate = 115200): Robot.__init__(self) self.debug = 0 self._lastTranslate = 0 self._lastRotate = 0 self._volume = 0 if serialport == None: serialport = ask("Port", useCache = 1) # Deal with requirement that Windows "COM#" names where # >= 9 needs to # be in the format "\\.\COM#" if type(serialport) == str and serialport.lower().startswith("com"): portnum = int(serialport[3:]) if portnum >= 10: serialport = r'\\.\COM%d' % (portnum) self.serialPort = serialport self.baudRate = baudrate self.window = None self.id = None self.name = "SRV-1" self.open() myro.globvars.robot = self
def __init__(self, serialport=None, baudrate=115200): Robot.__init__(self) self.debug = 0 self._lastTranslate = 0 self._lastRotate = 0 self._volume = 0 if serialport == None: serialport = ask("Port", useCache=1) # Deal with requirement that Windows "COM#" names where # >= 9 needs to # be in the format "\\.\COM#" if type(serialport) == str and serialport.lower().startswith("com"): portnum = int(serialport[3:]) if portnum >= 10: serialport = r'\\.\COM%d' % (portnum) self.serialPort = serialport self.baudRate = baudrate self.window = None self.id = None self.name = "SRV-1" self.open() myro.globvars.robot = self
def __init__(self, serialport=None, baudrate=38400): self.lock = threading.Lock() #### Camera Addresses #### self.CAM_PID = 0x0A self.CAM_PID_DEFAULT = 0x76 self.CAM_VER = 0x0B self.CAM_VER_DEFAULT = 0x48 self.CAM_BRT = 0x06 self.CAM_BRT_DEFAULT = 0x80 self.CAM_EXP = 0x10 self.CAM_EXP_DEFAULT = 0x41 self.CAM_COMA = 0x12 self.CAM_COMA_DEFAULT = 0x14 self.CAM_COMA_WHITE_BALANCE_ON = (self.CAM_COMA_DEFAULT | (1 << 2)) self.CAM_COMA_WHITE_BALANCE_OFF = (self.CAM_COMA_DEFAULT & ~(1 << 2)) self.CAM_COMB = 0x13 self.CAM_COMB_DEFAULT = 0xA3 self.CAM_COMB_GAIN_CONTROL_ON = (self.CAM_COMB_DEFAULT | (1 << 1)) self.CAM_COMB_GAIN_CONTROL_OFF = (self.CAM_COMB_DEFAULT & ~(1 << 1)) self.CAM_COMB_EXPOSURE_CONTROL_ON = (self.CAM_COMB_DEFAULT | (1 << 0)) self.CAM_COMB_EXPOSURE_CONTROL_OFF = (self.CAM_COMB_DEFAULT & ~(1 << 0)) self.ser = None self.requestStop = 0 self.debug = 0 self._lastTranslate = 0 self._lastRotate = 0 self._volume = 0 if serialport == None: serialport = ask("Port", useCache=1) # Deal with requirement that Windows "COM#" names where # >= 9 needs to # be in the format "\\.\COM#" hasPort = True if type(serialport) == str and serialport.lower().startswith("com"): portnum = int(serialport[3:]) elif isinstance(serialport, int): #allow integer input portnum = serialport else: hasPort = False if hasPort: if portnum >= 10: serialport = r'\\.\COM%d' % (portnum) self.serialPort = serialport self.baudRate = baudrate self.open() myro.globvars.robot = self self.dongle = None self.robotinfo = {} info = self.getVersion() if "fluke" in info.keys(): self.dongle = info["fluke"] print "You are using fluke firmware", info["fluke"] elif "dongle" in info.keys(): self.dongle = info["dongle"] print "You are using fluke firmware", info["dongle"] if self.dongle != None: # Turning on White Balance, Gain Control, and Exposure Control self.set_cam_param(self.CAM_COMA, self.CAM_COMA_WHITE_BALANCE_ON) self.set_cam_param( self.CAM_COMB, self.CAM_COMB_GAIN_CONTROL_ON | self.CAM_COMB_EXPOSURE_CONTROL_ON) # Config grayscale on window 0, 1, 2 conf_gray_window(self.ser, 0, 2, 0, 128, 191, 1, 1) conf_gray_window(self.ser, 1, 64, 0, 190, 191, 1, 1) conf_gray_window(self.ser, 2, 128, 0, 254, 191, 1, 1) set_ir_power(self.ser, 135) self.conf_rle(delay=90, smooth_thresh=4, y_low=0, y_high=255, u_low=51, u_high=136, v_low=190, v_high=255) self.robotinfo = {}
def __init__(self, serialport = None, baudrate = 38400): self.lock = threading.Lock() #### Camera Addresses #### self.CAM_PID=0x0A self.CAM_PID_DEFAULT=0x76 self.CAM_VER=0x0B self.CAM_VER_DEFAULT=0x48 self.CAM_BRT=0x06 self.CAM_BRT_DEFAULT=0x80 self.CAM_EXP=0x10 self.CAM_EXP_DEFAULT=0x41 self.CAM_COMA=0x12 self.CAM_COMA_DEFAULT=0x14 self.CAM_COMA_WHITE_BALANCE_ON= (self.CAM_COMA_DEFAULT | (1 << 2)) self.CAM_COMA_WHITE_BALANCE_OFF=(self.CAM_COMA_DEFAULT & ~(1 << 2)) self.CAM_COMB=0x13 self.CAM_COMB_DEFAULT=0xA3 self.CAM_COMB_GAIN_CONTROL_ON= (self.CAM_COMB_DEFAULT | (1 << 1)) self.CAM_COMB_GAIN_CONTROL_OFF=(self.CAM_COMB_DEFAULT & ~(1 << 1)) self.CAM_COMB_EXPOSURE_CONTROL_ON= (self.CAM_COMB_DEFAULT | (1 << 0)) self.CAM_COMB_EXPOSURE_CONTROL_OFF=(self.CAM_COMB_DEFAULT & ~(1 << 0)) self.ser = None self.requestStop = 0 self.debug = 0 self._lastTranslate = 0 self._lastRotate = 0 self._volume = 0 if serialport == None: serialport = ask("Port", useCache = 1) # Deal with requirement that Windows "COM#" names where # >= 9 needs to # be in the format "\\.\COM#" hasPort = True if type(serialport) == str and serialport.lower().startswith("com"): portnum = int(serialport[3:]) elif isinstance(serialport, int): #allow integer input portnum = serialport else: hasPort = False if hasPort: if portnum >= 10: serialport = r'\\.\COM%d' % (portnum) self.serialPort = serialport self.baudRate = baudrate self.open() myro.globvars.robot = self self.dongle = None self.robotinfo = {} info = self.getVersion() if "fluke" in info.keys(): self.dongle = info["fluke"] print "You are using fluke firmware", info["fluke"] elif "dongle" in info.keys(): self.dongle = info["dongle"] print "You are using fluke firmware", info["dongle"] if self.dongle != None: # Turning on White Balance, Gain Control, and Exposure Control self.set_cam_param(self.CAM_COMA, self.CAM_COMA_WHITE_BALANCE_ON) self.set_cam_param(self.CAM_COMB, self.CAM_COMB_GAIN_CONTROL_ON | self.CAM_COMB_EXPOSURE_CONTROL_ON) # Config grayscale on window 0, 1, 2 conf_gray_window(self.ser, 0, 2, 0, 128, 191, 1, 1) conf_gray_window(self.ser, 1, 64, 0, 190, 191, 1, 1) conf_gray_window(self.ser, 2, 128, 0, 254, 191, 1, 1) set_ir_power(self.ser, 135) self.conf_rle(delay = 90, smooth_thresh = 4, y_low=0, y_high=255, u_low=51, u_high=136, v_low=190, v_high=255) self.robotinfo = {}