py_trees
py_trees copied to clipboard
Support for Copying Behaviors?
I'd like to be able to use the same behavior in multiple parts of a tree (e.g., calling a ROS service that toggles some robot functionality on/off multiple times in the same tree). #281 disallowed this, because it may be problematic if behaviors maintain state.
I don't mind re-creating another version of the same behavior, but I want to do so in a way that maximizes code re-use. I see two options:
- Put the logic for creating the behavior into a helper function, and call it every time I want that behavior in the tree.
- Create the behavior once, and copy/clone it when I want to re-use it.
In terms of the second option, I was wondering:
- Would
copy.deepcopy
work on a behavior? I imagine not, because things like theparent
attribute would also be copied over, which is what gives rise to the error in #281 . - If not, what do you think of adding support for copying/cloning a behavior? Such a function would ideally copy the functional attributes of the behavior (e.g., any attributes defined by the subclass, any children it has) but not copy the attributes that are assigned when it is put into another tree.