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


Python Robot.updateMap方法代码示例

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


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

示例1: testMotion

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import updateMap [as 别名]
    def testMotion(self):
        global helpList, helpTheta
        sample = RobotMessage()
        sample.leftMotorTacho = 0
        sample.rightMotorTacho = 0
        sample.leftSensor = [0]
        sample.frontSensor = [43,0]
        sample.timeStamp = 0
        robot = Robot()
        pose = Pose(20, 0, 90*math.pi/180)
        robot.pose = pose
        assert robot.sensorWheelAngle == 90*math.pi/180
        
        robot.motion(sample)
        
        assert robot.poseList[0] == pose
        
        robot.updateMap(sample, helpMapCallBack)
        
        # move forward 
        moveDistance = round(360/360*math.pi*robot.wheelDiameter) #14
        sample.leftMotorTacho = 360
        sample.rightMotorTacho = 360
        sample.leftSensor = [12.3, 12.3, 12.3]
        sample.frontSensor = [43-moveDistance,0]
        sample.timeStamp = 0
        
        robot.motion(sample)
        pose = Pose(20, 14, 90*math.pi/180)
        assert robot.pose == pose
        
        sx, sy, lx, ly, rx, ry = 20, 14+7, round(20-7.7), 14, round(20+7.7), 14
        assert (sx, sy, lx, ly, rx, ry) == robot.getRobotShape(pose)

        robot.updateMap(sample, helpMapCallBack)
        testList = [(0, round(14/3)), (0, round(14/3*2)), (0, round(14/3*3)), (20, 50)]
        assert testList == helpList        
        assert helpTheta[0] == 90*math.pi/180
        
        # turn right 45 degree 
        # deltatacho = 45/180*math.pi*robot.TurnRadius)/(robot.wheelDiameter*math.pi)*360
        helpList = []
        helpTheta = []
        sample.leftMotorTacho = 360 + round((45*robot.TurnRadius)/(robot.wheelDiameter)*2)
        sample.rightMotorTacho = 360 - round((45*robot.TurnRadius)/(robot.wheelDiameter)*2)
        sample.leftSensor = [12.3, 12.3, 12.3]
        sample.frontSensor = [43,0]
        sample.timeStamp = 0        
        
        robot.motion(sample)
        pose = Pose(20, 14, round((90-45)*math.pi/180, 2))
        robot.pose.theta = round(robot.pose.theta, 2)

        assert robot.pose == pose
        
        moveWheel = round(7.7*math.cos(45/180*math.pi))
        moveSensor = round(7.0*math.cos(45/180*math.pi))
        
        pose = Pose(20, 14, (90-45)*math.pi/180)
        
        sx, sy, lx, ly, rx, ry = 20+moveSensor, 14 + moveSensor, 20 - moveWheel, 14 + moveWheel, 20 + moveWheel, 14 - moveWheel
        assert (sx, sy, lx, ly, rx, ry) == robot.getRobotShape(pose)
        
        testList = []
        robot.updateMap(sample, helpMapCallBack)
        assert testList == helpList
        
        #keep move forward with this angle
        helpList = []
        sample.leftMotorTacho = 360 + round((45*robot.TurnRadius)/(robot.wheelDiameter)*2) + 360
        sample.rightMotorTacho = 360 - round((45*robot.TurnRadius)/(robot.wheelDiameter)*2) + 360
        sample.leftSensor = [20, 20, 20]
        sample.frontSensor = [15]
        sample.timeStamp = 0        
        
        robot.motion(sample)
        pose = Pose(20 + round(14*math.cos(45/180*math.pi)), 14+ round(14*math.cos(45/180*math.pi)), round((90-45)*math.pi/180, 2))
        robot.pose.theta = round(robot.pose.theta, 2)   
        assert robot.pose == pose    
        
        # robot moved 14 again, each distance is 4.6, then, deltaX = sqrt(4.6*4.6/2), the sample point to sensor is 20
        # then, the delta(sensorX, samplepointX) is sqrt(20*20/2), the sampleX = lx + sqrt(4.6*4.6/2) - sqrt(20*20/2)
        # sampleY = ly + sqrt(4.6*4.6/2) + sqrt(20*20/2)
        testList = [(4, 36), (8, 40), (11, 43), (46, 40)]
        robot.updateMap(sample, helpMapCallBack)
        assert testList == helpList
        
        #Robot turn left 180
        sample.leftMotorTacho = 360 + round((45*robot.TurnRadius)/(robot.wheelDiameter)*2) + 360 - round((180*robot.TurnRadius)/(robot.wheelDiameter)*2)
        sample.rightMotorTacho = 360 - round((45*robot.TurnRadius)/(robot.wheelDiameter)*2) + 360 + round((180*robot.TurnRadius)/(robot.wheelDiameter)*2)
        sample.leftSensor = [20, 20, 20]
        sample.frontSensor = [15]
        sample.timeStamp = 0        
        
        robot.motion(sample)  
        pose = Pose(pose.x, pose.y, pose.theta + math.pi) 
        assert pose.x == robot.pose.x and pose.y == robot.pose.y and round(pose.theta, 2) == round(robot.pose.theta, 2)
        
        #Robot move 360 count
        helpList = []
#.........这里部分代码省略.........
开发者ID:cflames,项目名称:ev3,代码行数:103,代码来源:unitestRobot.py

示例2: print

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import updateMap [as 别名]
    lines = []    
    while True:
        pygame.event.clear()
        # get message from robotConnection
        message = robotConn.readMessage(simulate=True)        
            
        if message is None:
            pygame.event.pump()
            clock.tick(20)
            continue
        # make robot motion
        if message.type == "Left":
            robot.motion(message)
            # get sample points after motion
            robot.updateMap(message, map.update)            
        elif message.type == "Corner":
            robot.updateCorner(message, map.update)
        else:
            print("Error message type")
            continue
        # get sample points after motion
        robot.updateMap(message, map.update)
        # Draw Robot
        print(robot.pose)
        sx, sy, lx, ly, rx, ry = robot.getRobotShape(robot.pose)
        pygame.draw.polygon(screen,(255,0,0),((rx,ry),(lx,ly),(sx,sy)),2)
        # Draw map
        points = []
        points = map.getPoints()
        for point in points:
开发者ID:cflames,项目名称:ev3,代码行数:32,代码来源:gui.py


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