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


Python Simulator.robotOrientationToGoal方法代码示例

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


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

示例1: SimulatedLucy

# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import robotOrientationToGoal [as 别名]
class SimulatedLucy(Lucy):

    def __init__(self, visible=False):
        Lucy.__init__(self)
        self.visible = visible
        genetic_bioloid = os.getcwd() + self.sysConf.getFile("Lucy vrep model")
        self.sim = Simulator(genetic_bioloid)
        self.clientID = self.sim.getClientId() 
        if self.clientID == -1:
            retry_counter = sysConstants.ERROR_RETRY
            time.sleep(0.1)
            self.clientID = self.sim.getClientId()
            while self.clientID == -1 and retry_counter > 0:
                time.sleep(0.5)
                retry_counter = retry_counter - 1
                self.clientID = self.sim.getClientId()
                print "waiting for vrep connection"
            if self.clientID == -1:
                raise VrepException("error connecting with Vrep", -1)
        self.sim.startSim(self.clientID,self.visible)
        self.jointHandleCachePopulated = False
        configuration = LoadRobotConfiguration()
        self.joints = configuration.getJointsName()
        self.firstCallGetFrame = True
        self.sim.robotOrientationToGoal()
        self.updateLucyPosition()
        self.posesExecutedByStepQty = self.sim.getPosesExecutedByStepQty(self.clientID)

    def getSimTime(self):
        if self.stop == False:
            self.time = time.time() - self.startTime
        return self.time
        
    def getSimDistance(self):
        return self.distance

    def getFitness(self, secuenceLength, concatenationGap):
        error, angle = self.sim.robotOrientationToGoal()
        distance = self.getSimDistance()
        error, upD = self.sim.getUpDistance()
        framesQty = secuenceLength
        cycleEnded = 0

        print "--------------------------------------------------------------------"
        print "orientation: ", angle
        print "distance traveled: ", distance
        print "poses executed/total poses: ",  self.poseExecuted, "/", framesQty
        if self.isLucyUp():
            print "isRobotUp?: True"
            cycleEnded = 1
            framesExecuted = 1
            endCycleBalance = upD/self.balanceHeight #Distance from the floor when lucy is straight up
            if endCycleBalance > 1:
                endCycleBalance = 1
        else:
            print "isRobotUp?: False"
            if framesQty > 0:
                framesExecuted = self.poseExecuted / float(framesQty)
                if framesExecuted == 1:
                    framesExecuted = framesExecuted - framesExecuted/10
            else:
                framesExecuted = 0
            endCycleBalance = 0

        dtFitness = DTFitness(distance, concatenationGap, framesExecuted, endCycleBalance, angle)
        fitnessFunction = DistanceConcatenationgapFramesexecutedEndcyclebalanceAngle(dtFitness)


        #dtFitness = DTFitness(distance=distance, concatenationGap=concatenationGap, framesExecuted=framesExecuted, angle=angle, cycleEnded=cycleEnded)
        #fitnessFunction = NormdistanceConcatenationgapFramesexecutedNormAngle(dtFitness)
        #fitnessFunction = ConcatenationgapFramesexecutedNormAngle(dtFitness)
        fitness = fitnessFunction.getFitness()

        print "framesExecuted: ", framesExecuted
        print "FITNESS: ", fitness
        print "upDistance: ", self.sim.getUpDistance()
        print "endCycleBalance: ", endCycleBalance

        print "--------------------------------------------------------------------"
        return fitness

    def getPosesExecutedByStepQty(self):
        return self.posesExecutedByStepQty

    def executePose(self, pose):
        error = False
        #Above's N joints will be received and set on the V-REP side at the same time

        jointsQty = len(self.RobotImplementedJoints)
        jointExecutedCounter = 0

        error = self.sim.pauseSim(self.clientID) or error
        for joint in self.RobotImplementedJoints:
            angle = pose.getValue(joint) 
            angleAX = AXAngle()   
            angleAX.setDegreeValue(angle)
            #print "setting joint: ", joint, " to value: ", angle

            if jointExecutedCounter < jointsQty - 1:
                error = self.sim.setJointPositionNonBlock(self.clientID, joint, angleAX.toVrep()) or error
#.........这里部分代码省略.........
开发者ID:aguirrea,项目名称:lucy,代码行数:103,代码来源:Lucy.py


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