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


Python Robot.move方法代码示例

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


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

示例1: generate_ground_truth

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import move [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: Robot

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import move [as 别名]
import random
import time

from maze import MAZES, WALLS, GOALS, BLANKS
from Navigation import DFS, BFS
from Robot import Robot

maze = random.choice(MAZES)
nav_system = random.choice([DFS, BFS])

robot = Robot(
    maze,
    BLANKS,
    WALLS,
    GOALS,
    initial_pos=(6, 1),
    Navigation=nav_system
)

robot.get_path()
while robot.navigation.has_next_move():
    robot.move()
    data = robot.print_current_pos()
    with open('data.txt', 'r+b') as f:
        f.write(data)
        f.write('using %s nav system' % nav_system.__name__)
    time.sleep(0.1)
开发者ID:ozmax,项目名称:raskolnikov,代码行数:29,代码来源:run_robot_sample.py

示例3: __init__

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import move [as 别名]
class Game:
    
    robot = None
    pelota = None
    porteria = None
    
    #inicializamos juego con pelota y 
    def __init__(self,dimension = [0,0]):#requiere dimension del campo
        rx = dimension[0]*random()#inicializamos posicion x
        ry = dimension[1]*random()#inicializamos posicion y
        self.robot = Robot(pos = [rx,ry])#posicion
        
        self.robot.setAngle(random()*360)#colocamos un angulo aleatorio
        
        px = dimension[0]*random()#posicion x pelota
        py = dimension[1]*random()#posicion y pelota
        self.pelota = Pelota(pos = [px,py])
        
        #colocamos la porteria a la derecha por defecto
        x = dimension[0]#porteria en la derecha
        yini = dimension[1]/2.0-dimension[1]/6.0#se coloca a un tercio de altura
        yfin = dimension[1]/2.0+dimension[1]/6.0#que llegue hasta dos tercios 
        self.porteria = Porteria(init=[x,yini],end=[x,yfin])
        
    
    def action(self):
        direction = self.robot.getAngle()#direction es angulo en el campo del robot
        posicion = self.robot.getVel()#hacia donde apunta 
        posicionP = self.pelota.getPos()-self.robot.getPos()#donde se encuentra la pelota relativo al robot
#        print distance
#        print direction        
        
        fr = Front()
        
#        print "robot: P."+str(self.robot.getPos())+" V."+str(posicion)
#        print "pelota:"+str(self.pelota.getPos())+" PR."+str(posicionP)

        angleb = angle(posicion,[posicionP[0],posicionP[1]])#calculo el angulo entre ellos
#        print "angulo entre ellos:"+str(angleb)
#        print "direction:"+str(direction)
        vectorp = norm(posicionP)*array([cos((direction+angleb)/180.0*pi),-sin((direction+angleb)/180.0*pi)])#supongo que el angulo se mide hacia la izquierda
        #vuelvo a calcular un vector supuesto que tenga la misma direccion
#        print "nuevo:"+str(vectorp)+" compar:"+str(posicionP)
        vectorp = vectorp-posicionP#calculo la diferencia de valores
        if norm(vectorp)>10:
            #quiere decir que esta medido a la derecha
            angleb = -angleb
        
        fr.setTR(fr.TR(angleb))
        fr.setST(fr.ST(angleb))
        fr.setTL(fr.TL(angleb))
        
#        i1 = []
#        for i in range(-90,90,5):
#            i1.append(fr.evalFunc(i))
#            
#        plot([i for i in range(-90,90,5)],i1)
#        show()
#        
#        
        
        val = integrate(lambda x:fr.evalFuncUp(x),-45,45)
        if val!=0:
            val = val/integrate(lambda x:fr.evalFunc(x),-45,45)
            

        print "Cambio de angulo:"+str(val)
        print "Angulo o:"+str(self.robot.getAngle())
        self.robot.addAngle(val)
        self.robot.move()
    
        print "Robot:"+str(self.robot.getPos())
        print "Pelota:"+str(self.pelota.getPos())
        
#        time.sleep(1)
        
    
    def play(self):
        self.action()
        return self.porteria.revisarAdentro(self.pelota.getPos())
        
    def inContact(self):
        return self.pelota.inContact(self.robot.getPos())
    
    def shot(self):
        direction = self.robot.getAngle()#direction es angulo en el campo del robot
        posicion = self.robot.getVel()#hacia donde apunta 
        posicionP = self.porteria.getMed()-self.robot.getPos()#donde se encuentra la pelota relativo al robot
        
        angleb = angle(posicion,[posicionP[0],posicionP[1]])#calculo el angulo entre ellos

        vectorp = norm(posicionP)*array([cos((direction+angleb)/180.0*pi),-sin((direction+angleb)/180.0*pi)])#supongo que el angulo se mide hacia la izquierda
        
        vectorp = vectorp-posicionP#calculo la diferencia de valores
        if norm(vectorp)>10:
            #quiere decir que esta medido a la derecha
            angleb = -angleb
            
        self.robot.addAngle(angleb+self.robot.shotError())
        self.pelota.setVel(3*self.robot.getVel())
#.........这里部分代码省略.........
开发者ID:11elangelm,项目名称:Mini-5,代码行数:103,代码来源:Game.py

示例4: __init__

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import move [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.move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。