From 851c7a0f68352cbbe4be6fe227205bbcc83ad948 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Thu, 29 Feb 2024 18:14:35 +0100 Subject: [PATCH] added comments --- examples/t12_groot_howto.cpp | 7 ++++++- sample_nodes/movebase_node.h | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/t12_groot_howto.cpp b/examples/t12_groot_howto.cpp index 226176f0e..ec3fbeedc 100644 --- a/examples/t12_groot_howto.cpp +++ b/examples/t12_groot_howto.cpp @@ -11,11 +11,16 @@ */ // A custom struct that I want to visualize in Groot2 -struct Position2D { +struct Position2D +{ double x; double y; }; +// This macro will generate the code that is needed to convert +// the object to/from JSON. +// You still need to call BT::RegisterJsonDefinition() +// in main() BT_JSON_CONVERTER(Position2D, pos) { add_field("x", &pos.x); diff --git a/sample_nodes/movebase_node.h b/sample_nodes/movebase_node.h index 486d34139..8700d5536 100644 --- a/sample_nodes/movebase_node.h +++ b/sample_nodes/movebase_node.h @@ -1,21 +1,23 @@ #pragma once +#include "behaviortree_cpp/action_node.h" #include "behaviortree_cpp/json_export.h" -#include "behaviortree_cpp/behavior_tree.h" // Custom type struct Pose2D { - double x, y, theta; + double x, y, theta; }; -// Use this to register this function into JsonExporter: +// Add this to you main() to register this function into JsonExporter: // // BT::JsonExporter::get().addConverter(); -inline void to_json(nlohmann::json& dest, const Pose2D& pose) { - dest["x"] = pose.x; - dest["y"] = pose.y; - dest["theta"] = pose.theta; + +BT_JSON_CONVERTER(Pose2D, pose) +{ + add_field("x", &pose.x); + add_field("y", &pose.y); + add_field("theta", &pose.theta); }