16 #ifndef NAV2_BEHAVIOR_TREE__JSON_UTILS_HPP_
17 #define NAV2_BEHAVIOR_TREE__JSON_UTILS_HPP_
23 #include "rclcpp/time.hpp"
24 #include "rclcpp/node.hpp"
25 #include "behaviortree_cpp/json_export.h"
26 #include "geometry_msgs/msg/point.hpp"
27 #include "geometry_msgs/msg/pose_stamped.hpp"
28 #include "geometry_msgs/msg/quaternion.hpp"
29 #include "nav_msgs/msg/goals.hpp"
30 #include "nav_msgs/msg/path.hpp"
35 namespace builtin_interfaces::msg
38 BT_JSON_CONVERTER(builtin_interfaces::msg::Time, msg)
40 add_field(
"sec", &msg.sec);
41 add_field(
"nanosec", &msg.nanosec);
46 namespace std_msgs::msg
49 BT_JSON_CONVERTER(std_msgs::msg::Header, msg)
51 add_field(
"stamp", &msg.stamp);
52 add_field(
"frame_id", &msg.frame_id);
57 namespace geometry_msgs::msg
60 BT_JSON_CONVERTER(geometry_msgs::msg::Point, msg)
62 add_field(
"x", &msg.x);
63 add_field(
"y", &msg.y);
64 add_field(
"z", &msg.z);
67 BT_JSON_CONVERTER(geometry_msgs::msg::Quaternion, msg)
69 add_field(
"x", &msg.x);
70 add_field(
"y", &msg.y);
71 add_field(
"z", &msg.z);
72 add_field(
"w", &msg.w);
75 BT_JSON_CONVERTER(geometry_msgs::msg::Pose, msg)
77 add_field(
"position", &msg.position);
78 add_field(
"orientation", &msg.orientation);
81 BT_JSON_CONVERTER(geometry_msgs::msg::PoseStamped, msg)
83 add_field(
"header", &msg.header);
84 add_field(
"pose", &msg.pose);
89 namespace nav_msgs::msg
92 BT_JSON_CONVERTER(nav_msgs::msg::Goals, msg)
94 add_field(
"header", &msg.header);
95 add_field(
"goals", &msg.goals);
98 BT_JSON_CONVERTER(nav_msgs::msg::Path, msg)
100 add_field(
"header", &msg.header);
101 add_field(
"poses", &msg.poses);
110 inline void from_json(
const nlohmann::json & js, std::chrono::milliseconds & dest)
112 if (js.contains(
"ms")) {
113 dest = std::chrono::milliseconds(js.at(
"ms").get<
int>());
115 throw std::runtime_error(
"Invalid JSON for std::chrono::milliseconds");
119 inline void to_json(nlohmann::json & js,
const std::chrono::milliseconds & src)
121 js[
"__type"] =
"std::chrono::milliseconds";
122 js[
"ms"] = src.count();