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


Python Robot.refreshRobot方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import refreshRobot [as 别名]
class Simulation:
    
    def __init__(self):
        '''Uses VPython to visualize, manipulate and simulate the Quadruped live.'''
        self.bodies = []
        self.cWorld = myWorld()
        self.createUI(self.cWorld.world._getScene())
        
        # terrain for future implementation
        #self.myWorld = e.Heightmap(self.cWorld.world)
        #self.Terrain = self.myWorld.makeWorld()
        
        self.cRobot = Robot(self.cWorld.world, vpyode._bigSpace, 50)
        self.cCtrl = ControlWindow(self.cWorld.world._getScene(), self.cRobot, self.cWorld)
        
        self.cRobot.dropRobot()
        
        self.dt = 1.0/const.framerate
        self.refresh = 0
        
        self.bodies.append(e.drop_object(self.cWorld.world, self.cRobot.center))
    
    def startLoop(self):
        itemcount = 0
        count = random.uniform(1,50)
        random.seed()
        
        while(1):
            visual.rate(const.framerate) # Frame rate
            
            # check for events, drive actions; must be executed repeatedly in a loop
            self.cCtrl.ctrls.interact()
            
            # do multiple simulation steps per frame to prevent jittering due to
            # 'small' collisions
            n = 6
            
            if itemcount < count:
                itemcount += 1
                self.bodies.append(e.drop_object(self.cWorld.world, self.cRobot.center))
                    
            itemcount+=1
            
            if itemcount == 500:
                itemcount = 0
                for b in self.bodies:
                    for body in b.GetElementKeys():
                        b.RemoveElement(body)
                self.bodies = []
        
            for i in range(n):           
                # Simulation step
                self.cWorld.world.step(self.dt/n)
                
                # terrain for future implementation
                #self.Terrain.UpdateDisplay()
                
                if self.cRobot.bodyExists():
                    self.cRobot.refreshRobot(self.cCtrl.lBody)
                
                    if (self.cRobot.centerRobot):
                        self.cWorld.world._getScene().center = self.cRobot.center
                    
                    for leg in self.cRobot.tibia:
                        leg.UpdateDisplay()
                        
                    for leg in self.cRobot.femur:
                        leg.UpdateDisplay()
                        
                    for b in self.bodies:
                        b.UpdateDisplay()
                        
                        
    def setupWindow(self, scene):
        scene.title = 'Quadruped Simulation'
        scene.height = const.windowHeight
        scene.width = const.windowWidth
        scene.autoscale = 0
        scene.forward = (-5,-5,-5)
        scene.background = (0.0,0.0,0.0)
        
        self.createFloor()
        self.createArrows()
        
    def createFloor(self):
        Grid.grid(500)
    
    def createArrows(self):
        ''' Create arrow coordinates '''
        visual.arrow(pos=(0,0,0), axis=(1,0,0), radius=1, color=(0,0,1), length=3)
        visual.arrow(pos=(0,0,0), axis=(0,1,0), radius=1, color=(1,0,0), length=3)
        visual.arrow(pos=(0,0,0), axis=(0,0,1), radius=1, color=(0,1,0), length=3)
        
        visual.controls.label(pos = (3,0,0), text='x',box=False, opacity=0.0)
        visual.controls.label(pos = (0,3,0), text='y',box=False, opacity=0.0)
        visual.controls.label(pos = (0,0,3), text='z',box=False, opacity=0.0)
        
    def createUI(self, scene):
        '''Setup window and controls'''
        self.setupWindow(scene)
#.........这里部分代码省略.........
开发者ID:MartinStolle,项目名称:quadruped-walking-gaits,代码行数:103,代码来源:Simu.py


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