Skip to content

The correct way to set or override the default values #186

@TPODAvia

Description

@TPODAvia

How can I change the default values for options in my custom Leaf class in ROS BT Py?

I'm trying to change the default values of my custom Leaf class that uses COMMON_OPTIONS:

COMMON_OPTIONS = {
    'host': str,          # REST server host, Default value: "localhost"
    'port': int,          # REST server port, Default value: 9898
    'exec_task': bool,    # whether to execute on the server, default: True
    'save_json': bool     # whether the server should save JSON, default: False
}

@define_bt_node(NodeConfig(
    options={**COMMON_OPTIONS},
    inputs={ "error_code": bool, "error_msg": str},
    outputs={"error_code": bool, "error_msg": str},
    max_children=0))

I tried modifying the get_default_value function in helpers.py:

def get_default_value(data_type, ros=False):
    if data_type is type:
        return int
    elif data_type is int:
        return 0
    elif data_type is str:
        return "foo"
    elif data_type is float:
        return 1.2
    elif data_type is bool:
        return False
    ...

However, changing the return values in get_default_value() has no effect on the actual defaults in the behavior tree UI or runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions