Skip to content

Behavior Tree Tutorial 2.2 OptionWirings

heppner edited this page Mar 18, 2022 · 1 revision

WARNING DEPRECTATED
Optionwirings have been Removed from the Library and are not needed anymore. This page will remain in case you stumble across them.
WARNING DEPRECTATED

As we now have the ability to change the Type of values, we need to make sure that the input values are also updated accordingly when we change the type, especially in the editor. OptionWirings are used to do this.

An easy example, the Constant-node from the standard library

The constant.Constant node is a very simple example of a ros_bt_py Leaf node which uses the OptionWiring for the constand value:

from ros_bt_py_msgs.msg import Node as NodeMsg

from ros_bt_py.node import Leaf, define_bt_node
from ros_bt_py.node_config import NodeConfig, OptionRef


@define_bt_node(NodeConfig(
    version='0.9.0',
    options={'constant_type': type,
             'constant_value': OptionRef('constant_type')},
    inputs={},
    outputs={'constant': OptionRef('constant_type')},
    max_children=0,
    option_wirings=[{'source': 'constant_type', 'target': 'constant_value'}],
    tags=['constant', 'value', 'variable']))
class Constant(Leaf):
    """Provide a set value as an output

Useful to provide parameters to Subtrees."""
    def _do_setup(self):
        pass

    def _do_tick(self):
        self.outputs['constant'] = self.options['constant_value']
        return NodeMsg.SUCCEEDED

    def _do_shutdown(self):
        pass

    def _do_reset(self):
        return NodeMsg.IDLE

    def _do_untick(self):
        return NodeMsg.IDLE

    # Uncomment this if your node provides a utility calculation
    #
    # def _do_calculate_utility(self):
    #     pass

As before we see the familiar NodeConfig and do functions. But the Optionwiring helps to keep track of the relationship between the type and the value set to this. So when the constant type is changed from int to float, the type of the constant_value is immediately updated. This prevents any type mismatch and allows easy initialization. Also note the tags field which is used to enable an easier lookup of the nodes.Also, the Description of the node is set with the Class.

Editor Based input changes

The optionwiring was an attempt to homogenize the update of options. Another approach that was or is currently used is to explicitly state the exceptions in the web editor component. The renderSearchResults(results, key, onNewValue) function in the component.js class (currently line 5587) is responsible for this by chcecking the individual nodeClass and node package:

if ( (this.props.nodeClass === 'Service' || this.props.nodeClass === 'ServiceInput') && this.props.module === 'ros_bt_py.nodes.service')

So if you create a new class and the automatic fill of types is not working anymore, check here to include your node in the auto filling.

Clone this wiki locally