19#include "auto_apms_behavior_tree/executor/executor_base.hpp"
20#include "auto_apms_behavior_tree/standard_nodes.hpp"
21#include "auto_apms_behavior_tree/util/node.hpp"
22#include "auto_apms_behavior_tree_core/builder.hpp"
23#include "auto_apms_util/filesystem.hpp"
24#include "auto_apms_util/string.hpp"
25#include "rclcpp/rclcpp.hpp"
27#define NEW_TREE_NAME "NewTree"
31int main(
int argc,
char ** argv)
33 bool print_help =
false;
35 const std::string arg(argv[1]);
36 print_help =
"-h" == arg ||
"--help" == arg;
38 if (print_help || argc < 2) {
39 std::cerr <<
"new_tree: The program accepts: \n\t1.) The path of the new behavior tree xml "
40 "file.\n\t2.) Optional: Node plugin manifest identities of installed resources used to create the "
41 "node model. Any arguments after the first one are interpreted as resource identities.\n";
42 std::cerr <<
"Usage: new_tree <tree_file_path> [<node_manifest_identity> ...].\n";
48 for (
int i = 2; i < argc; ++i) {
53 if (tree_file_path.empty()) {
54 throw std::runtime_error(
"Argument tree_file_path is empty.");
58 if (tree_file_path.extension() !=
".xml") {
59 throw std::runtime_error(
"Output file '" + tree_file_path.string() +
"' has wrong extension. Must be '.xml'.");
63 if (std::filesystem::exists(tree_file_path)) {
65 throw std::runtime_error(
"Output file '" + tree_file_path.string() +
"' is not empty.");
78 if (!node_manifest.
empty()) {
83 std::ofstream out_stream(tree_file_path);
84 if (out_stream.is_open()) {
88 throw std::runtime_error(
"Error opening behavior tree output file '" + tree_file_path.string() +
"'.");
91 std::cout <<
"Wrote behavior tree to file " << tree_file_path << std::endl;
Data structure for information about which behavior tree node plugin to load and how to configure the...
bool empty() const
Determine whether any node registration options have been added to the manifest.
NodeManifest & merge(const NodeManifest &other, bool replace=false)
Merges another NodeManifest with this one.
static NodeManifest fromResourceIdentity(const std::string &identity)
Create a node manifest from an installed resource.
NodeElement insertNode(const std::string &name, const NodeElement *before_this=nullptr)
Add a new node to the children of this node.
Handle for a single behavior tree of a TreeDocument.
TreeElement & makeRoot()
Set this behavior tree as the root tree of the parent document.
This class offers a programmatic approach for building behavior trees and stores the registration dat...
TreeDocument & addNodeModel(bool include_native=false)
Add an behavior tree node model element to the document.
virtual TreeDocument & registerNodes(const NodeManifest &tree_node_manifest, bool override=false)
Load behavior tree node plugins and register them with the internal behavior tree factory.
std::string writeToString() const
Write the XML of this tree document to a string.
TreeElement newTree(const std::string &tree_name)
Create a new behavior tree inside this document.
std::string trimWhitespaces(const std::string &str)
Trim whitespaces from both ends of a string.
bool isFileEmpty(const std::string &path)
Determine if a file is empty.
Useful tooling for incorporating behavior trees for task development.