コード例 #1
0
    def __init__(self, name, model):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        # name = type(model.target).__name__
        # self.shared_content[name] = {model.target}

        root = py_trees.composites.Selector("Selector")
        left_sequence = py_trees.composites.Sequence("LSequence")
        right_sequence = py_trees.composites.Sequence("RSequence")
        low = RandomWalk('1')
        low.setup(0, self)
        # low1 = IsMoveable('2')
        # low1.setup(0, self,)
        low2 = Move('3')
        low2.setup(0, self)
        medium = NeighbourObjects('4')
        medium.setup(0, self, 'Sites')
        high = DoNotMove('5')
        high.setup(0, self)
        left_sequence.add_children([medium, high])
        right_sequence.add_children([low, low2])
        # medium = GoTo('2')
        # medium.setup(0, self, self.attached_objects['Sites'][0])
        root.add_children([left_sequence, right_sequence])
        self.behaviour_tree = py_trees.trees.BehaviourTree(root)
コード例 #2
0
    def __init__(self, name, model):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        # self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        root = py_trees.composites.Sequence("Sequence")

        sense = NeighbourObjects('Sense')
        sense.setup(0, self, 'Debris')

        multiple_carry = CompositeMultipleCarry('MultipleCarry')
        multiple_carry.setup(0, self, 'Debris')

        move = Move('Move')
        move.setup(0, self)

        root.add_children([sense, multiple_carry, move])

        self.behaviour_tree = py_trees.trees.BehaviourTree(root)
コード例 #3
0
    def __init__(self, name, model):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        # self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        root = py_trees.composites.Sequence("Sequence")
        # Sensing the environemnt to find object to carry
        lowest = NeighbourObjects('0')
        lowest.setup(0, self, 'Food')

        # First check if the item is carrable?
        carryable = IsCarryable('SC_IsCarryable_1')
        carryable.setup(0, self, 'Food')

        # Then check if the item can be carried by a single agent
        issinglecarry = IsSingleCarry('SC_IsSingleCarry_2')
        issinglecarry.setup(0, self, 'Food')

        # Finally, carry the object
        singlecarry = SingleCarry('SC_SingleCarry_3')
        singlecarry.setup(0, self, 'Food')

        # Define a sequence to combine the primitive behavior
        sc_sequence = py_trees.composites.Sequence('SC_SEQUENCE')
        sc_sequence.add_children([carryable, issinglecarry, singlecarry])

        # Creating composite single carry object
        # singlecarry = CompositeSingleCarry('SingleCarry')
        # singlecarry.setup(0, self, 'Food')

        high = Explore('Explore')
        high.setup(0, self)

        root.add_children([lowest, sc_sequence, high])
        self.behaviour_tree = py_trees.trees.BehaviourTree(root)
コード例 #4
0
    def __init__(self, name, model):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        # self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        root = py_trees.composites.Sequence("Sequence")
        # Sensing the environemnt to find object to carry
        lowest = NeighbourObjects('0')
        lowest.setup(0, self, 'Debris')

        # Creating composite single carry object
        singlecarry = CompositeSingleCarry('SingleCarry')
        singlecarry.setup(0, self, 'Debris')

        root.add_children([lowest, singlecarry])
        self.behaviour_tree = py_trees.trees.BehaviourTree(root)
コード例 #5
0
    def setup(self, timeout, agent, item=None):
        """Have defined the setup method.

        This method defines the other objects required for the
        behavior. Agent is the actor in the environment,
        item is the name of the item we are trying to find in the
        environment and timeout defines the execution time for the
        behavior.
        """
        self.agent = agent
        self.item = item

        # Define the root for the BT
        root = Sequence('CPC_Sequence')

        c1 = NeighbourObjects('CPS_SearchCue')
        c1.setup(0, self.agent, 'Cue')

        c2 = PickCue('CPS_PickCue')
        c2.setup(0, self.agent, 'Cue')

        root.add_children([c1, c2])

        self.behaviour_tree = BehaviourTree(root)
コード例 #6
0
    def setup(self, timeout, agent, item=None):
        """Have defined the setup method.

        This method defines the other objects required for the
        behavior. Agent is the actor in the environment,
        item is the name of the item we are trying to find in the
        environment and timeout defines the execution time for the
        behavior.
        """
        self.agent = agent
        self.item = item

        # Define the root for the BT
        root = Sequence('CRS_Sequence')

        s1 = NeighbourObjects('CRS_NeighbourObjects')
        s1.setup(0, self.agent, 'Signal')

        s2 = ReceiveSignal('CRS_ReceiveSignal')
        s2.setup(0, self.agent, 'Signal')

        root.add_children([s1, s2])

        self.behaviour_tree = BehaviourTree(root)
コード例 #7
0
ファイル: test_full_ct.py プロジェクト: foton263/swarm
    def __init__(self, name, model):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        # self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()
        self.shared_content['Hub'] = {model.hub}
        self.shared_content['Sites'] = {model.site}

        # Drop branch
        dseq = py_trees.composites.Sequence('DSequence')

        iscarrying = IsInPartialAttached('8')
        iscarrying.setup(0, self, 'Food')

        # If near hub and carrying food with other agents drop
        neighhub = NeighbourObjects('2')
        neighhub.setup(0, self, 'Hub')

        drop = CompositeDropPartial('4')
        drop.setup(0, self, 'Food')

        dseq.add_children([neighhub, drop])

        # Carry branch
        cseq = py_trees.composites.Sequence('CSequence')

        # neighsite = NeighbourObjects('5')
        # neighsite.setup(0, self, 'Sites')
        neighhub = py_trees.meta.inverter(NeighbourObjects)('40')
        neighhub.setup(0, self, 'Hub')

        neighfood = NeighbourObjects('50')
        neighfood.setup(0, self, 'Food')

        invcarrying = py_trees.meta.inverter(IsInPartialAttached)('8')
        invcarrying.setup(0, self, 'Food')

        carry = CompositeMultipleCarry('9')
        carry.setup(0, self, 'Food')

        # Move to hub
        hubseq = py_trees.composites.Sequence('HubSeq')
        # If carrying something to go to hub
        gotohub = MoveTowards('10')
        gotohub.setup(0, self, 'Hub')

        hubseq.add_children([iscarrying, gotohub])

        cseq.add_children([neighhub, neighfood, carry, hubseq])

        # Locomotion branch

        # Move to site
        siteseq = py_trees.composites.Sequence('SiteSeq')
        # If site already found and not carrying anything go to site
        sitefound = IsVisitedBefore('7')
        sitefound.setup(0, self, 'Sites')

        gotosite = MoveTowards('9')
        gotosite.setup(0, self, 'Sites')

        siteseq.add_children([sitefound, invcarrying, gotosite])

        # Do Random walk
        explore = Explore('12')
        explore.setup(0, self)

        randwalk = py_trees.composites.Sequence('Randwalk')
        randwalk.add_children([explore])
        # Try to got to site and hub if not explore
        locoselect = py_trees.composites.Selector('Move')
        locoselect.add_children([iscarrying, siteseq, explore])
        # First try to drop then collect or explore
        select = py_trees.composites.Selector('Main')
        select.add_children([dseq, cseq, locoselect])

        self.behaviour_tree = py_trees.trees.BehaviourTree(select)
コード例 #8
0
ファイル: simagent.py プロジェクト: foton263/swarm
    def __init__(self, name, model, xmlstring=None):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        self.carryable = False
        # Define a BTContruct object
        self.bt = BTConstruct(None, self)

        class DummyIndividual:
            def __init__(self):
                self.phenotype = None

        dummyind = DummyIndividual()
        self.individual = [dummyind]
        self.individual[0].phenotype = xmlstring

        # self.bt.xmlstring = xmlstring
        # self.bt.construct()

        # Drop branch
        dseq = py_trees.composites.Sequence('DSequence')
        iscarrying = IsCarrying('IsCarrying_Food')
        iscarrying.setup(0, self, 'Food')

        neighhub = NeighbourObjects('NeighbourObjects_Hub')
        neighhub.setup(0, self, 'Hub')

        notneighhub = py_trees.meta.inverter(NeighbourObjects)(
            'NeighbourObjects_Hub')
        notneighhub.setup(0, self, 'Hub')

        drop = CompositeDrop('CompositeDrop_Food')
        drop.setup(0, self, 'Food')

        dseq.add_children([neighhub, drop])

        # Carry branch
        cseq = py_trees.composites.Sequence('CSequence')

        neighsite = NeighbourObjects('NeighbourObjects_Sites')
        neighsite.setup(0, self, 'Sites')

        neighfood = NeighbourObjects('NeighbourObjects_Food')
        neighfood.setup(0, self, 'Food')

        invcarrying = py_trees.meta.inverter(IsCarrying)('IsCarrying_Food')
        invcarrying.setup(0, self, 'Food')

        carry = CompositeSingleCarry('CompositeSingleCarry_Food')
        carry.setup(0, self, 'Food')

        cseq.add_children([neighsite, neighfood, invcarrying, carry])

        # Locomotion branch

        # Move to site
        siteseq = py_trees.composites.Sequence('SiteSeq')

        sitefound = IsVisitedBefore('IsVisitedBefore_Sites')
        sitefound.setup(0, self, 'Sites')

        gotosite = MoveTowards('MoveTowards_Sites')
        gotosite.setup(0, self, 'Sites')

        siteseq.add_children([sitefound, invcarrying, gotosite])
        # siteseq.add_children([invcarrying])

        # Move to hub
        hubseq = py_trees.composites.Sequence('HubSeq')

        gotohub = MoveTowards('MoveTowards_Hub')
        gotohub.setup(0, self, 'Hub')

        hubseq.add_children([iscarrying, gotohub])

        sitenotfound = py_trees.meta.inverter(IsVisitedBefore)(
            'IsVisitedBefore_Sites')
        sitenotfound.setup(0, self, 'Sites')

        explore = Explore('Explore')
        explore.setup(0, self)

        randwalk = py_trees.composites.Sequence('Randwalk')
        randwalk.add_children([sitenotfound, explore])

        locoselect = py_trees.composites.Selector('Move')
        # locoselect.add_children([siteseq, hubseq, explore])
        locoselect.add_children([hubseq, randwalk])

        select = py_trees.composites.Selector('Main')

        select.add_children([dseq, cseq, locoselect])

        self.behaviour_tree = py_trees.trees.BehaviourTree(select)

        py_trees.display.render_dot_tree(self.behaviour_tree.root,
                                         name=model.pname + '/forgehc')
コード例 #9
0
ファイル: simagent.py プロジェクト: foton263/swarm
    def __init__(self, name, model, xmlstring=None):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        self.carryable = False
        # Define a BTContruct object
        self.bt = BTConstruct(None, self)

        class DummyIndividual:
            def __init__(self):
                self.phenotype = None

        dummyind = DummyIndividual()
        self.individual = [dummyind]
        self.individual[0].phenotype = xmlstring

        # self.bt.xmlstring = xmlstring
        # self.bt.construct()

        # self.shared_content['Hub'] = {model.hub}
        # self.shared_content['Sites'] = {model.site}

        # Drop branch
        dseq = py_trees.composites.Sequence('DSequence')

        iscarrying = IsInPartialAttached('IsInPartialAttached_Food')
        iscarrying.setup(0, self, 'Food')

        # If near hub and carrying food with other agents drop
        neighhub = NeighbourObjects('NeighbourObjects_Hub')
        neighhub.setup(0, self, 'Hub')

        drop = CompositeDropPartial('CompositeDropPartial_Food')
        drop.setup(0, self, 'Food')

        dseq.add_children([neighhub, drop])

        # Carry branch
        cseq = py_trees.composites.Sequence('CSequence')

        # neighsite = NeighbourObjects('5')
        # neighsite.setup(0, self, 'Sites')
        neighhub = py_trees.meta.inverter(NeighbourObjects)(
            'NeighbourObjects_Hub')
        neighhub.setup(0, self, 'Hub')

        neighfood = NeighbourObjects('NeighbourObjects_Food')
        neighfood.setup(0, self, 'Food')

        invcarrying = py_trees.meta.inverter(IsInPartialAttached)(
            'IsInPartialAttached_Food')
        invcarrying.setup(0, self, 'Food')

        carry = CompositeMultipleCarry('CompositeMultipleCarry_Food')
        carry.setup(0, self, 'Food')

        # Move to hub
        hubseq = py_trees.composites.Sequence('HubSeq')
        # If carrying something to go to hub
        gotohub = MoveTowards('MoveTowards_Hub')
        gotohub.setup(0, self, 'Hub')

        hubseq.add_children([iscarrying, gotohub])

        cseq.add_children([neighhub, neighfood, carry, hubseq])

        # Locomotion branch

        # Move to site
        siteseq = py_trees.composites.Sequence('SiteSeq')
        # If site already found and not carrying anything go to site
        sitefound = IsVisitedBefore('IsVisitedBefore_Sites')
        sitefound.setup(0, self, 'Sites')

        gotosite = MoveTowards('MoveTowards_Sites')
        gotosite.setup(0, self, 'Sites')

        siteseq.add_children([sitefound, invcarrying, gotosite])

        # Do Random walk
        explore = Explore('Explore')
        explore.setup(0, self)

        randwalk = py_trees.composites.Sequence('Randwalk')
        randwalk.add_children([explore])
        # Try to got to site and hub if not explore
        locoselect = py_trees.composites.Selector('Move')
        locoselect.add_children([iscarrying, siteseq, explore])
        # First try to drop then collect or explore
        select = py_trees.composites.Selector('Main')
        select.add_children([dseq, cseq, locoselect])

        self.behaviour_tree = py_trees.trees.BehaviourTree(select)
        py_trees.display.render_dot_tree(self.behaviour_tree.root,
                                         name=model.pname + '/cthc')
コード例 #10
0
    def __init__(self, name, model):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        # self.shared_content['Hub'] = model.hub
        # self.shared_content['Sites'] = model.site
        self.shared_content['Hub'] = {model.hub}
        # root = py_trees.composites.Sequence("Sequence")
        # root = py_trees.composites.Selector('Selector')
        mseq = py_trees.composites.Sequence('MSequence')
        nseq = py_trees.composites.Sequence('NSequence')
        select = py_trees.composites.Selector('RSelector')
        carryseq = py_trees.composites.Sequence('CSequence')
        dropseq = py_trees.composites.Sequence('DSequence')

        lowest1 = py_trees.meta.inverter(NeighbourObjects)('00')
        lowest1.setup(0, self, 'Hub')

        lowest11 = NeighbourObjects('0')
        lowest11.setup(0, self, 'Sites')

        lowest = NeighbourObjects('0')
        lowest.setup(0, self, 'Food')

        low = IsCarryable('1')
        low.setup(0, self, 'Food')

        medium = IsSingleCarry('2')
        medium.setup(0, self, 'Food')

        high = SingleCarry('3')
        high.setup(0, self, 'Food')

        carryseq.add_children([lowest1, lowest11, lowest, low, medium, high])

        repeathub = RepeatUntilFalse("RepeatSeqHub")
        repeatsite = RepeatUntilFalse("RepeatSeqSite")

        high1 = py_trees.meta.inverter(NeighbourObjects)('4')
        # high1 = NeighbourObjects('4')
        high1.setup(0, self, 'Hub')

        med1 = GoTo('5')
        med1.setup(0, self, 'Hub')

        # low1 = py_trees.meta.inverter(Move)('6')
        low1 = Move('6')
        low1.setup(0, self, None)

        high2 = py_trees.meta.inverter(NeighbourObjects)('12')
        # high2 = NeighbourObjects('12')
        high2.setup(0, self, 'Sites')

        # med2 = py_trees.meta.inverter(GoTo)('13')
        med2 = GoTo('13')
        med2.setup(0, self, 'Sites')

        # low1 = py_trees.meta.inverter(Move)('6')
        low2 = Move('14')
        low2.setup(0, self, None)

        # Drop
        dropseq = py_trees.composites.Sequence('DSequence')
        c1 = IsCarrying('7')
        c1.setup(0, self, 'Food')

        d1 = IsDropable('8')
        d1.setup(0, self, 'Hub')

        d2 = Drop('9')
        d2.setup(0, self, 'Food')

        dropseq.add_children([c1, d1, d2])

        repeathub.add_children([high1, med1, low1])
        repeatsite.add_children([high2, med2, low2])

        mseq.add_children([carryseq, repeathub])
        nseq.add_children([dropseq, repeatsite])

        # For randomwalk to work the agents shouldn't know the location of Site
        v1 = py_trees.meta.inverter(IsVisitedBefore)('15')
        v1.setup(0, self, 'Sites')

        r1 = RandomWalk('16')
        r1.setup(0, self, None)

        m1 = Move('17')
        m1.setup(0, self, None)

        randseq = py_trees.composites.Sequence('RSequence')
        randseq.add_children([v1, r1, m1])

        select.add_children([nseq, mseq, randseq])

        self.behaviour_tree = py_trees.trees.BehaviourTree(select)
コード例 #11
0
    def __init__(self, name, model):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        self.shared_content['Hub'] = {model.hub}
        # Drop branch
        dseq = py_trees.composites.Sequence('DSequence')
        iscarrying = IsCarrying('1')
        iscarrying.setup(0, self, 'Food')

        neighhub = NeighbourObjects('2')
        neighhub.setup(0, self, 'Hub')

        drop = CompositeDrop('4')
        drop.setup(0, self, 'Food')

        dseq.add_children([neighhub, drop])

        # Carry branch
        cseq = py_trees.composites.Sequence('CSequence')

        neighsite = NeighbourObjects('5')
        neighsite.setup(0, self, 'Sites')

        neighfood = NeighbourObjects('50')
        neighfood.setup(0, self, 'Food')

        invcarrying = py_trees.meta.inverter(IsCarrying)('8')
        invcarrying.setup(0, self, 'Food')

        carry = CompositeSingleCarry('6')
        carry.setup(0, self, 'Food')

        cseq.add_children([neighsite, neighfood, invcarrying, carry])

        # Locomotion branch

        # Move to site
        siteseq = py_trees.composites.Sequence('SiteSeq')

        sitefound = IsVisitedBefore('7')
        sitefound.setup(0, self, 'Sites')

        gotosite = MoveTowards('9')
        gotosite.setup(0, self, 'Sites')

        siteseq.add_children([sitefound, invcarrying, gotosite])

        # Move to hub
        hubseq = py_trees.composites.Sequence('HubSeq')

        gotohub = MoveTowards('10')
        gotohub.setup(0, self, 'Hub')

        hubseq.add_children([iscarrying, gotohub])

        sitenotfound = py_trees.meta.inverter(IsVisitedBefore)('11')
        sitenotfound.setup(0, self, 'Sites')

        explore = Explore('12')
        explore.setup(0, self)

        randwalk = py_trees.composites.Sequence('Randwalk')
        randwalk.add_children([explore])

        locoselect = py_trees.composites.Selector('Move')
        locoselect.add_children([siteseq, hubseq, explore])
        select = py_trees.composites.Selector('Main')

        select.add_children([dseq, cseq, locoselect])

        self.behaviour_tree = py_trees.trees.BehaviourTree(select)
コード例 #12
0
ファイル: agent.py プロジェクト: foton263/swarm
    def construct_bt(self):
        """Construct BT."""
        # Get the phenotype of the genome and store as xmlstring
        # self.bt.xmlstring = self.xmlstring
        # Drop branch
        # Drop branch
        dseq = py_trees.composites.Sequence('DSequence')
        iscarrying = IsCarrying('IsCarrying_Debris')
        iscarrying.setup(0, self, 'Debris')

        neighhub = NeighbourObjects('NeighbourObjects')
        neighhub.setup(0, self, 'Obstacles')

        drop = CompositeDrop('CompositeDrop_Debris')
        drop.setup(0, self, 'Debris')

        dseq.add_children([neighhub, drop])

        # Carry branch
        cseq = py_trees.composites.Sequence('CSequence')

        neighsite = py_trees.meta.inverter(NeighbourObjects)(
            'NeighbourObjects')
        neighsite.setup(0, self, 'Obstacles')

        neighfood = NeighbourObjects('NeighbourObjects_Debris')
        neighfood.setup(0, self, 'Debris')

        invcarrying = py_trees.meta.inverter(IsCarrying)('IsCarrying_Debris')
        invcarrying.setup(0, self, 'Debris')

        carry = CompositeSingleCarry('CompositeSingleCarry_Debris')
        carry.setup(0, self, 'Debris')

        cseq.add_children([neighsite, neighfood, invcarrying, carry])

        # Locomotion branch

        # Move to site
        siteseq = py_trees.composites.Sequence('SiteSeq')

        sitefound = IsVisitedBefore('IsVisitedBefore')
        sitefound.setup(0, self, 'Obstacles')

        gotosite = MoveTowards('MoveTowards')
        gotosite.setup(0, self, 'Obstacles')

        siteseq.add_children([sitefound, iscarrying, gotosite])

        # Move to hub
        hubseq = py_trees.composites.Sequence('HubSeq')

        gotohub = MoveTowards('MoveTowards_Hub')
        gotohub.setup(0, self, 'Hub')

        hubseq.add_children([iscarrying, gotohub])

        sitenotfound = py_trees.meta.inverter(IsVisitedBefore)(
            'IsVisitedBefore')
        sitenotfound.setup(0, self, 'Obstacles')

        explore = Explore('Explore')
        explore.setup(0, self)

        randwalk = py_trees.composites.Sequence('Randwalk')
        randwalk.add_children([explore])

        locoselect = py_trees.composites.Selector('Move')
        locoselect.add_children([siteseq, explore])
        select = py_trees.composites.Selector('Main')

        select.add_children([dseq, cseq, locoselect])

        self.behaviour_tree = py_trees.trees.BehaviourTree(select)
コード例 #13
0
    def __init__(self, name, model):
        super().__init__(name, model)
        self.location = ()

        self.direction = model.random.rand() * (2 * np.pi)
        self.speed = 2
        self.radius = 3

        self.moveable = True
        self.shared_content = dict()

        root = py_trees.composites.Selector("Selector")
        left_sequence = py_trees.composites.Sequence("LSequence")
        right_sequence = py_trees.composites.Sequence("RSequence")
        hub_sequence = py_trees.composites.RepeatUntilFalse("L1Sequence")

        right_selector = py_trees.composites.Selector("RSelector")
        right1_sequence = py_trees.composites.Sequence("R1Sequence")

        self.blackboard = Blackboard()
        self.blackboard.shared_content = dict()

        name = type(model.hub).__name__
        self.shared_content[name] = {model.hub}

        # self.blackboard.shared_content[
        # type(model.hub).__name__] = [model.hub]

        hub_dnm = NeighbourObjects('5')
        hub_dnm.setup(0, self, 'Hub')

        dmn = DoNotMove('6')
        dmn.setup(0, self)

        low = RandomWalk('7')
        low.setup(0, self)
        # low1 = IsMoveable('8')
        # low1.setup(0, self)
        low2 = Move('9')
        low2.setup(0, self)

        medium = NeighbourObjects('1')
        medium.setup(0, self, 'Sites')

        high = GoTo('2')
        high.setup(0, self, type(model.hub).__name__)

        highm = Move('3')
        highm.setup(0, self)

        high1 = py_trees.meta.inverter(NeighbourObjects)('4')
        high1.setup(0, self, 'Hub')

        hub_sequence.add_children([high, highm, high1])
        left_sequence.add_children([medium, hub_sequence])

        right1_sequence.add_children([hub_dnm, dmn])
        right_sequence.add_children([low, low2])

        right_selector.add_children([right1_sequence, right_sequence])
        root.add_children([left_sequence, right_selector])

        self.behaviour_tree = py_trees.trees.BehaviourTree(root)
コード例 #14
0
ファイル: agent.py プロジェクト: foton263/swarm
    def construct_bt(self):
        """Construct BT."""
        # Get the phenotype of the genome and store as xmlstring
        # self.bt.xmlstring = self.xmlstring
        # Drop branch
        dseq = py_trees.composites.Sequence('DSequence')

        iscarrying = IsInPartialAttached('IsInPartialAttached_Food')
        iscarrying.setup(0, self, 'Food')

        # If near hub and carrying food with other agents drop
        neighhub = NeighbourObjects('NeighbourObjects_Hub')
        neighhub.setup(0, self, 'Hub')

        drop = CompositeDropPartial('CompositeDropPartial_Food')
        drop.setup(0, self, 'Food')

        dseq.add_children([neighhub, drop])

        # Carry branch
        cseq = py_trees.composites.Sequence('CSequence')

        # neighsite = NeighbourObjects('5')
        # neighsite.setup(0, self, 'Sites')
        neighhub = py_trees.meta.inverter(NeighbourObjects)(
            'NeighbourObjects_Hub')
        neighhub.setup(0, self, 'Hub')

        neighfood = NeighbourObjects('NeighbourObjects_Food')
        neighfood.setup(0, self, 'Food')

        invcarrying = py_trees.meta.inverter(IsInPartialAttached)(
            'IsInPartialAttached_Food')
        invcarrying.setup(0, self, 'Food')

        carry = CompositeMultipleCarry('CompositeMultipleCarry_Food')
        carry.setup(0, self, 'Food')

        # Move to hub
        hubseq = py_trees.composites.Sequence('HubSeq')
        # If carrying something to go to hub
        gotohub = MoveTowards('MoveTowards_Hub')
        gotohub.setup(0, self, 'Hub')

        hubseq.add_children([iscarrying, gotohub])

        cseq.add_children([neighhub, neighfood, carry, hubseq])

        # Locomotion branch

        # Move to site
        siteseq = py_trees.composites.Sequence('SiteSeq')
        # If site already found and not carrying anything go to site
        sitefound = IsVisitedBefore('IsVisitedBefore_Sites')
        sitefound.setup(0, self, 'Sites')

        gotosite = MoveTowards('MoveTowards_Sites')
        gotosite.setup(0, self, 'Sites')

        siteseq.add_children([sitefound, invcarrying, gotosite])

        # Do Random walk
        explore = Explore('Explore')
        explore.setup(0, self)

        randwalk = py_trees.composites.Sequence('Randwalk')
        randwalk.add_children([explore])
        # Try to got to site and hub if not explore
        locoselect = py_trees.composites.Selector('Move')
        locoselect.add_children([iscarrying, siteseq, explore])
        # First try to drop then collect or explore
        select = py_trees.composites.Selector('Main')
        select.add_children([dseq, cseq, locoselect])

        self.behaviour_tree = py_trees.trees.BehaviourTree(select)