Allow loading of trees from parameter
This commit is contained in:
parent
7193070220
commit
65df5d10c4
3
.clang-format
Normal file
3
.clang-format
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 4
|
||||||
|
ColumnLimit: 140
|
||||||
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
@ -50,13 +50,13 @@ namespace BT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto pose = std::make_shared<geometry_msgs::msg::Pose>();
|
auto pose = std::make_shared<geometry_msgs::msg::Pose>();
|
||||||
pose->orientation.w=0;
|
pose->orientation.w = 0;
|
||||||
pose->orientation.x=0;
|
pose->orientation.x = 0;
|
||||||
pose->orientation.y=1;
|
pose->orientation.y = 1;
|
||||||
pose->orientation.z=0;
|
pose->orientation.z = 0;
|
||||||
pose->position.x= convertFromString<double>(parts[0]);
|
pose->position.x = convertFromString<double>(parts[0]);
|
||||||
pose->position.y= convertFromString<double>(parts[1]);
|
pose->position.y = convertFromString<double>(parts[1]);
|
||||||
pose->position.z= convertFromString<double>(parts[2]);
|
pose->position.z = convertFromString<double>(parts[2]);
|
||||||
|
|
||||||
std::cout << "[ generated pose from string ]" << std::endl;
|
std::cout << "[ generated pose from string ]" << std::endl;
|
||||||
|
|
||||||
@ -71,9 +71,9 @@ namespace BT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto point = std::make_shared<geometry_msgs::msg::Point>();
|
auto point = std::make_shared<geometry_msgs::msg::Point>();
|
||||||
point->x= convertFromString<double>(parts[0]);
|
point->x = convertFromString<double>(parts[0]);
|
||||||
point->y= convertFromString<double>(parts[1]);
|
point->y = convertFromString<double>(parts[1]);
|
||||||
point->z= convertFromString<double>(parts[2]);
|
point->z = convertFromString<double>(parts[2]);
|
||||||
|
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
@ -86,10 +86,10 @@ namespace BT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto point = std::make_shared<geometry_msgs::msg::Quaternion>();
|
auto point = std::make_shared<geometry_msgs::msg::Quaternion>();
|
||||||
point->w= convertFromString<double>(parts[0]);
|
point->w = convertFromString<double>(parts[0]);
|
||||||
point->x= convertFromString<double>(parts[1]);
|
point->x = convertFromString<double>(parts[1]);
|
||||||
point->y= convertFromString<double>(parts[2]);
|
point->y = convertFromString<double>(parts[2]);
|
||||||
point->z= convertFromString<double>(parts[3]);
|
point->z = convertFromString<double>(parts[3]);
|
||||||
|
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "Area.h"
|
#include "Area.h"
|
||||||
#include <behaviortree_cpp_v3/blackboard.h>
|
#include <behaviortree_cpp_v3/blackboard.h>
|
||||||
|
#include <behaviortree_cpp_v3/bt_factory.h>
|
||||||
#include <rclcpp/rclcpp.hpp>
|
#include <rclcpp/rclcpp.hpp>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <rclcpp/utilities.hpp>
|
#include <rclcpp/utilities.hpp>
|
||||||
@ -140,8 +141,16 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::cout << "Creating tree." << std::endl;
|
std::cout << "Creating tree." << std::endl;
|
||||||
|
|
||||||
Tree actorTree = factory.createTreeFromFile("/home/ros/workspace/src/btree_nodes/actorTree.xml",blackboard);
|
mainNode -> declare_parameter("trees",std::vector<std::string>({
|
||||||
Tree robotTree = factory.createTreeFromFile("/home/ros/workspace/src/btree_nodes/robotTree.xml",blackboard);
|
"/home/ros/workspace/src/btree_nodes/actorTree.xml",
|
||||||
|
"/home/ros/workspace/src/btree_nodes/robotTree.xml"
|
||||||
|
}));
|
||||||
|
|
||||||
|
auto treeFileNames = mainNode -> get_parameter("trees").as_string_array();
|
||||||
|
auto trees = std::vector<std::shared_ptr<BT::Tree>>();
|
||||||
|
for(auto treeFileName : treeFileNames){
|
||||||
|
trees.emplace_back(std::make_shared<BT::Tree>(factory.createTreeFromFile(treeFileName,blackboard)));
|
||||||
|
}
|
||||||
|
|
||||||
auto init = std::make_shared<geometry_msgs::msg::Pose>();
|
auto init = std::make_shared<geometry_msgs::msg::Pose>();
|
||||||
init->position.x = 6.0;
|
init->position.x = 6.0;
|
||||||
@ -167,8 +176,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
while (rclcpp::ok()) {
|
while (rclcpp::ok()) {
|
||||||
blackboardMutex.lock();
|
blackboardMutex.lock();
|
||||||
actorTree.tickRoot();
|
for(auto tree : trees){
|
||||||
robotTree.tickRoot();
|
tree->tickRoot();
|
||||||
|
}
|
||||||
blackboardMutex.unlock();
|
blackboardMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user