BehaviorTree / BehaviorTree.ROS2

BehaviorTree.CPP utilities to work with ROS2
Apache License 2.0
144 stars 59 forks source link

Defining default_port_value for ROS2 plugins #69

Closed marj3220 closed 4 months ago

marj3220 commented 4 months ago

TL:DR How can the default_port_value of a ROS2 BT Node be set when using the new plugin architecture?

Context

Normally a ROS2 BT node would be set this way:

// in main()
  BehaviorTreeFactory factory;

  auto node = std::make_shared<rclcpp::Node>("fibonacci_action_client");
  // provide the ROS node and the name of the action service
  RosNodeParams params; 
  params.nh = node;
  params.default_port_value = "fibonacci";
  factory.registerNodeType<FibonacciAction>("Fibonacci", params);

Problem when using macro from BT.CPP:

Using the bt_factory.h (BT.CPP) for creating a non-ROS plugin is straightforward, but when adding ROS2 necessities the ROS node goes out of scope.

Code:

image

Result:

image

Problem when using macro from BT.ROS2:

Inversly, when using the plugins.hpp (BT.ROS2) macro, I can't find how to set the params:

Code:

image

Result:

image

So how should a ROS2 plugin be set with its params?

Thank you in advance!

marj3220 commented 4 months ago

As pointed out by @MarqRazz:

BT_REGISTER_ROS_NODES(factory, params)
{
  BT::RosNodeParams my_params(params);
  my_params.default_port_value = "TopicName";
  my_params.server_timeout = std::chrono::milliseconds(5000);
  factory.registerNodeType<SomeBehavior>("SomeBehavior", my_params);
}