### Install Dependencies and Run Demos (Python) Source: https://github.com/splintered-reality/py_trees/blob/devel/README.md Installs project dependencies using poetry and demonstrates how to explore various py-trees demos, such as blackboard, context switching, and display modes. ```bash # Install Dependencies (docker) zen@py_trees:/workspaces/py_trees$ poetry install # Explore the demos (docker) zen@py_trees:/workspaces/py_trees$ poetry shell (py-trees-py3.10) (docker) zen@py_trees:/workspaces/py_trees$ py-trees-demo-- py-trees-demo-action-behaviour py-trees-demo-context-switching py-trees-demo-logging py-trees-demo-behaviour-lifecycle py-trees-demo-display-modes py-trees-demo-pick-up-where-you-left-off py-trees-demo-blackboard py-trees-demo-dot-graphs py-trees-demo-selector py-trees-demo-blackboard-namespaces py-trees-demo-either-or py-trees-demo-sequence py-trees-demo-blackboard-remappings py-trees-demo-eternal-guard py-trees-demo-tree-stewardship (py-trees-py3.10) (docker) zen@py_trees:/workspaces/py_trees$ py-trees-demo-blackboard ... (py-trees-py3.10) (docker) zen@py_trees:/workspaces/py_trees$ exit ``` -------------------------------- ### Tree Setup and Shutdown Methods Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Illustrates the standalone setup() method for unmanaged trees and the shutdown() method for cleaning up tree resources. These methods are essential for managing the lifecycle of behavior trees. ```python from py_trees import setup, Behaviour # Conceptual usage: # class MyBehaviour(Behaviour): # def setup(self, **kwargs): # # Initialization logic # return True # # def shutdown(self, **kwargs): # # Cleanup logic # pass # tree = BehaviourTree(root) # setup(tree) # tree.shutdown() ``` -------------------------------- ### py-trees-demo-behaviour-lifecycle Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates the lifecycle of a behaviour in py-trees. This includes setup, execution, and teardown phases of a behaviour. ```python import py_trees def py_trees_demo_behaviour_lifecycle(): """Demo the lifecycle of a behaviour.""" # Example of a behaviour with lifecycle methods class MyLifecycleBehaviour(py_trees.behaviours.Behaviour): def __init__(self, name): super(MyLifecycleBehaviour, self).__init__(name) self.logger.info("__init__") def setup(self, **kwargs): self.logger.info("setup") def initialise(self): self.logger.info("initialise") def update(self): self.logger.info("update") return py_trees.common.Status.SUCCESS def terminate(self, new_status): self.logger.info("terminate") return super(MyLifecycleBehaviour, self).terminate(new_status) root = MyLifecycleBehaviour("LifecycleRoot") # In a real scenario, you would tick the tree # py_trees.tick_tree(root) print("Behaviour lifecycle demo setup complete.") if __name__ == '__main__': py_trees_demo_behaviour_lifecycle() ``` -------------------------------- ### Generate Documentation Source: https://github.com/splintered-reality/py_trees/blob/devel/DEVELOPING.md Instructions for installing documentation dependencies and building the HTML documentation for the py_trees project. ```shell # Install dependencies $ poetry install --with docs # Build $ poetry run make -C docs html ``` -------------------------------- ### py_trees.behaviour.Behaviour.setup() Changes Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Highlights the changes in the `setup()` method for `py_trees.behaviour.Behaviour`, including the removal of boolean return values and timeout parameters. ```python import py_trees # class MyBehaviour(py_trees.behaviour.Behaviour): # def __init__(self, name): # super(MyBehaviour, self).__init__(name) # # def setup(self, **kwargs): # # No boolean return value expected # # Timeouts are handled by BehaviourTree # print("Setting up behaviour...") # return py_trees.common.Status.SUCCESS ``` -------------------------------- ### Py_trees Tree Pre/Post Handlers Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Adds pre/post handlers to trees after setup, providing robustness in case of setup failure. ```python [trees] add pre/post handlers after setup, just in case setup fails ``` -------------------------------- ### Skeleton Behaviour Example Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/behaviours.rst A basic skeleton for creating custom behaviours by subclassing the py_trees.behaviour.Behaviour class. This example demonstrates the fundamental structure required for a new behaviour. ```python import py_trees class MyBehaviour(py_trees.behaviour.Behaviour): def __init__(self, name): super(MyBehaviour, self).__init__(name) self.description = "My custom behaviour" def setup(self, unused_subscriber=None): # Setup any resources required for execution return def initialise(self): # Reset behaviour variables for execution return def update(self): # The core logic of the behaviour # Must return py_trees.common.Status.SUCCESS, py_trees.common.Status.FAILURE, or py_trees.common.Status.RUNNING return py_trees.common.Status.SUCCESS def terminate(self, new_status): # Cleanup resources return ``` -------------------------------- ### Behaviour Design Guidelines - py_trees Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/the_crazy_hospital.rst Guidelines for designing behaviours in py_trees. Emphasizes minimal constructors, deferred initialization to setup(), and lightweight update() methods. Recommends focused behaviour scope and using subtrees for complex concepts. ```python class MyBehaviour(py_trees.behaviour.Behaviour): def __init__(self, name): super(MyBehaviour, self).__init__(name) # Minimal constructor def setup(self, **kwargs): # Hardware or runtime specific initialization pass def update(self): # Light and non-blocking logic return py_trees.common.Status.SUCCESS ``` -------------------------------- ### Py_trees Napoleon Style Documentation Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Updates documentation to follow the Napoleon style guide and enhances Sphinx documentation. ```docs [docs] rolled over with napolean style [docs] sphinx documentation updated ``` -------------------------------- ### Skeleton Tree Example Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/trees.rst Demonstrates the basic skeleton of a behaviour tree, including automatic tick-tock functionality and methods for ticking and interrupting the tree. ```python import py_trees def skeleton_tree(): # Create a simple root node root = py_trees.decorators.Successer("Root") # Create a BehaviourTree instance behaviour_tree = py_trees.trees.BehaviourTree(root) # Tick the tree for a specific number of iterations behaviour_tree.tick_tock(n_iterations=5) # Or tick indefinitely and interrupt later # behaviour_tree.tick_tock() # ... later ... # behaviour_tree.interrupt() # Or manually tick the tree # behaviour_tree.tick() skeleton_tree() ``` -------------------------------- ### Py_trees Documentation Updates Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Includes updates to documentation, such as disabling color during builds, sidebar enhancements, and removing project installation requirements. ```docs [docs] disable colour when building [docs] sidebar headings [docs] dont require project installation ``` -------------------------------- ### PyTrees DOT Graph Rendering Utility Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/visualisation.rst Renders a DOT graph from a behaviour tree to an image file (e.g., PNG, SVG). This utility requires the Graphviz 'dot' executable to be installed and in the system's PATH. ```python import py_trees # Assuming 'root' is the root node of your behaviour tree py_trees.display.render_dot_tree(root, 'tree.png') ``` -------------------------------- ### Publish Package to PyPI Source: https://github.com/splintered-reality/py_trees/blob/devel/DEVELOPING.md Commands to configure Poetry with PyPI credentials and publish the package. ```shell $ poetry config http-basic.pypi ${POETRY_HTTP_BASIC_PYPI_USERNAME} ${POETRY_HTTP_BASIC_PYPI_PASSWORD} $ poetry publish ``` -------------------------------- ### py_trees Composites: Sequences and Selectors with and without Memory Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Explains the new functionality in py_trees composites (Sequences and Selectors) that support both 'with memory' and 'without memory' paradigms. 'Without memory' starts ticking with the first child, while 'with memory' attempts to start with the current child. This change brings symmetry and enables new practical use cases. ```python Without Memory - ticking starts with the **first** child With Memory - ticking attempts to start with the **current** child ``` -------------------------------- ### SnapshotVisitor Blackboard Tracking Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Demonstrates how SnapshotVisitor tracks blackboard clients and keys, contrasting with previous implementations. This snippet highlights the refactoring of visitor patterns for better blackboard management. ```python class SnapshotVisitor: def __init__(self): self.visited_blackboard_client_ids = set() self.visited_blackboard_keys = set() # Previously tangled in DisplaySnapshotVisitor: # display_snapshot_visitor.visited.keys() # blackboard client uuid's (also behaviour uuid's), typing.Set[uuid.UUID] # display_snapshot_visitor.visited_keys # blackboard keys, typing.Set[str] # Now in SnapshotVisitor: # snapshot_visitor.visited_blackboard_client_ids # typing.Set[uuid.UUID] # snapshot_visitor.visited_blackboard_keys # typing.Set[str] ``` -------------------------------- ### Pick Up Where You Left Off Demo Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst This Python script demonstrates the 'pickup where you left off' idiom using the py-trees library. It's designed to show how to resume a behavior tree execution from a previous state. ```python import py_trees import py_trees.demos def pick_up_where_you_left_off(): """Demo the 'pickup where you left off' idiom.""" # Create a simple behavior tree root = py_trees.behaviours.Sequence(name='Root') action = py_trees.behaviours.Success(name='Action') root.add_children([action]) # Initialize the tree tree = py_trees.trees.BehaviourTree(root) # Simulate running the tree multiple times, saving and restoring state for i in range(3): print(f"\n--- Tick {i+1} ---") tree.tick() print(f"Tree state: {tree.root.status}") # In a real scenario, you would save the tree state here # For demonstration, we'll just show the concept if i < 2: print("Simulating saving state...") # Simulate restoring state for the next tick print("Simulating restoring state...") if __name__ == '__main__': pick_up_where_you_left_off() ``` -------------------------------- ### py-trees-demo-blackboard-remappings Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates blackboard key remappings in py-trees. This allows for aliasing keys to simplify access or manage different naming conventions. ```python import py_trees def py_trees_demo_blackboard_remappings(): """Demo blackboard key remappings.""" blackboard = py_trees.blackboard.Blackboard() # Example of setting up remappings blackboard.set_remappings({ "old_key": "new_key", "another_old_key": "ns1.new_key" }) blackboard.set("new_key", "remapped_value") blackboard.set("ns1.new_key", "another_remapped_value") value1 = blackboard.get("old_key") value2 = blackboard.get("another_old_key") print(f"Remapped value 1: {value1}") print(f"Remapped value 2: {value2}") print("Blackboard remappings demo setup complete.") if __name__ == '__main__': py_trees_demo_blackboard_remappings() ``` -------------------------------- ### Pre-tick Handler Example Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/trees.rst Illustrates how to implement and add a pre-tick handler to a BehaviourTree. This handler executes just before the tree is ticked, useful for logging or introspection. ```python import py_trees def my_pre_tick_handler(tree): print("Executing pre-tick handler...") # Assuming 'root' is a defined behaviour tree root node # behaviour_tree = py_trees.trees.BehaviourTree(root) # behaviour_tree.add_pre_tick_handler(my_pre_tick_handler) ``` -------------------------------- ### Py_trees Blackboard Initialization Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Permits initialization of subscriber2blackboard behaviors and introduces blackboard watchers. ```python [blackboard] permit init of subscriber2blackboard behaviours [blackboard] watchers ``` -------------------------------- ### Namespaced Blackboard Clients and Key Registration Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Illustrates the new approach to managing blackboard clients with namespaces. This allows for better organization and isolation of blackboard variables, especially in complex systems. ```python import py_trees # Previously, a single blackboard client exists per behaviour # Now, no blackboard client on construction, instead attach on demand: self.blackboard = self.attach_blackboard_client(name="Foo") self.parameters = self.attach_blackboard_client( name="FooParams", namespace="parameters_foo_" ) self.state = self.attach_blackboard_client( name="FooState", namespace="state_foo_" ) # create a local key 'speed' that maps to 'state_foo_speed' on the blackboard self.state.register_key(key="speed", access=py_trees.common.Access.WRITE) self.state.speed = 30.0 ``` -------------------------------- ### PyTrees Composite Parallel Initialization Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Demonstrates the recommended way to initialize a PyTrees Parallel composite using keyword arguments for clarity and future-proofing against signature changes. This approach enhances code readability and reduces the risk of bugs during refactoring or library upgrades. ```python parallel = py_trees.composite.Parallel( name="Parallel", policy=py_trees.common.ParallelPolicy.SuccessOnAll() ) ``` -------------------------------- ### Feedback Message Update Example Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/behaviours.rst Demonstrates how to update the feedback message within a behaviour's lifecycle, typically in the update method to signal significant events or status changes. ```python self.feedback_message = "Task completed successfully." # or self.feedback_message = "Encountered an error: {}".format(error_details) ``` -------------------------------- ### py-trees-demo-blackboard-namespaces Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates blackboard namespacing concepts in py-trees. This allows for organizing blackboard keys into hierarchical structures. ```python import py_trees def py_trees_demo_blackboard_namespaces(): """Demo blackboard namespacing concepts.""" blackboard = py_trees.blackboard.Blackboard() # Example of using namespaces with blackboard.namespace("ns1"): blackboard.set("key1", "value1") with blackboard.namespace("ns1.ns2"): blackboard.set("key2", "value2") value1 = blackboard.get("ns1.key1") value2 = blackboard.get("ns1.ns2.key2") print(f"Namespace value 1: {value1}") print(f"Namespace value 2: {value2}") print("Blackboard namespacing demo setup complete.") if __name__ == '__main__': py_trees_demo_blackboard_namespaces() ``` -------------------------------- ### py-trees-demo-blackboard Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates blackboard set/get operations and related behaviours in py-trees. This snippet shows how to use the blackboard for inter-behaviour communication. ```python import py_trees def py_trees_demo_blackboard(): """Demo blackboard set/get and related behaviours.""" blackboard = py_trees.blackboard.Blackboard() # Example of setting and getting values from the blackboard blackboard.set("my_key", "my_value") value = blackboard.get("my_key") print(f"Blackboard value: {value}") # Example of a behaviour using the blackboard class BlackboardReader(py_trees.behaviours.Behaviour): def __init__(self, name, key): super(BlackboardReader, self).__init__(name) self.key = key def update(self): value = self.blackboard.get(self.key) if value: print(f"Read from blackboard: {self.key}={value}") return py_trees.common.Status.SUCCESS return py_trees.common.Status.FAILURE root = py_trees.composites.Sequence("Root") reader = BlackboardReader("Reader", "my_key") root.add_children([reader]) # In a real scenario, you would tick the tree # py_trees.tick_tree(root) print("Blackboard demo setup complete.") if __name__ == '__main__': py_trees_demo_blackboard() ``` -------------------------------- ### SHA256 Hashes for py_trees Dependencies Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/requirements.txt This snippet lists various SHA256 hashes associated with the py_trees project's dependencies. These hashes are used to verify the integrity of downloaded packages, ensuring that the correct and untampered versions are installed. ```text --hash=sha256:085fd3201e7b12809f9e6e9bc1e5c96a368c8523fad5afb02afe3c051ae4afcc --hash=sha256:090376d812fb6ac5f171e5938e82e7f2d7adc2b629101cec0db8b267815c85e2 --hash=sha256:0b462104ba25f1ac006fdab8b6a01ebbfbce9ed37fd37fd4acd70c67c973e460 --hash=sha256:137678c63c977754abe9086a3ec011e8fd985ab90631145dfb9294ad09c102a7 --hash=sha256:1bea30e9bf331f3fef67e0a3877b2288593c98a21ccb2cf29b74c581a4eb3af0 --hash=sha256:22152d00bf4a9c7c83960521fc558f55a1adbc0631fbb00a9471e097b19d72e1 --hash=sha256:22731d79ed2eb25059ae3df1dfc9cb1546691cc41f4e3130fe6bfbc3ecbbecfa --hash=sha256:2298c859cfc5463f1b64bd55cb3e602528db6fa0f3cfd568d3605c50678f8f03 --hash=sha256:28057e985dace2f478e042eaa15606c7efccb700797660629da387eb289b9323 --hash=sha256:2e7821bffe00aa6bd07a23913b7f4e01328c3d5cc0b40b36c0bd81d362faeb65 --hash=sha256:2ec4f2d48ae59bbb9d1f9d7efb9236ab81429a764dedca114f5fdabbc3788013 --hash=sha256:340bea174e9761308703ae988e982005aedf427de816d1afe98147668cc03036 --hash=sha256:40627dcf047dadb22cd25ea7ecfe9cbf3bbbad0482ee5920b582f3809c97654f --hash=sha256:40dfd3fefbef579ee058f139733ac336312663c6706d1163b82b3003fb1925c4 --hash=sha256:4cf06cdc1dda95223e9d2d3c58d3b178aa5dacb35ee7e3bbac10e4e1faacb419 --hash=sha256:50c42830a633fa0cf9e7d27664637532791bfc31c731a87b202d2d8ac40c3ea2 --hash=sha256:55f44b440d491028addb3b88f72207d71eeebfb7b5dbf0643f7c023ae1fba619 --hash=sha256:608e7073dfa9e38a85d38474c082d4281f4ce276ac0010224eaba11e929dd53a --hash=sha256:63ba06c9941e46fa389d389644e2d8225e0e3e5ebcc4ff1ea8506dce646f8c8a --hash=sha256:65608c35bfb8a76763f37036547f7adfd09270fbdbf96608be2bead319728fcd --hash=sha256:665a36ae6f8f20a4676b53224e33d456a6f5a72657d9c83c2aa00765072f31f7 --hash=sha256:6d6607f98fcf17e534162f0709aaad3ab7a96032723d8ac8750ffe17ae5a0666 --hash=sha256:7313ce6a199651c4ed9d7e4cfb4aa56fe923b1adf9af3b420ee14e6d9a73df65 --hash=sha256:7668b52e102d0ed87cb082380a7e2e1e78737ddecdde129acadb0eccc5423859 --hash=sha256:7df70907e00c970c60b9ef2938d894a9381f38e6b9db73c5be35e59d92e06625 --hash=sha256:7e007132af78ea9df29495dbf7b5824cb71648d7133cf7848a2a5dd00d36f9ff --hash=sha256:835fb5e38fd89328e9c81067fd642b3593c33e1e17e2fdbf77f5676abb14a156 --hash=sha256:8bca7e26c1dd751236cfb0c6c72d4ad61d986e9a41bbf76cb445f69488b2a2bd --hash=sha256:8db032bf0ce9022a8e41a22598eefc802314e81b879ae093f36ce9ddf39ab1ba --hash=sha256:99625a92da8229df6d44335e6fcc558a5037dd0a760e11d84be2260e6f37002f --hash=sha256:9cad97ab29dfc3f0249b483412c85c8ef4766d96cdf9dcf5a1e3caa3f3661cf1 --hash=sha256:a4abaec6ca3ad8660690236d11bfe28dfd707778e2442b45addd2f086d6ef094 --hash=sha256:a6e40afa7f45939ca356f348c8e23048e02cb109ced1eb8420961b2f40fb373a --hash=sha256:a6f2fcca746e8d5910e18782f976489939d54a91f9411c32051b4aab2bd7c513 --hash=sha256:a806db027852538d2ad7555b203300173dd1b77ba116de92da9afbc3a3be3eed --hash=sha256:abcabc8c2b26036d62d4c746381a6f7cf60aafcc653198ad678306986b09450d --hash=sha256:b8526c6d437855442cdd3d87eede9c425c4445ea011ca38d937db299382e6fa3 --hash=sha256:bb06feb762bade6bf3c8b844462274db0c76acc95c52abe8dbed28ae3d44a147 --hash=sha256:c0a33bc9f02c2b17c3ea382f91b4db0e6cde90b63b296422a939886a7a80de1c --hash=sha256:c4a549890a45f57f1ebf99c067a4ad0cb423a05544accaf2b065246827ed9603 --hash=sha256:ca244fa73f50a800cf8c3ebf7fd93149ec37f5cb9596aa8873ae2c1d23498601 --hash=sha256:cf877ab4ed6e302ec1d04952ca358b381a882fbd9d1b07cccbfd61783561f98a --hash=sha256:d9d971ec1e79906046aa3ca266de79eac42f1dbf3612a05dc9368125952bd1a1 --hash=sha256:da25303d91526aac3672ee6d49a2f3db2d9502a4a60b55519feb1a4c7714e07d --hash=sha256:e55e40ff0cc8cc5c07996915ad367fa47da6b3fc091fdadca7f5403239c5fec3 --hash=sha256:f03a532d7dee1bed20bc4884194a16160a2de9ffc6354b3878ec9682bb623c54 --hash=sha256:f1cd098434e83e656abf198f103a8207a8187c0fc110306691a2e94a78d0abb2 --hash=sha256:f2bfb563d0211ce16b63c7cb9395d2c682a23187f54c3d79bfec33e6705473c6 --hash=sha256:f8ffb705ffcf5ddd0e80b65ddf7bed7ee4f5a441ea7d3419e861a12eaf41af58 ``` -------------------------------- ### Visitor Implementation and Usage Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/trees.rst Demonstrates how to add DebugVisitor and SnapshotVisitor to a BehaviourTree and how to use the collected snapshot information to display an ASCII representation of the tree. ```python import py_trees import py_trees.visitors import py_trees.display # Assuming 'root' is a defined behaviour tree root node # behaviour_tree = py_trees.trees.BehaviourTree(root) # Add DebugVisitor for logging # behaviour_tree.visitors.append(py_trees.visitors.DebugVisitor()) # Add SnapshotVisitor to collect runtime data # snapshot_visitor = py_trees.visitors.SnapshotVisitor() # behaviour_tree.visitors.append(snapshot_visitor) # Tick the tree # behaviour_tree.tick() # Generate and print ASCII tree with snapshot information # ascii_tree = py_trees.display.ascii_tree( # behaviour_tree.root, # snapshot_information=snapshot_visitor # ) # print(ascii_tree) ``` -------------------------------- ### Run Formatter, Tests, and Linters (Python) Source: https://github.com/splintered-reality/py_trees/blob/devel/README.md Executes various development tasks including code formatting, running tests across different Python versions (e.g., py310, py312), and linting using tox. ```bash # Run the Formatter, Tests, Linters and Mypy (docker) zen@py_trees:/workspaces/py_trees$ poetry run tox -l py310 py312 format check mypy310 mypy312 (docker) zen@py_trees:/workspaces/py_trees$ poetry run tox -e format ... (docker) zen@py_trees:/workspaces/py_trees$ poetry run tox -e py310 ... (docker) zen@py_trees:/workspaces/py_trees$ poetry run tox -e check ... ``` -------------------------------- ### py-trees-demo-tree-stewardship Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates tree stewardship in py-trees. This involves managing the lifecycle and execution of a behaviour tree, potentially with multiple stewards. ```python import py_trees def py_trees_demo_tree_stewardship(): """Demo tree stewardship.""" # Example of setting up a tree and a steward to manage it root = py_trees.composites.Sequence("Root Sequence") action_node = py_trees.behaviours.Action("MyAction", lambda: print("Action executed!")) root.add_children([action_node]) steward = py_trees.trees.BehaviourTree(root) # In a real scenario, you would use the steward to tick the tree # steward.tick() print("Tree stewardship demo setup complete.") if __name__ == '__main__': py_trees_demo_tree_stewardship() ``` -------------------------------- ### py_trees: Development Instructions Consolidation Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Notes the consolidation of development instructions within the py_trees README file for improved clarity and ease of use. ```python [readme] consolidate development instructions ``` -------------------------------- ### py_trees.blackboard.Client Documentation Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/blackboards.rst Documentation for the py_trees blackboard client class. This class provides the main interface for users to interact with the blackboard, allowing for data storage and retrieval within the py_trees framework. ```APIDOC py_trees.blackboard.Client: __init__(name='blackboard') Initialises the client. Parameters: name (str): The name of the blackboard client. Defaults to 'blackboard'. set(key, value, overwrite=False) Sets a value on the blackboard. Parameters: key (str): The key to set the value under. value: The value to set. overwrite (bool): Whether to overwrite an existing value. Defaults to False. Returns: bool: True if the value was set successfully, False otherwise. get(key, default=None) Gets a value from the blackboard. Parameters: key (str): The key of the value to retrieve. default: The default value to return if the key is not found. Defaults to None. Returns: The value associated with the key, or the default value if not found. has(key) Checks if a key exists on the blackboard. Parameters: key (str): The key to check. Returns: bool: True if the key exists, False otherwise. delete(key) Deletes a key from the blackboard. Parameters: key (str): The key to delete. Returns: bool: True if the key was deleted successfully, False otherwise. list_keys(filter_string=None) Lists all keys on the blackboard, optionally filtered by a string. Parameters: filter_string (str, optional): A string to filter keys by. Defaults to None. Returns: list: A list of keys matching the filter. interrupt(key) Interrupts a key on the blackboard, typically used for signalling. Parameters: key (str): The key to interrupt. publish(topic, message) Publishes a message to a given topic on the blackboard. Parameters: topic (str): The topic to publish to. message: The message to publish. subscribe(topic, callback) Subscribes to a topic on the blackboard. Parameters: topic (str): The topic to subscribe to. callback (callable): The function to call when a message is received. unsubscribe(topic, callback) Unsubscribes from a topic on the blackboard. Parameters: topic (str): The topic to unsubscribe from. callback (callable): The callback function to remove. ``` -------------------------------- ### Required Blackboard Keys and Verification Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Shows how to register keys as required on the blackboard and subsequently verify their existence. This is crucial for ensuring that necessary data is available before proceeding with operations. ```python import py_trees self.blackboard = self.attach_blackboard_client(name="Foo") self.blackboard.register_key(name="foo", access=py_trees.common.Access.READ, required=True) # ... self.verify_required_keys_exist() # KeyError if any required keys do not yet exist on the blackboard ``` -------------------------------- ### py-trees-demo-selector Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates priority switching in selectors in py-trees. Selectors execute children in order until one succeeds. ```python import py_trees def py_trees_demo_selector(): """Demo priority switching in selectors.""" # Example of a selector executing children in priority order root = py_trees.composites.Selector("Root Selector") # Child 1: Will succeed first success_node = py_trees.behaviours.Successer("FirstSuccess") # Child 2: Will only execute if Child 1 fails failure_node = py_trees.behaviours.Failure("SecondFailure") root.add_children([success_node, failure_node]) # In a real scenario, you would tick the tree # py_trees.tick_tree(root) print("Selector demo setup complete.") if __name__ == '__main__': py_trees_demo_selector() ``` -------------------------------- ### py-trees-demo-dot-graphs Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates generating DOT graphs with varying visibility levels in py-trees. This allows for visualizing the behaviour tree structure. ```python import py_trees def py_trees_demo_dot_graphs(): """Demo dot graphs with varying visibility levels.""" # Example of creating a tree and generating a DOT graph root = py_trees.composites.Sequence("Root Sequence") action_node = py_trees.behaviours.Action("MyAction", lambda: print("Action executed!")) root.add_children([action_node]) # Generate DOT graph string dot_graph = py_trees.display.ascii_tree(root, show_status=True) print("--- ASCII Tree ---") print(dot_graph) # To generate a visual DOT file, you would typically use: # py_trees.display.render_dot_tree(root, 'tree.dot') # and then use graphviz to convert it to an image. print("DOT graph generation demo setup complete.") if __name__ == '__main__': py_trees_demo_dot_graphs() ``` -------------------------------- ### py-trees-demo-sequence Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates sequences in action in py-trees. Sequences execute children in order, and the sequence succeeds only if all children succeed. ```python import py_trees def py_trees_demo_sequence(): """Demo sequences in action.""" # Example of a sequence executing children in order root = py_trees.composites.Sequence("Root Sequence") # Child 1: Succeeds success_node1 = py_trees.behaviours.Successer("FirstSuccess") # Child 2: Succeeds success_node2 = py_trees.behaviours.Successer("SecondSuccess") # Child 3: Succeeds success_node3 = py_trees.behaviours.Successer("ThirdSuccess") root.add_children([success_node1, success_node2, success_node3]) # In a real scenario, you would tick the tree # py_trees.tick_tree(root) print("Sequence demo setup complete.") if __name__ == '__main__': py_trees_demo_sequence() ``` -------------------------------- ### py-trees-demo-context-switching Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates context switching use cases with parallels in py-trees. This involves managing different states or execution contexts within a behaviour tree. ```python import py_trees def py_trees_demo_context_switching(): """Demo context switching use case with parallels.""" # This is a conceptual example. Actual context switching might involve # more complex state management and parallel execution. root = py_trees.composites.Parallel("Root Parallel", children=[ py_trees.behaviours.Successer("Successer 1"), py_trees.behaviours.Successer("Successer 2") ], policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) # In a real scenario, you would tick the tree and manage contexts # py_trees.tick_tree(root) print("Context switching demo setup complete.") if __name__ == '__main__': py_trees_demo_context_switching() ``` -------------------------------- ### py_trees Release History and Compatibility Source: https://github.com/splintered-reality/py_trees/blob/devel/README.md Provides a historical overview of py_trees releases, highlighting significant changes, Python version support, and links to CI/CD status and documentation for each version. This table helps users track project evolution and compatibility. ```APIDOC Project: py_trees Release History: - 2.3.x: Added Python 3.12 support, dropped Python 3.8. - 2.2.x: Introduced Selectors, Sequences (with/without memory). Improved testing, style, and type checking. - 2.1.x: Deprecated Chooser. Performed API housekeeping. - 2.0.x: Introduced Blackboards V2. - 1.2.x: Enabled clean tree shutdowns. Added StatusToBlackboard and EternalGuard. Visitors now have a finalize() method. - 1.1.x: Addressed fixes for setup, tick-tock, and viz. - 1.0.x: Core features: Behaviours, Decorators, Composites, Blackboards, Tree Management, and Viz tools. - 0.y.x: Initial open-source pre-releases. Compatibility and Status: - Python Compatibility: - 3.12: Supported from 2.3.x onwards. - 3.10: Supported from 2.2.x onwards. - 3.8: Supported up to 2.2.x. - 3.6: Supported up to 1.2.x and 2.0.x. - Build Status: - Devel: [![devel-Status][devel-build-status-image]][devel-build-status] - 2.3.x: [![2.3.x-Status][2.3.x-build-status-image]][2.3.x-build-status] - 2.2.x: [![2.2.x-Status][2.2.x-build-status-image]][2.2.x-build-status] - Documentation: - Devel: [![devel-Docs][docs-devel-image]][docs-devel] - 2.3.x: [![2.3.x-Docs][docs-2.3.x-image]][docs-2.3.x] - 2.2.x: [![2.2.x-Docs][docs-2.2.x-image]][docs-2.2.x] - 2.1.x: [![2.1.x-Docs][docs-2.1.x-image]][docs-2.1.x] - 2.0.x: [![2.0.x-Docs][docs-2.0.x-image]][docs-2.0.x] - 1.2.x: [![1.2.x-Docs][docs-1.2.x-image]][docs-1.2.x] External Links: - License: [![license-image]][license] - Python Docs: - 3.12: [Python 3.12 Docs][python312-docs] - 3.10: [Python 3.10 Docs][python310-docs] - 3.8: [Python 3.8 Docs][python38-docs] - 3.6: [Python 3.6 Docs][python36-docs] ``` -------------------------------- ### py_trees.blackboard Module Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/modules.rst Shared data store and related behaviours. ```python import py_trees.blackboard ``` -------------------------------- ### py-trees-demo-logging Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/demos.rst Demonstrates tree logging to JSON files in py-trees. This allows for recording the execution state and history of a behaviour tree. ```python import py_trees import py_trees.logging import os def py_trees_demo_logging(): """Demo tree logging to json files.""" # Example of setting up logging for a behaviour tree root = py_trees.composites.Sequence("Root Sequence") action_node = py_trees.behaviours.Action("MyAction", lambda: print("Action executed!")) root.add_children([action_node]) log_file = "tree_log.json" py_trees.logging.setup_logging(log_file) # In a real scenario, you would tick the tree to generate logs # py_trees.tick_tree(root) print(f"Tree logging demo setup complete. Log file: {log_file}") # Clean up the log file for demonstration purposes # if os.path.exists(log_file): # os.remove(log_file) if __name__ == '__main__': py_trees_demo_logging() ``` -------------------------------- ### py_trees.composites.Parallel Policies Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Demonstrates the new parallel policies available for composite behaviours: `SuccessOnAll` and `SuccessOnSelected`. ```python import py_trees # Example usage: # parallel_behaviour = py_trees.composites.Parallel( # children=[ # py_trees.behaviours.Successer("Child1"), # py_trees.behaviours.Failureder("Child2") # ], # policy=py_trees.common.ParallelPolicy.SuccessOnAll # ) ``` -------------------------------- ### py_trees.behaviours Module Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/modules.rst Library of useful behaviours. ```python import py_trees.behaviours ``` -------------------------------- ### py_trees: Release Documentation and Graphviz Bugfix Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Covers the release documentation for version 2.2.2 and a bugfix related to Graphviz rendering on read-the-docs. ```python [docs] 2.2.x release documentation, bugfix for graphviz on read-the-docs, `#400 `_ ``` -------------------------------- ### Blackboard Client and Global Methods Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Showcases various methods for interacting with the py_trees Blackboard, including unregistering keys, clearing the blackboard, setting values, and unsetting values. These methods are crucial for managing shared data within a behavior tree. ```python from py_trees.blackboard import Blackboard b = Blackboard() # Client unregister_key() b.unregister_key('my_key') # Global clear() b.clear() # Global set() b.set('my_key', 'my_value') # Client unset() b.unset('my_key') ``` -------------------------------- ### Test and Lint Code Source: https://github.com/splintered-reality/py_trees/blob/devel/DEVELOPING.md Commands to auto-format, check style, format, and type-check code using tox. Also includes commands to run tests against Python 3.10. ```shell # Auto-format your code (if using VSCode, install the ufmt extension) $ poetry run tox -e format # Style, Format $ poetry run tox -e check # Type-Check $ poetry run tox -e mypy310 # Tests $ poetry run tox -e py310 ``` -------------------------------- ### py_trees: VSCode Extension Recommendations Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Highlights recommendations for VSCode extensions, particularly devcontainers, to enhance the development experience for py_trees. ```python [vscode] recommend extensions, especially devcontainers ``` -------------------------------- ### py_trees.console Module Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/modules.rst Colour definitions and syntax highlighting for the console. ```python import py_trees.console ``` -------------------------------- ### Tree Design and Tick Rate - py_trees Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/the_crazy_hospital.rst Best practices for designing behaviour trees in py_trees. Suggests stubbing trees with placeholder behaviours, focusing on names and structure, and rendering dot graphs for collaboration. Recommends light pre/post tick handlers and visitors, with a tick-tock rate of 1-500ms for high-level decision making. ```python # Stub out trees with nonsense behaviours for design # Focus on descriptive names, composite types, and render dot graphs # Keep pre/post tick handlers and visitors light # Good tick-tock rate for high-level decision making: 1-500ms ``` -------------------------------- ### Py_trees Initial Behavior Tree Implementation Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Marks the first implementation of behavior trees in Python. ```python a first implementation of behaviour trees in python ``` -------------------------------- ### py_trees.utilities Module Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/modules.rst Assorted utility functions. ```python import py_trees.utilities ``` -------------------------------- ### Py_trees Imposter Behavior Drilling Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Ensures the 'tip()' method correctly drills down into composite behaviors. ```python [imposter] make sure tip() drills down into composites ``` -------------------------------- ### PyTrees Command Line Rendering Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/visualisation.rst Renders behaviour trees from the command line using the 'py-trees-render' program. This is useful for designing trees or auto-rendering DOT graphs for documentation. ```bash # Example: Render a tree defined in a Python script 'my_tree_script.py' # The script must have a function that returns the root node. py-trees-render --module my_tree_script --output-format dot --output-file my_tree.dot ``` -------------------------------- ### py_trees.display Module Source: https://github.com/splintered-reality/py_trees/blob/devel/docs/modules.rst Visualising trees with dot graphs, strings or on stdout. ```python import py_trees.display ``` -------------------------------- ### Py_trees Demo Reorganization Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Reorganizes demo modules for better structure. ```python [demos] re-organised into modules ``` -------------------------------- ### Python Version Compatibility and Support Source: https://github.com/splintered-reality/py_trees/blob/devel/CHANGELOG.rst Details on Python version compatibility, including the dropping of Python 2 support and the transition to Python 3 only. ```APIDOC Python Compatibility: - Python 2 support dropped. - Python 3 only support from version 0.7.0 onwards. - Compatible for ros2 projects from version 0.7.0 onwards. - Maintained Python 2/3 compatibility until version 0.6.0. ```