Beispiel #1
0
    def testRepeatUntilSucceed_Count(self):
        """Does repeatUntilSucceed execute its child with every tick?
        """
        # How many times to repeat the behavior?
        ticks = 100
        bb = blackboard.Blackboard('test', count=0)

        @owyl.task
        def increment(**kwargs):
            bb, key = kwargs['blackboard'], kwargs['key']
            bb[key] += 1
            yield False

        tree = owyl.repeatUntilSucceed(increment(key='count'))
        v = owyl.visit(tree, blackboard=bb)
        for i in xrange(ticks):
            v.next()
        self.assertEqual(bb['count'], ticks)

        # Need to reset the blackboard to get the same results.
        bb = blackboard.Blackboard('test', count=0)
        v = owyl.visit(tree, blackboard=bb)
        for i in xrange(ticks):
            v.next()
        self.assertEqual(bb['count'], ticks)
Beispiel #2
0
    def create_main_tree(self):
        '''
            creates the main tree for owyl behavior tree

            Args:
                self
                The tree looks like this:
                                                                            root
                                                                             |
                                                                     owyl.repeatAlways
                                                                             |
                                                                        owyl.sequence
                                                                             |  
                            ---------------------------------------------------------------------------------------------------------------------------------------------------------
                            |                                                                       |                          |                            |                       |
                    owyl.selector                                                           owyl.repeatUntilSucceed    self.isCameraTrackDone()   owyl.repeatUntilSucceed      self.isWalkForward()
                           |                                                                        |                                                       |
                -------------------------------------------------------------------------       self.cameraTrack()                                  self.isBodyTrack()
                |                  |                |                   |               |       
        self.checkIfBall() self.search85()   self.search60()  self.search35() self.turnBody()


            Returns:
                Creates a tree and returns
                owyl.visit method to visit next nodes in the tree.
        '''
        # tree=owyl.repeatAlways(self.cameraTrack())  # For testing only the camera tracker ... see method cameraTrack() for details
        tree = owyl.repeatAlways(
            owyl.sequence(
                owyl.selector(
                    self.checkIfBall(),
                    owyl.selector(self.search85(), self.search60(),
                                  self.search35(), self.turnBody())),
                owyl.repeatUntilSucceed(self.cameraTrack()),
                self.isCameraTrackDone(),
                owyl.repeatUntilSucceed(self.isBodyTrack()),
                self.isWalkForward()))

        return owyl.visit(tree, blackboard=self.blackboard)
Beispiel #3
0
    def create_main_tree(self):
        '''
            creates the main tree for owyl behavior tree

            Args:
                self
                The tree looks like this:
                                                                            root
                                                                             |
                                                                     owyl.repeatAlways
                                                                             |
                                                                        owyl.sequence
                                                                             |  
                            ---------------------------------------------------------------------------------------------------------------------------------------------------------
                            |                                                                       |                          |                            |                       |
                    owyl.selector                                                           owyl.repeatUntilSucceed    self.isCameraTrackDone()   owyl.repeatUntilSucceed      self.isWalkForward()
                           |                                                                        |                                                       |
                -------------------------------------------------------------------------       self.cameraTrack()                                  self.isBodyTrack()
                |                  |                |                   |               |       
        self.checkIfBall() self.search85()   self.search60()  self.search35() self.turnBody()
                                    60()                35()            10()

            Returns:
                Creates a tree and returns
                owyl.visit method to visit next nodes in the tree.
        '''
        # tree=owyl.repeatAlways(self.cameraTrack())  # For testing only the camera tracker ... see method cameraTrack() for details
        tree=owyl.repeatAlways(
                owyl.sequence(
                    owyl.selector(self.checkIfBall(),owyl.selector(self.search85(),self.search60(),self.search35(),self.turnBody()))
                    ,owyl.repeatUntilSucceed(self.cameraTrack())
                    ,self.isCameraTrackDone()
                    ,owyl.repeatUntilSucceed(self.isBodyTrack())
                    ,self.isWalkForward()
                    )
                )
         
        return owyl.visit(tree,blackboard=self.blackboard)
Beispiel #4
0
 def testStructureBig(self):
     tree = owyl.parallel(owyl.sequence(owyl.repeatAlways(blackboard.setBB()), owyl.log()),
                          owyl.selector(owyl.repeatUntilSucceed(blackboard.checkBB())),
                          owyl.repeatUntilFail(owyl.fail()))
     viztree = OwylTree(tree)
     structure = truncate(viztree.get_structure(), ['name', 'children'])
     self.assertEquals(structure,
                       {'name': 'parallel',
                        'children': [{'name': 'sequence',
                                      'children': [{'name': 'repeatAlways',
                                                    'children': [{'name': 'setBB',
                                                                  'children': []}]},
                                                   {'name': 'log',
                                                    'children': []}]},
                                     {'name': 'selector',
                                      'children': [{'name': 'repeatUntilSucceed',
                                                    'children': [{'name': 'checkBB',
                                                                  'children': []}]}]},
                                     {'name': 'repeatUntilFail',
                                      'children': [{'name': 'fail',
                                                    'children': []}]}]})