AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
load_bt.cpp
Go to the documentation of this file.
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
18
19#define INPUT_KEY_PACKAGE "package_name"
20#define INPUT_KEY_FILENAME "filename"
21#define OUTPUT_KEY_DATA "xml_data"
22
24{
25
26class LoadBehaviorTreeAction : public BT::SyncActionNode
27{
28public:
29 using SyncActionNode::SyncActionNode;
30
31 static BT::PortsList providedPorts()
32 {
33 return { BT::InputPort<std::string>(INPUT_KEY_PACKAGE, "Name of the ROS2 package containing the trees file"),
34 BT::InputPort<std::string>(INPUT_KEY_FILENAME, "Name of the trees file (Extension may be omitted)"),
35 BT::OutputPort<std::string>(OUTPUT_KEY_DATA, "{xml_data}",
36 "XML string containing the data for the behavior trees") };
37 }
38
39 BT::NodeStatus tick() final
40 {
41 auto package_name = getInput<std::string>(INPUT_KEY_PACKAGE).value();
42 auto filename = getInput<std::string>(INPUT_KEY_FILENAME).value();
43
44 std::unique_ptr<TreeResource> tree_resource_ptr;
45 try
46 {
47 tree_resource_ptr = std::make_unique<TreeResource>(TreeResource::selectByFileName(filename, package_name));
48 }
50 {
51 return BT::NodeStatus::FAILURE;
52 }
53
54 setOutput<std::string>(OUTPUT_KEY_DATA, tree_resource_ptr->writeTreeToString());
55 return BT::NodeStatus::SUCCESS;
56 }
57};
58
59} // namespace auto_apms_behavior_tree
60
61AUTO_APMS_BEHAVIOR_TREE_REGISTER_NODE(auto_apms_behavior_tree::LoadBehaviorTreeAction)
#define AUTO_APMS_BEHAVIOR_TREE_REGISTER_NODE(type)
Macro for registering a behavior tree node plugin.
Definition node.hpp:30
#define INPUT_KEY_FILENAME
Definition load_bt.cpp:20
#define OUTPUT_KEY_DATA
Definition load_bt.cpp:21
#define INPUT_KEY_PACKAGE
Definition load_bt.cpp:19
static TreeResource selectByFileName(const std::string &file_name, const std::string &package_name="")