Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Feb 27, 2024
1 parent 66eed7d commit 27f4f28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 5 additions & 7 deletions examples/t12_groot_howto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@
* But this time we also show how to connect
*/

// A custom structuree that I want to visualize in Groot2
// A custom struct that I want to visualize in Groot2
struct Position2D {
double x;
double y;
};

// Allows Position2D to be visualized in Groot2
// You still need BT::RegisterJsonDefinition<Position2D>(PositionToJson)
void PositionToJson(nlohmann::json& j, const Position2D& p)
BT_JSON_CONVERTER(Position2D, pos)
{
j["x"] = p.x;
j["y"] = p.y;
add_field("x", &pos.x);
add_field("y", &pos.y);
}

// Simple Action that updates an instance of Position2D in the blackboard
Expand Down Expand Up @@ -97,7 +95,7 @@ int main()
factory.registerBehaviorTreeFromText(xml_text);

// Add this to allow Groot2 to visualize your custom type
BT::RegisterJsonDefinition<Position2D>(PositionToJson);
BT::RegisterJsonDefinition<Position2D>();

auto tree = factory.createTree("MainTree");

Expand Down
11 changes: 5 additions & 6 deletions include/behaviortree_cpp/json_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace BT {

/**
* To add new type, you must follow these isntructions:
* To add new type to the JSON library, you should follow these isntructions:
* https://json.nlohmann.me/features/arbitrary_types/
*
* Considering for instance the type:
Expand All @@ -24,19 +24,18 @@ namespace BT {
* void to_json(nlohmann::json& j, const Point2D& point);
* void from_json(const nlohmann::json& j, Point2D& point);
*
* To avoir repeating yourself, we provide the macro BT_JSON_CONVERTION
* that implements both those function, at once.
* Usage:
* To avoid repeating yourself, we provide the macro BT_JSON_CONVERTION
* that implements both those function, at once. Usage:
*
* BT_JSON_CONVERTER(Point2D, point)
* {
* add_field("x", &point.x);
* add_field("y", &point.y);
* }
*
* Later, you MUST register the type in main using:
* Later, you MUST register the type using:
*
* RegisterJsonDefinition<Point2D>();
* BT::RegisterJsonDefinition<Point2D>();
*/

//-----------------------------------------------------------------------------------
Expand Down

0 comments on commit 27f4f28

Please sign in to comment.