splintered-reality / py_trees

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

Clarification on Recommended Usage of Blackboard #429

Open songyuc opened 7 months ago

songyuc commented 7 months ago

Hello guys,

I am currently working with py_trees and I'm seeking some clarification on best practices for using the blackboard feature. I have previously used a basic approach for blackboard usage, which involves directly setting and getting values on the blackboard. Here's a brief example of what I've done:

import py_trees

def example():
    # Creating a blackboard instance
    blackboard = py_trees.blackboard.Blackboard()

    # Setting data
    blackboard.set("robot_battery_level", 100)

    # Getting data
    battery_level = blackboard.get("robot_battery_level")
    print(f"Robot battery level: {battery_level}")

if __name__ == '__main__':
    example()

While this method works for basic scenarios, I am aware that py_trees also offers more sophisticated mechanisms like using the py_trees.blackboard.Client class for managing blackboard access. I would like to know if the approach I am using is in line with the recommended practices, or if it's more advisable to use the Client class for blackboard interactions, especially in more complex behavior trees.

Any guidance or clarification you can provide on this matter would be greatly appreciated. I am especially interested in understanding the best practices for blackboard usage in py_trees to ensure efficient and effective implementation in my projects.

Thank you for your time and assistance.

Best regards, Yucheng Song

CleanBandit5595 commented 6 months ago

I think the Client API is useful when passing a specific namespace to be a client of. Then you only need to pass the relative blackboard key name. This way you can organize the blackboard better with some behaviours only referencing some specific namespaces of the blackboard. However, I would also very much appreciate more best practices for blackboard usage, and py_trees in general.