本文整理汇总了Python中Data.dataAccess.DataAccess.getLocationByName方法的典型用法代码示例。如果您正苦于以下问题:Python DataAccess.getLocationByName方法的具体用法?Python DataAccess.getLocationByName怎么用?Python DataAccess.getLocationByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data.dataAccess.DataAccess
的用法示例。
在下文中一共展示了DataAccess.getLocationByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RobotCommands
# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import getLocationByName [as 别名]
class RobotCommands(object):
def __init__(self):
self._dao = DataAccess()
exposed = True
def POST(self, *args, **kwargs):
request = json.loads(cherrypy.request.body.read())
# Send the robot to certain location
if request.has_key('location'):
object = self._dao.getLocationByName(request['location']);
robot = Factory.getCurrentRobot();
robot.setComponentState('tray', request['tray'])
robot.setComponentState('base', [object['xCoord'], object['yCoord'], object['orientation']])
# Send voice command to the robot (espeak software required)
elif request.has_key('speech'):
if self._dao.getUserPreferences()[0]['voice'] == 1:
import subprocess
#subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows
subprocess.call(['espeak', request['speech']]); #Linux
else:
raise cherrypy.HTTPError(400)
示例2: LocationProcessor
# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import getLocationByName [as 别名]
class LocationProcessor(PollingProcessor):
"""Abstract location processor, current concrete implementations are Human and Robot processors"""
def __init__(self):
super(LocationProcessor, self).__init__()
self._dao = DataAccess()
self._storedLoc = lambda: {'locationName': '', 'xCoord': 0, 'yCoord': 0, 'orientation': 0, 'driftThreshold': 0 }
self._curLoc = lambda: ('', (0, 0, 0))
self._updateLoc = lambda locid, x, y, orientation: True
self._targetName = ''
def start(self):
print "Started polling location for %s" % (self._targetName)
self._addPollingProcessor('location', self.checkUpdateLocation, (self._curLoc, self._storedLoc, self._updateLoc), 2)
def stop(self):
print "Stopped polling location for %s" % (self._targetName)
self._removePollingProcessor('location')
def checkUpdateLocation(self, getCurrentLocation, getSavedLocation, updateLocation):
savedLoc = getSavedLocation()
(name, (x, y, orientation)) = getCurrentLocation()
if x == None or y == None:
return
update = False
if name != savedLoc['locationName']:
update = True
else:
dist = 0
dist += math.pow(x - savedLoc['xCoord'], 2)
dist += math.pow(y - savedLoc['yCoord'], 2)
dist = math.sqrt(dist)
if not savedLoc.has_key('driftThreshold') or dist > savedLoc['driftThreshold']:
update = True
else:
if abs(savedLoc['orientation'] - orientation) > 5:
update = True
if update:
loc = self._dao.getLocationByName(name)
if loc == None:
locid = None
else:
locid = loc['locationId']
print "Updating %(target)s location to Name:%(name)s, X:%(x)s, Y:%(y)s, O:%(orientation)s" % dict({'target':self._targetName}.items() + locals().items())
updateLocation(locid, x, y, orientation)