FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow to set server_name/service_name in RegisterRosAction/RegisterRosService by panwauu · Pull Request #16 · BehaviorTree/BehaviorTree.ROS · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .h  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 15 additions & 3 deletions include/behaviortree_ros/bt_action_node.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,22 @@ class RosActionNode : public BT::ActionNodeBase
template <class DerivedT> static
void RegisterRosAction(BT::BehaviorTreeFactory& factory,
const std::string& registration_ID,
ros::NodeHandle& node_handle)
ros::NodeHandle& node_handle,
const std::string& default_server_name = {} )
{
NodeBuilder builder = [&node_handle](const std::string& name, const NodeConfiguration& config) {
return std::make_unique<DerivedT>(node_handle, name, config );
NodeBuilder builder = [&node_handle, default_server_name](const std::string& name, const NodeConfiguration& config) {
auto server_name_port = config.input_ports.find("server_name");
if (server_name_port != config.input_ports.end() && !server_name_port->second.empty()) {
return std::make_unique<DerivedT>(node_handle, name, config );
}

if (!default_server_name.empty()) {
auto new_config = config;
new_config.input_ports["server_name"] = default_server_name;
return std::make_unique<DerivedT>(node_handle, name, new_config );
}

throw std::runtime_error("server_name not given as port or default in RegisterRosAction");
};

TreeNodeManifest manifest;
Expand Down
18 changes: 15 additions & 3 deletions include/behaviortree_ros/bt_service_node.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,22 @@ class RosServiceNode : public BT::SyncActionNode
template <class DerivedT> static
void RegisterRosService(BT::BehaviorTreeFactory& factory,
const std::string& registration_ID,
ros::NodeHandle& node_handle)
ros::NodeHandle& node_handle,
const std::string& default_service_name = {} )
{
NodeBuilder builder = [&node_handle](const std::string& name, const NodeConfiguration& config) {
return std::make_unique<DerivedT>(node_handle, name, config );
NodeBuilder builder = [&node_handle, default_service_name](const std::string& name, const NodeConfiguration& config) {
auto service_name_port = config.input_ports.find("service_name");
if (service_name_port != config.input_ports.end() && !service_name_port->second.empty()) {
return std::make_unique<DerivedT>(node_handle, name, config );
}

if (!default_service_name.empty()) {
auto new_config = config;
new_config.input_ports["service_name"] = default_service_name;
return std::make_unique<DerivedT>(node_handle, name, new_config );
}

throw std::runtime_error("service_name not given as port or default in RegisterRosService");
};

TreeNodeManifest manifest;
Expand Down
10 changes: 4 additions & 6 deletions test/test_bt.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,13 @@ RosActionNode<behaviortree_ros::FibonacciAction>(handle, name, conf) {}
<root >
<BehaviorTree>
<Sequence>
<AddTwoInts service_name = "add_two_ints"
first_int = "3" second_int = "4"
<AddTwoInts first_int = "3" second_int = "4"
sum = "{add_two_result}" />
<PrintValue message="{add_two_result}"/>

<RetryUntilSuccessful num_attempts="4">
<Timeout msec="300">
<Fibonacci server_name="fibonacci" order="5"
result="{fibonacci_result}" />
<Fibonacci order="5" result="{fibonacci_result}" />
</Timeout>
</RetryUntilSuccessful>
<PrintValue message="{fibonacci_result}"/>
Expand All @@ -186,8 +184,8 @@ int main(int argc, char **argv)
BehaviorTreeFactory factory;

factory.registerNodeType<PrintValue>("PrintValue");
RegisterRosService<AddTwoIntsAction>(factory, "AddTwoInts", nh);
RegisterRosAction<FibonacciServer>(factory, "Fibonacci", nh);
RegisterRosService<AddTwoIntsAction>(factory, "AddTwoInts", nh, "add_two_ints");
RegisterRosAction<FibonacciServer>(factory, "Fibonacci", nh, "fibonacci");

auto tree = factory.createTreeFromText(xml_text);

Expand Down

Back | FazBrowse Home | New Git URL