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


Python Robot.run方法代码示例

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


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

示例1: sineMotion

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import run [as 别名]
def sineMotion(ids, commandRate, offset, amp, freq):
    robot = Robot(expectedIds=ids, commandRate=commandRate, cropMethod=None)

    nIds = len(ids)
    motionFunction = lambda time: [offset + amp * sin(2 * pi * time * freq) for ii in range(nIds)]

    robot.run(motionFunction, runSeconds=10, interpBegin=1, resetFirst=False)
开发者ID:yosinski,项目名称:QuadraTot,代码行数:9,代码来源:sineMotion.py

示例2: main

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import run [as 别名]
def main():
    if len(sys.argv) < 3:
        print 'Usage: %s input_gait_file output_position_file' % sys.argv[0]
        sys.exit(1)

    gaitFile = sys.argv[1]
    posFile  = sys.argv[2]


    strategy = TimedFileStrategy(posFile = gaitFile)

    motionFunction, logInfo = strategy.getNext()

    #runman = RunManager()
    #runman.do_many_runs(strategy, SineModel5.typicalRanges)

    #timeScale = .3
    #motionFunctionScaled = scaleTime(motionFunction, timeScale)
    wiiTrack = WiiTrackFastClient("localhost", 8080)
    time.sleep(.5)
    position,age = wiiTrack.getPosAge()
    if age is None:
        raise Exception('Could not get position from wiiTrack.')

    robot = Robot(loud = True)
    bucket = []

    def foo():
        savePosition(wiiTrack, bucket)

    robot.run(motionFunction, runSeconds = 10, resetFirst = True,
              interpBegin = 2, interpEnd = 2, extraLogInfoFn = foo)

    print 'Positions:'
    print len(bucket)

    relTimeBucket = []
    for ii, line in enumerate(bucket):
        delta = line[0] - bucket[0][0]
        relTime = delta.seconds + delta.microseconds/1e6
        relTimeBucket.append((relTime, line[1], line[2]))


    ff = open (posFile, 'w')
    ff.write('# time (junk junk)x9 pos.x pos.y 0 age\n')
    for ii, timePosAge in enumerate(relTimeBucket):
        timeOfPosition, position, age = timePosAge
        line = '%.3f' % timeOfPosition
        line += ' -1 -1' * 9
        line += ' %.1f %.1f %.1f' % (position[0], position[1], 0)
        line += ' %f' % age
        ff.write(line + '\n')
    ff.close()
    print 'Wrote position file:', posFile
开发者ID:PHPDOTSQL,项目名称:QuadraTot,代码行数:56,代码来源:runGaitAndLogPos.py

示例3: main22

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import run [as 别名]
def main22():
    if len(sys.argv) > 2 and sys.argv[1] == '-filt':
        filtFile = sys.argv[2]
        strategy = FileStrategy(filtFile = filtFile)
        motionFunction, logInfo = strategy.getNext()
    elif len(sys.argv) > 2 and sys.argv[1] == '-sine':
        sineModel5Params = [eval(xx) for xx in sys.argv[2].split()]
        print 'Using SineModel5 with params: ', sineModel5Params
        motionFunction = lambda time: SineModel5().model(time,
                                                         parameters = sineModel5Params)
    else:
        #filtFile = '../results/hyperneatTo20gens_101/neat_110115_175446_00014_008_filt'
        filtFile = '../results/hyperneatTo20gens_101/neat_110115_175446_00004_007_filt'
        strategy = FileStrategy(filtFile = filtFile)
        motionFunction, logInfo = strategy.getNext()
    	

    
    #runman = RunManager()
    #runman.do_many_runs(strategy, SineModel5.typicalRanges)

    #timeScale = .3
    #motionFunctionScaled = scaleTime(motionFunction, timeScale)
    wiiTrack = WiiTrackFastClient("localhost", 8080)
    time.sleep(.5)
    position,age = wiiTrack.getPosAge()
    if age is None:
        raise Exception('Could not get position from wiiTrack.')

    robot = Robot(loud = True)
    bucket = []

    def foo():
        savePosition(wiiTrack, bucket)

    robot.run(motionFunction, runSeconds = 8, resetFirst = False,
              interpBegin = 2, interpEnd = 2, extraLogInfoFn = foo)
    
    print bucket    
开发者ID:PHPDOTSQL,项目名称:QuadraTot,代码行数:41,代码来源:justWalkPlot.py

示例4: __init__

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import run [as 别名]
class RunManager:
    '''Manage runs..'''

    def __init__(self):
        self.robot = Robot(commandRate = 40, loud = False)
        self.statesSoFar = set()  # Keeps track of the states tested so far
        
    def run_robot(self, currentState):
        '''
        Runs the robot with currentState parameters and returns the
        distance walked.  If currentState is a function, calls that
        function instead of passing to a motion model.
        '''

        if hasattr(currentState, '__call__'):
            # is a function
            motionModel = currentState
        else:
            # is a parameter vector
            model = SineModel5()
            motionModel = lambda time: model.model(time,
                                                   parameters = currentState)

        # Reset before measuring
        self.robot.readyPosition()

        wiiTrack = WiiTrackClient("localhost", 8080)
        beginPos = wiiTrack.getPosition()
        if beginPos is None:
            # Robot walked out of sensor view
            self.manual_reset('Robot has walked outisde sensor view.  Please place back in center and push enter to continue.')
            print 'Retrying last run'
            return self.run_robot(currentState)

        if not self.robot.shimmy():
            self.manual_reset('Shimmy failed.  Fix and restart.')
            return self.run_robot(currentState)

        try:
            self.robot.run(motionModel, runSeconds = 9, resetFirst = False,
                           interpBegin = 1, interpEnd = 2)
        except RobotFailure as ee:
            print ee
            override = self.manual_reset('Robot run failure.  Fix something and push enter to continue, or enter a fitness to manually enter it.')
#            print 'Retrying last run'
#            return self.run_robot(currentState)
            try:
                manualDist = float(override)
                return manualDist
            except ValueError:
                print 'Retrying last run'
                return self.run_robot(currentState)
            

        endPos = wiiTrack.getPosition()
        if endPos is None:
            # Robot walked out of sensor view
            override = self.manual_reset('Robot has walked outisde sensor view.  Please place back in center\nand push enter to retry or enter manual fitness override to skip.')
            try:
                manualDist = float(override)
                return manualDist
            except ValueError:
                print 'Retrying last run'
                return self.run_robot(currentState)

        distance_walked = self.calculate_distance(beginPos, endPos)
        #print '        walked %.2f' % distance_walked

        if not self.robot.shimmy():
            ret = distance_walked / 2.0
            print 'Shimmy failed, returning %.2f instead of %.2f' % (ret, distance_walked)
            self.manual_reset('Shimmy failed at end, reset robot if necessary and push enter to continue.')
            return ret
        else:
            return distance_walked
            
    def run_function_and_log(self, motionFunction, runSeconds, timeScale = 1, logFilename = None):
        '''
        Runs the robot with the given motion function from 0 to
        runSeconds, logging time and position to logFileName
        '''

        # Reset before measuring
        self.robot.readyPosition()

        wiiTrack = WiiTrackFastClient("localhost", 8080)
        sleep(.5)
        beginPos = wiiTrack.getPosition()
        if beginPos is None:
            # Robot walked out of sensor view
            self.manual_reset('Robot has walked outisde sensor view.  Please place back in center and push enter to retry.')
            raise Exception

        if not self.robot.shimmy():
            print 'Shimmy failed :('
            #self.manual_reset('Shimmy failed.  Fix and push enter to retry.')
            #####HACK !!!!!!
            #raise Exception

        ff = open(logFilename, 'a')
#.........这里部分代码省略.........
开发者ID:PHPDOTSQL,项目名称:QuadraTot,代码行数:103,代码来源:RunManager.py

示例5: doRun

# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import run [as 别名]
def doRun():
    # Parameters are: amp, tau, scaleInOut, flipFB, flipLR
    
    android = Robot(commandRate = 40, loud = False)
    # TODO: motion = Motion()
    # TODO: Move ranges below 
    #ranges = [(0, 400),
    #          (.5, 8),
    #          (-2, 2),
    #          (False, True),
    #          (False, True)]

    ranges = [(0, 400),
              (.5, 8),
              (-2, 2),
              (-1, 1),
              (-1, 1)]

    if len(sys.argv) > 1:
        currentState = [eval(xx) for xx in sys.argv[1].split()]
    else:
        currentState = initialState(ranges)

    statesSoFar = set()  # Keeps track of the states tested so far
    
    bestDistance = -1e100

    stateSoFar = set()

    logFile = open('log.txt', 'a')
    logFile.write('\nOptimize (gauss_op)  started at %s\n' % datetime.now().ctime())
    logFile.close()
    for ii in range(10000):
        print
        print 'Iteration %2d params' % ii, prettyVec(currentState)

        beginDistance = WiiTrackClient.getPosition()

        # Make sure this state is new, skip otherwise
        if tuple(currentState) in statesSoFar:
            print '*** Skipping duplicate iteration!'
            continue

        stateSoFar.add(tuple(currentState))

        motionModel = lambda time: sineModel(time,
                                             parameters = currentState)

        android.run(motionModel, runSeconds = 10, resetFirst = False,
                    interpBegin = 3, interpEnd = 3)

        endDistance = WiiTrackClient.getPosition()
        
        currentDistance = RunManager.calculateDistance(beginDistance,
                                                       endDistance)

        if currentDistance >= bestDistance:  # Is this a new best?
            bestState = copy(currentState)  # Save new neighbor to best found
            bestDistance = copy(currentDistance)

        print '        best so far', prettyVec(bestState), bestDistance  # Prints best state and distance so far

        # Writes to log file that keeps track of tests so far
        stats = ' '.join([repr(xx) for xx in currentState])
        logFile = open('log.txt', 'a')
        logFile.write(stats + ", " + str(currentDistance) + "\n")
        logFile.close()

        currentState = neighbor(ranges, bestState)

    return bestState  # Return the best solution found (a list of params)
开发者ID:PHPDOTSQL,项目名称:QuadraTot,代码行数:73,代码来源:gauss_op.py


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