py_trees icon indicating copy to clipboard operation
py_trees copied to clipboard

Support for Copying Behaviors?

Open amalnanavati opened this issue 1 year ago • 6 comments

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:

  1. Put the logic for creating the behavior into a helper function, and call it every time I want that behavior in the tree.
  2. Create the behavior once, and copy/clone it when I want to re-use it.

In terms of the second option, I was wondering:

  1. Would copy.deepcopy work on a behavior? I imagine not, because things like the parent attribute would also be copied over, which is what gives rise to the error in #281 .
  2. 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.

amalnanavati avatar Aug 30 '23 23:08 amalnanavati