class Scenario(object): def __init__(self): self._dao = DataAccess() self._robot = Factory.getRobot('UH Sunflower') self._thread1 = myThreadLights(1, "Thread-1", self._robot) self._thread2 = myThreadHead(2, "Thread-2", self._robot) def Scenario1(self): #self._thread1.start() time.sleep(25) self._dao.setResponse('fromDiningArea', None)
class Data(object): exposed = True def __init__(self): self._dao = DataAccess() def GET(self, *args, **kwargs): if len(args) < 1: raise cherrypy.HTTPError(400) questionNo = args[0] if questionNo == 'current': ques = self._dao.getActiveQuestion() if ques != None: questionNo = ques['sequenceName'] else: questionNo = None if questionNo != None: resp = self._dao.getResponses(questionNo) obj = {'query': questionNo, 'responses':resp} else: obj = {'query': 'none'} cherrypy.response.headers['Content-Type'] = 'application/json' return json.dumps(obj) def POST(self, *args, **kwargs): request = json.loads(cherrypy.request.body.read()) if not request.has_key('response'): raise cherrypy.HTTPError(400) else: userresponse = int(request['response']) if self._dao.setResponse(args[0], userresponse): return 'OK' else: raise cherrypy.HTTPError(500)
class Data(object): exposed = True def __init__(self): self._dao = DataAccess() def GET(self, *args, **kwargs): if len(args) < 1: raise cherrypy.HTTPError(400) questionNo = args[0] if questionNo == 'current': ques = self._dao.getActiveQuestion() if ques != None: questionNo = ques['sequenceName'] else: questionNo = None if questionNo != None: resp = self._dao.getResponses(questionNo) obj = {'query': questionNo, 'responses': resp} else: obj = {'query': 'none'} cherrypy.response.headers['Content-Type'] = 'application/json' return json.dumps(obj) def POST(self, *args, **kwargs): request = json.loads(cherrypy.request.body.read()) if not request.has_key('response'): raise cherrypy.HTTPError(400) else: userresponse = int(request['response']) if self._dao.setResponse(args[0], userresponse): return 'OK' else: raise cherrypy.HTTPError(500)
class Scenario(object): def __init__(self): self._dao = DataAccess() self._preferences = self._dao.users.getUserPreferences() self._robot = Factory.getCurrentRobot() self._threadLights = myThreadLights(1, "Thread-Lights", self._robot) self._threadHead = myThreadHead(2, "Thread-Head", self._robot) self._threadBase = myThreadBase(3, "Thread-BaseDirect", self._robot) self._threadTray = myThreadTray(4, "Thread-Tray", self._robot) def Scenario1(self, request, host): #Get the location selected by the user location = self._dao.locations.getLocationByName(request['location']) #Preferred LED colour self._robot.setComponentState('head', 'front') #Set default head position #Compose speech if request['scenario'] == 1 or request['scenario'] == 2: message = request['speech'].replace("User,", request['username'] + ",") else: message = request['speech'].replace("User, ", "") message = message.replace("<br/>", "") #Remove end of line if exists #If robot voice is activated if self._preferences[0]['voice'] == 1: #subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows #subprocess.call(['espeak', message]) #Linux subprocess.Popen( ["ssh", "%s" % host, "espeak -s 135 '%s'" % message], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Remote Linux #Open or close tray if 'lowered' == request['tray']: self._robot.setComponentState('tray', 'lowered') else: self._robot.setComponentState('tray', 'raised') time.sleep(1.5) self._threadLights.start() #Send the robot to the location #time.sleep(4) self._robot.setComponentState( 'base', [location['xCoord'], location['yCoord'], location['orientation']]) if 'KitchenDrink' == request['scenarioType']: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) self._threadBase.start() self._dao.setResponse('goKitchen', None) elif 'TransportDrink' == request['scenarioType']: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) self._threadHead.start() self._dao.setResponse('transportDrink', None) elif 'LivingDrink' == request['scenarioType']: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) self._threadBase.start() self._dao.setResponse('goLivingRoom', None) elif 'TransportObject' == request['scenarioType']: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) self._threadBase.start() self._dao.setResponse('transportObject', None) elif 'DoorbellGoToHall' == request['scenarioType']: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) self._threadBase.start() self._dao.setResponse('doorbellAssistance', None) else: self._threadLights.stopLights(eval(self._preferences[0]['light'])) self._robot.setComponentState('tray', 'raised') self._robot.setComponentState('head', 'back') #Set head position def Scenario2(self, request, host): #Get the location selected by the user location = self._dao.locations.getLocationByName(request['location']) #Preferred LED colour self._threadLights.start() self._robot.setComponentState('head', 'front') #Set default head position #Open or close tray if 'lowered' == request['tray']: self._robot.setComponentState('tray', 'lowered') else: self._robot.setComponentState('tray', 'raised') time.sleep(1) self._threadLights.arrivedPlace(eval(self._preferences[0]['light'])) self._threadBase.start() self._dao.setResponse('fromDiningArea', None) def Scenario3(self, request, host): #Get the location selected by the user location = self._dao.locations.getLocationByName(request['location']) self._robot.setComponentState('head', 'front') #Set default head position #Compose speech if request['scenario'] == 1 or request['scenario'] == 2: message = request['speech'].replace("User,", request['username'] + ",") else: message = request['speech'].replace("User, ", "") message = message.replace("<br/>", "") #Remove end of line if exists #If robot voice is activated if self._preferences[0]['voice'] == 1: #subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows #subprocess.call(['espeak', message]) #Linux subprocess.Popen( ["ssh", "%s" % host, "espeak -s 135 '%s'" % message], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Remote Linux #Open or close tray if 'lowered' == request['tray']: self._robot.setComponentState('tray', 'lowered') else: self._robot.setComponentState('tray', 'raised') time.sleep(1.5) #Send the robot to the location self._threadLights.start() #time.sleep(4) self._robot.setComponentState( 'base', [location['xCoord'], location['yCoord'], location['orientation']]) self._threadLights.stopLights(eval(self._preferences[0]['light'])) if 'KitchenDrink' == request['scenarioType']: self._dao.setResponse('goKitchen', None) elif 'TransportDrink' == request['scenarioType']: self._dao.setResponse('transportDrink', None) elif 'LivingDrink' == request['scenarioType']: self._dao.setResponse('goLivingRoom', None) elif 'TransportObject' == request[ 'scenarioType'] or 'DoorbellGoToHall' == request[ 'scenarioType']: self._dao.setResponse('transportObject', None) elif 'DoorbellGoToHall' == request['scenarioType']: self._dao.setResponse('transportObject', None) else: self._robot.setComponentState('tray', 'raised') self._robot.setComponentState('head', 'back') #Set head position def ScenarioDoorbell1(self, request, host): #Get the location selected by the user location = self._dao.locations.getLocationByName(request['location']) self._robot.setComponentState('head', 'front') self._threadLights.start() #Open or close tray if 'lowered' == request['tray']: self._robot.setComponentState('tray', 'lowered') else: self._robot.setComponentState('tray', 'raised') #Send the robot to the location (if it is not there already) #time.sleep(4) if request['scenario'] == 1: livingRoomLoc = self._dao.locations.getLocationByName( 'Living Room Sofa Area') self._robot.setComponentState('base', [ livingRoomLoc['xCoord'], livingRoomLoc['yCoord'], livingRoomLoc['orientation'] ]) else: livingRoomSocialLoc = self._dao.locations.getLocationByName( 'Living Room Sofa Area Social') self._robot.setComponentState('base', [ livingRoomSocialLoc['xCoord'], livingRoomSocialLoc['yCoord'], livingRoomSocialLoc['orientation'] ]) if request['scenario'] == 1: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) #Set base movement (expressive behaviour) self._robot.setComponentState('head', 'up') self._robot.setComponentState('base_direct', [0.2, 0.0]) self._robot.setComponentState('head', 'up_look_left') self._robot.setComponentState('base_direct', [-0.4, 0.0]) self._robot.setComponentState('head', 'up_look_right') self._robot.setComponentState('base_direct', [0.3, 0.0]) self._robot.setComponentState('head', 'up_look_left') self._robot.setComponentState('base_direct', [-0.2, 0.0]) self._robot.setComponentState('head', 'up_look_right') self._robot.setComponentState('base_direct', [0.075, 0.0]) self._robot.setComponentState('head', 'up') time.sleep(0.5) self._robot.setComponentState('head', 'front') else: self._threadLights.stopLights(eval(self._preferences[0]['light'])) #Compose speech if request['scenario'] == 1 or request['scenario'] == 2: message = request['speech'].replace("User,", request['username'] + ",") else: message = request['speech'].replace("User, ", "") message = message.replace("<br/>", "") #Remove end of line if exists #If robot voice is activated if self._preferences[0]['voice'] == 1: #subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows #subprocess.call(['espeak', message]) #Linux subprocess.Popen( ["ssh", "%s" % host, "espeak -s 135 '%s'" % message], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Remote Linux if request['scenario'] == 1: self._robot.setComponentState('head', 'front_bend_left') time.sleep(0.150) self._robot.setComponentState('head', 'front_bend_right') time.sleep(0.150) self._robot.setComponentState('head', 'front') else: time.sleep(1) ## Determine the speech time wait = 0.4 * (len(message.split()) - 1) time.sleep(wait) #Send the robot to the location time.sleep(1) self._threadLights.start() #time.sleep(4) self._robot.setComponentState( 'base', [location['xCoord'], location['yCoord'], location['orientation']]) #Stop blinking lights and tell user about help to transport if request['scenario'] == 1 or request['scenario'] == 2: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) self._threadBase.start() else: self._threadLights.stopLights(eval(self._preferences[0]['light'])) self._dao.setResponse('doorbellAssistance', None) def ScenarioDoorbell2(self, request, host): #Get the location selected by the user location = self._dao.locations.getLocationByName(request['location']) self._robot.setComponentState('head', 'front') self._threadLights.start() #Open or close tray if 'lowered' == request['tray']: self._robot.setComponentState('tray', 'lowered') else: self._robot.setComponentState('tray', 'raised') livingRoomSocialLoc = self._dao.locations.getLocationByName( 'Living Room Sofa Area Social') self._robot.setComponentState('base', [ livingRoomSocialLoc['xCoord'], livingRoomSocialLoc['yCoord'], livingRoomSocialLoc['orientation'] ]) self._threadLights.arrivedPlace(eval(self._preferences[0]['light'])) #Set base movement (expressive behaviour) self._robot.setComponentState('head', 'up') self._robot.setComponentState('base_direct', [0.2, 0.0]) self._robot.setComponentState('head', 'up_look_left') self._robot.setComponentState('base_direct', [-0.4, 0.0]) self._robot.setComponentState('head', 'up_look_right') self._robot.setComponentState('base_direct', [0.3, 0.0]) self._robot.setComponentState('head', 'up_look_left') self._robot.setComponentState('base_direct', [-0.2, 0.0]) self._robot.setComponentState('head', 'up_look_right') self._robot.setComponentState('base_direct', [0.075, 0.0]) self._robot.setComponentState('head', 'up') time.sleep(0.5) self._robot.setComponentState('head', 'front') #Wait until the tray finishes time.sleep(1.5) self._dao.setResponse('doorbellAssistLowPro', None)
class RobotCommands(object): exposed = True def __init__(self): self._dao = DataAccess() self._scenarios = Scenario() self._host = "nathan@sf1-1-pc1" self._robot = Factory.getCurrentRobot() def POST(self, *args, **kwargs): request = json.loads(cherrypy.request.body.read()) # Send the robot to certain location (The behaviour depends on the scenario) if request.has_key('location'): if request['scenario'] == 1: if request['scenarioType'] == 'HallDoorbell': self._scenarios.ScenarioDoorbell1(request, self._host) else: self._scenarios.Scenario1(request, self._host) elif request['scenario'] == 2: if request['scenarioType'] == 'HallDoorbell': self._scenarios.ScenarioDoorbell2(request, self._host) elif request['scenarioType'] == 'LivingDrink': self._scenarios.Scenario2(request, self._host) else: self._scenarios.Scenario1(request, self._host) elif request['scenario'] == 3: if request['scenarioType'] == 'HallDoorbell': self._scenarios.ScenarioDoorbell1(request, self._host) else: self._scenarios.Scenario3(request, self._host) # Send voice command to the robot (espeak software required) elif request.has_key( 'speech') and self._dao.getActiveQuestion()['repeated'] == 0: #Block other interfaces to repeat the message self._dao.setResponse(request['messageId'], None, 1) self._preferences = self._dao.users.getUserPreferences() if request['scenario'] == 3 or request[ 'messageId'] == 'doorbellAssistLowPro': time.sleep(0.5) #Including delay to help transition elif request['scenario'] == 1 or request['scenario'] == 2: time.sleep(7) #Time to wait for the body movement to finish if self._preferences[0]['voice'] == 1: self._robot.setComponentState('head', 'front') #Compose speech if request['scenario'] == 1 or request['scenario'] == 2: message = request['speech'].replace( "User,", request['username'] + ",") else: message = request['speech'].replace("User, ", "") message = message.replace("<br/>", "") #Remove end of line if exists #subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows #subprocess.call(['espeak', message]) #Linux subprocess.Popen( ["ssh", "%s" % self._host, "espeak -s 135 '%s'" % message], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Remote Linux if request['scenario'] == 1 or request['scenario'] == 2: self._robot.setComponentState('head', 'front_bend_left') time.sleep(0.150) self._robot.setComponentState('head', 'front_bend_right') time.sleep(0.150) self._robot.setComponentState('head', 'front') else: time.sleep(1) ## Determine the speech time wait = 0.3 * (len(message.split()) - 1) time.sleep(wait) #It means the robot has already spoken and the dialog can be shown self._dao.setResponse(request['messageId'], None, 2) # Open Tray if self._robot.getComponentState('tray')[0] == 'lowered': self._robot.setComponentState('tray', 'raised') #Finish Action self._robot.setComponentState('head', 'back') self._robot.setLight(eval(self._preferences[0]['light'])) # Open Tray (Sometimes the first attempt is failing) if self._robot.getComponentState('tray')[0] != 'raised': self._robot.setComponentState('tray', 'raised') else: raise cherrypy.HTTPError(400)
class Scenario(object): def __init__(self): self._dao = DataAccess() self._preferences = self._dao.users.getUserPreferences() self._robot = Factory.getCurrentRobot() self._threadLights = myThreadLights(1, "Thread-Lights", self._robot) self._threadHead = myThreadHead(2, "Thread-Head", self._robot) self._threadBase = myThreadBase(3, "Thread-BaseDirect", self._robot) self._threadTray = myThreadTray(4, "Thread-Tray", self._robot) def Scenario1(self, request, host): #Get the location selected by the user location = self._dao.locations.getLocationByName(request['location']) #Preferred LED colour self._robot.setComponentState('head', 'front') #Set default head position #If robot voice is activated if self._dao.users.getUserPreferences()[0]['voice'] == 1: #subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows #subprocess.call(['espeak', request['speech']]) #Linux subprocess.Popen( ["ssh", "%s" % host, "espeak -s 135 '%s'" % request['speech']], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Remote Linux #time.sleep(1.5) #Open or close tray if 'lowered' == request['tray']: self._robot.setComponentState('tray', 'lowered') else: self._robot.setComponentState('tray', 'raised') time.sleep(1.5) self._threadLights.start() #Send the robot to the location #time.sleep(4) self._robot.setComponentState( 'base', [location['xCoord'], location['yCoord'], location['orientation']]) if "Kitchen Entrance" in request['location']: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) self._threadBase.start() self._dao.setResponse('goKitchen', None) elif "Living" in request['location']: self._threadLights.arrivedPlace(eval( self._preferences[0]['light'])) if "Transporting" not in request['speech']: self._threadBase.start() self._dao.setResponse('goLivingRoom', None) else: self._threadHead.start() self._dao.setResponse('transportLivingRoom', None) else: self._threadLights.stopLights(eval(self._preferences[0]['light'])) self._robot.setComponentState('tray', 'raised') self._robot.setComponentState('head', 'back') #Set head position def Scenario3(self, request, host): #Get the location selected by the user location = self._dao.locations.getLocationByName(request['location']) self._robot.setComponentState('head', 'front') #Set default head position #If robot voice is activated if self._dao.users.getUserPreferences()[0]['voice'] == 1: #subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows #subprocess.call(['espeak', request['speech']]) #Linux subprocess.Popen( ["ssh", "%s" % host, "espeak -s 135 '%s'" % request['speech']], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Remote Linux #Open or close tray if 'lowered' == request['tray']: self._robot.setComponentState('tray', 'lowered') else: self._robot.setComponentState('tray', 'raised') time.sleep(1.5) #Send the robot to the location self._threadLights.start() #time.sleep(4) self._robot.setComponentState( 'base', [location['xCoord'], location['yCoord'], location['orientation']]) self._threadLights.stopLights(eval(self._preferences[0]['light'])) if "Kitchen Entrance" in request['location']: self._dao.setResponse('goKitchen', None) elif "Living" in request['location']: if "Transporting" not in request['speech']: self._dao.setResponse('goLivingRoom', None) else: self._dao.setResponse('transportLivingRoom', None) else: self._robot.setComponentState('tray', 'raised') self._robot.setComponentState('head', 'back') #Set head position def ScenarioDoorbell3(self, request, host): #Get the location selected by the user location = self._dao.locations.getLocationByName(request['location']) self._threadLights.start() time.sleep(2) self._robot.setComponentState('head', 'front') self._threadLights.arrivedPlace(eval(self._preferences[0]['light'])) #Set base movement (expressive behaviour) self._robot.setComponentState('head', 'up') self._robot.setComponentState('base_direct', [0.2, 0.0]) self._robot.setComponentState('head', 'up_look_left') self._robot.setComponentState('base_direct', [-0.4, 0.0]) self._robot.setComponentState('head', 'up_look_right') self._robot.setComponentState('base_direct', [0.3, 0.0]) self._robot.setComponentState('head', 'up_look_left') self._robot.setComponentState('base_direct', [-0.2, 0.0]) self._robot.setComponentState('head', 'up_look_right') self._robot.setComponentState('base_direct', [0.1, 0.0]) self._robot.setComponentState('head', 'up') time.sleep(0.5) self._robot.setComponentState('head', 'front') #Compose speech message = request['speech'].replace( "User", self._dao.users.getActiveUser()['firstName']) message = message.replace("<br/>", "") #Remove end of line if exists #If robot voice is activated if self._dao.users.getUserPreferences()[0]['voice'] == 1: #subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows #subprocess.call(['espeak', request['speech']]) #Linux subprocess.Popen( ["ssh", "%s" % host, "espeak -s 135 '%s'" % request['speech']], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Remote Linux self._robot.setComponentState('head', 'front_bend_left') time.sleep(0.150) self._robot.setComponentState('head', 'front_bend_right') time.sleep(0.150) self._robot.setComponentState('head', 'front') #Open or close tray if 'lowered' == request['tray']: self._robot.setComponentState('tray', 'lowered') else: self._robot.setComponentState('tray', 'raised') #Wait until the tray finishes time.sleep(1.5) #Send the robot to the location #time.sleep(4) self._threadLights.start() time.sleep(4) #self._robot.setComponentState('base', [location['xCoord'], location['yCoord'], location['orientation']]) #Stop blinking lights and tell user about help to transport self._threadLights.stopLights(eval(self._preferences[0]['light'])) self._dao.setResponse('doorbellAssistance', None)