当前位置: 首页>>代码示例>>Python>>正文


Python Robot.sense方法代码示例

本文整理汇总了Python中Robot.Robot.sense方法的典型用法代码示例。如果您正苦于以下问题:Python Robot.sense方法的具体用法?Python Robot.sense怎么用?Python Robot.sense使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Robot.Robot的用法示例。


在下文中一共展示了Robot.sense方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_ground_truth

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import sense [as 别名]
def generate_ground_truth(motions, landmarks, worldSize):

	myrobot = Robot({'landmarks':landmarks, 'worldSize':worldSize})
    	myrobot.set_noise({'bearing':bearing_noise, 'steering': steering_noise, 'distance': distance_noise})

    	Z = []
    	T = len(motions)

    	for t in range(T):
        	myrobot = myrobot.move(motions[t])
        	Z.append(myrobot.sense())
    	return [myrobot, Z]
开发者ID:Ranlot,项目名称:self-driving-robot,代码行数:14,代码来源:runRobot.py

示例2: __init__

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import sense [as 别名]
class Simulation:

	def __init__(self,propsfile):
		self.canvas = Tk()
		
		self.props = json.load(open(propsfile))
		self.worldMap = WorldMap(propsfile)
		
		self.wg = WorldGrid(self.canvas,self.props,self.worldMap)
		self.wg.registerCallBack(self.processEvent)
		
		self.robot = Robot(self.props,self.worldMap)
		self.robot.registerSenseCallBack(self.sense)
		self.robot.registerMoveCallBack(self.move)
		
		self.rRow = -1
		self.rCol = -1

		self.randomizeRobotPosition()
		self.robot.sense()
		self.shadeSquares()
		
	def randomizeRobotPosition(self):
		# randomly select the starting robot location --
		# do this until a valid square (i.e., not a wall) is 
		# selected
		found = False
		while (found == False):
			row = random.randint(0,self.worldMap.nRows-1)
			col = random.randint(0,self.worldMap.nCols-1)
			if(self.worldMap.isValidSquare(row,col)):
				found = True
				self.rRow = row
				self.rCol = col


	def move(self,dirc):
		
		row = self.rRow
		col = self.rCol
		if(dirc == 1):	# NORTH
			row -= 1
		elif(dirc == 2):   # EAST
			col += 1
		elif(dirc == 4):   # SOUTH
			row += 1
		elif(dirc == 8):	# WEST
			col -= 1
		else:
			print "ERROR: Invalid move direction"
		
		self.rRow = row
		self.rCol = col
		
	def sense(self):
		
		# NORTH
		meas = 0
		if(self.worldMap.isValidSquare(self.rRow-1,self.rCol)):
			meas = meas | 1
		
		# EAST
		if(self.worldMap.isValidSquare(self.rRow,self.rCol+1)):
			meas = meas | 2
			
		# SOUTH
		if(self.worldMap.isValidSquare(self.rRow+1,self.rCol)):
			meas = meas | 4
			
		# WEST
		if(self.worldMap.isValidSquare(self.rRow,self.rCol-1)):
			meas = meas | 8
		
		return meas
		
		
	def run(self):
		self.wg.draw()
		
		self.shadeSquares()
				
		self.wg.drawRobot(self.rRow,self.rCol)
		self.canvas.geometry(self.props["windowDimensions"])
		self.canvas.mainloop()

	def shadeSquares(self):
		probabilities = self.robot.mapProbabilities
		for i in range(0,len(probabilities)):
			for j in range(0,len(probabilities[i])):
				if(self.worldMap.isWall(i,j)==False):
					if(self.robot.mapProbabilities[i][j]>0):      
						# 0 is black, 255 is white
						c = 125 - math.floor(self.robot.mapProbabilities[i][j]*125.0)
						#c = 255 - int(self.robot.mapProbabilities[i][j]*255.0)
						cstr = "#%02x%02x%02x" % (0,c,0)
						self.wg.shadeSquare(i,j,cstr)
					else:
						cstr = "#%02x%02x%02x" % (255,255,255)
						self.wg.shadeSquare(i,j,cstr)
						
#.........这里部分代码省略.........
开发者ID:ankush92,项目名称:robot_localization_python,代码行数:103,代码来源:Simulation.py


注:本文中的Robot.Robot.sense方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。