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"
31 #include "nav2_msgs/msg/waypoint_status.hpp"
36 namespace builtin_interfaces::msg
39 BT_JSON_CONVERTER(builtin_interfaces::msg::Time, msg)
41 add_field(
"sec", &msg.sec);
42 add_field(
"nanosec", &msg.nanosec);
47 namespace std_msgs::msg
50 BT_JSON_CONVERTER(std_msgs::msg::Header, msg)
52 add_field(
"stamp", &msg.stamp);
53 add_field(
"frame_id", &msg.frame_id);
58 namespace geometry_msgs::msg
61 BT_JSON_CONVERTER(geometry_msgs::msg::Point, msg)
63 add_field(
"x", &msg.x);
64 add_field(
"y", &msg.y);
65 add_field(
"z", &msg.z);
68 BT_JSON_CONVERTER(geometry_msgs::msg::Quaternion, msg)
70 add_field(
"x", &msg.x);
71 add_field(
"y", &msg.y);
72 add_field(
"z", &msg.z);
73 add_field(
"w", &msg.w);
76 BT_JSON_CONVERTER(geometry_msgs::msg::Pose, msg)
78 add_field(
"position", &msg.position);
79 add_field(
"orientation", &msg.orientation);
82 BT_JSON_CONVERTER(geometry_msgs::msg::PoseStamped, msg)
84 add_field(
"header", &msg.header);
85 add_field(
"pose", &msg.pose);
90 namespace nav_msgs::msg
93 BT_JSON_CONVERTER(nav_msgs::msg::Goals, msg)
95 add_field(
"header", &msg.header);
96 add_field(
"goals", &msg.goals);
99 BT_JSON_CONVERTER(nav_msgs::msg::Path, msg)
101 add_field(
"header", &msg.header);
102 add_field(
"poses", &msg.poses);
107 namespace nav2_msgs::msg
110 BT_JSON_CONVERTER(nav2_msgs::msg::WaypointStatus, msg)
112 add_field(
"waypoint_status", &msg.waypoint_status);
113 add_field(
"waypoint_index", &msg.waypoint_index);
114 add_field(
"waypoint_pose", &msg.waypoint_pose);
115 add_field(
"error_code", &msg.error_code);
116 add_field(
"error_msg", &msg.error_msg);
124 inline void from_json(
const nlohmann::json & js, std::chrono::milliseconds & dest)
126 if (js.contains(
"ms")) {
127 dest = std::chrono::milliseconds(js.at(
"ms").get<
int>());
129 throw std::runtime_error(
"Invalid JSON for std::chrono::milliseconds");
133 inline void to_json(nlohmann::json & js,
const std::chrono::milliseconds & src)
135 js[
"__type"] =
"std::chrono::milliseconds";
136 js[
"ms"] = src.count();