splintered-reality / py_trees

Python implementation of behaviour trees.
Other
415 stars 139 forks source link

Unable to get Repeat decorator to work properly #423

Open apoorvcn47 opened 11 months ago

apoorvcn47 commented 11 months ago

I want the node "SetBlackboardValue" to repeat 3 times. But it only runs once and the tree finishes execution. Is there something I am doing wrong here?

################### import py_trees from py_trees.decorators import Repeat

class SetBlackboardValue(py_trees.behaviour.Behaviour): def init(self, name): super().init(name)

def update(self):
    print("Setting Blackboard Value")
    return py_trees.common.Status.SUCCESS

def create_behavior_tree(): root = py_trees.composites.Sequence("Behavior Tree", False)

repeat_behavior = Repeat(
    name="Repeat",
    child=SetBlackboardValue("Set Blackboard Value"),
    num_success=3  # Set the number of times to repeat the node
)

root.add_child(repeat_behavior)

return root

def main(): behavior_tree = create_behavior_tree() tree = py_trees.trees.BehaviourTree(behavior_tree)

try:
    print("Behavior Tree Execution:")
    tree.setup(timeout=15)
    tree.tick()
        # pass
    # while tree.tick():
    #     pass
finally:
    print("Behavior Tree Finished")

if name == "main": main()