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


Python Robot.shimmy方法代码示例

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


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

示例1: __init__

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


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