15 #ifndef NAV2_BEHAVIOR_TREE__BT_CONVERSIONS_HPP_
16 #define NAV2_BEHAVIOR_TREE__BT_CONVERSIONS_HPP_
20 #include "rclcpp/time.hpp"
21 #include "behaviortree_cpp_v3/behavior_tree.h"
22 #include "geometry_msgs/msg/point.hpp"
23 #include "geometry_msgs/msg/quaternion.hpp"
24 #include "geometry_msgs/msg/pose_stamped.hpp"
39 inline geometry_msgs::msg::Point convertFromString(
const StringView key)
42 auto parts = BT::splitString(key,
';');
43 if (parts.size() != 3) {
44 throw std::runtime_error(
"invalid number of fields for point attribute)");
46 geometry_msgs::msg::Point position;
47 position.x = BT::convertFromString<double>(parts[0]);
48 position.y = BT::convertFromString<double>(parts[1]);
49 position.z = BT::convertFromString<double>(parts[2]);
60 inline geometry_msgs::msg::Quaternion convertFromString(
const StringView key)
63 auto parts = BT::splitString(key,
';');
64 if (parts.size() != 4) {
65 throw std::runtime_error(
"invalid number of fields for orientation attribute)");
67 geometry_msgs::msg::Quaternion orientation;
68 orientation.x = BT::convertFromString<double>(parts[0]);
69 orientation.y = BT::convertFromString<double>(parts[1]);
70 orientation.z = BT::convertFromString<double>(parts[2]);
71 orientation.w = BT::convertFromString<double>(parts[3]);
82 inline geometry_msgs::msg::PoseStamped convertFromString(
const StringView key)
85 auto parts = BT::splitString(key,
';');
86 if (parts.size() != 9) {
87 throw std::runtime_error(
"invalid number of fields for PoseStamped attribute)");
89 geometry_msgs::msg::PoseStamped pose_stamped;
90 pose_stamped.header.stamp = rclcpp::Time(BT::convertFromString<int64_t>(parts[0]));
91 pose_stamped.header.frame_id = BT::convertFromString<std::string>(parts[1]);
92 pose_stamped.pose.position.x = BT::convertFromString<double>(parts[2]);
93 pose_stamped.pose.position.y = BT::convertFromString<double>(parts[3]);
94 pose_stamped.pose.position.z = BT::convertFromString<double>(parts[4]);
95 pose_stamped.pose.orientation.x = BT::convertFromString<double>(parts[5]);
96 pose_stamped.pose.orientation.y = BT::convertFromString<double>(parts[6]);
97 pose_stamped.pose.orientation.z = BT::convertFromString<double>(parts[7]);
98 pose_stamped.pose.orientation.w = BT::convertFromString<double>(parts[8]);
109 inline std::chrono::milliseconds convertFromString<std::chrono::milliseconds>(
const StringView key)
111 return std::chrono::milliseconds(std::stoul(key.data()));