def getConfigFileValue(config, section, option, title, valueList, saveToFile): # Check if option exists in the file if config.has_option(section, option): values = config.get(section, option) values = values.split(',') # Prompt the user to pick an option if the file specified more than one option if len(values) > 1: setting = robot.pickFromList(title, values) else: setting = values[0] else: setting = '' # Deal with blank or missing values by prompting user if not setting or not config.has_option(section, option): # Provide an empty text prompt if no list of values provided if not valueList: setting = robot.getInput(title).result # Let the user pick from a list of values else: setting = robot.pickFromList(title, valueList) if saveToFile: config.set(section, option, setting) with open(configFilePath, 'wb') as configfile: config.write(configfile) # Strip whitespace and try turning numbers into floats setting = setting.strip() try: setting = float(setting) except ValueError: pass return setting
def run(self): command = '' msg = '' global running global pauseSending while command != "Exit": try: command = robot.pickFromList( "Pick an action (set down phone to pause)", [ 'Say Hello', 'Point Using Compass', 'Take Picture', 'Speak Location', 'Voice Command', 'Exit' ]) # Pause sending commands so that robot only does what user selected here pauseSending = True if command == "Take Picture": commandOut("picture", True) droid.speak("Asking robot to take a picture") droid.makeToast("Please wait, this may take a few seconds") time.sleep(5) msg = "Picture should be taken by now" elif command == "Speak Location": msg = "Speaking location" commandOut("x", True) elif command == "Voice Command": try: voiceCommand = droid.recognizeSpeech().result commandOut(voiceCommand, True) msg = "Told the robot to " + voiceCommand droid.makeToast(msg) time.sleep(2) except: msg = "Could not understand" elif command == "Point Using Compass": direction = robot.pickFromList( "Pick a direction", ['North', 'East', 'West', 'South']) commandOut("p " + direction, True) msg = "Asking robot to point " + direction droid.speak(msg) time.sleep(10) msg = "Robot should be facing " + direction elif command == "Say Hello": msg = "Asking robot to say hello" commandOut("hi", True) elif command == "Exit": msg = "Bye bye. Come again." except KeyError: msg = "Sorry, please try that again" droid.speak(msg) time.sleep(1) # This resumes sending of normal accelerometer stream of commands pauseSending = False commandOut("w 0 0", True) # This will exit the main loop as well. Remove this if you only want to exit the pop-up menu. running = False
def run(self): command = '' msg = '' global running global pauseSending while command != "Exit": try: command = robot.pickFromList("Pick an action (set down phone to pause)", ['Say Hello', 'Point Using Compass', 'Take Picture','Speak Location','Voice Command','Exit']) # Pause sending commands so that robot only does what user selected here pauseSending = True if command == "Take Picture": commandOut("picture", True) droid.speak("Asking robot to take a picture") droid.makeToast("Please wait, this may take a few seconds") time.sleep(5) msg = "Picture should be taken by now" elif command == "Speak Location": msg = "Speaking location" commandOut("x", True) elif command == "Voice Command": try: voiceCommand = droid.recognizeSpeech().result commandOut(voiceCommand, True) msg = "Told the robot to " + voiceCommand droid.makeToast(msg) time.sleep(2) except: msg = "Could not understand" elif command == "Point Using Compass": direction = robot.pickFromList("Pick a direction", ['North','East','West','South']) commandOut("p " + direction, True) msg = "Asking robot to point " + direction droid.speak(msg) time.sleep(10) msg = "Robot should be facing " + direction elif command == "Say Hello": msg = "Asking robot to say hello" commandOut("hi", True) elif command == "Exit": msg = "Bye bye. Come again." except KeyError: msg = "Sorry, please try that again" droid.speak(msg) time.sleep(1) # This resumes sending of normal accelerometer stream of commands pauseSending = False commandOut("w 0 0", True) # This will exit the main loop as well. Remove this if you only want to exit the pop-up menu. running = False