Skip to content

Commit 27f4f28

Browse files
committed
fix
1 parent 66eed7d commit 27f4f28

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

examples/t12_groot_howto.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@
1010
* But this time we also show how to connect
1111
*/
1212

13-
// A custom structuree that I want to visualize in Groot2
13+
// A custom struct that I want to visualize in Groot2
1414
struct Position2D {
1515
double x;
1616
double y;
1717
};
1818

19-
// Allows Position2D to be visualized in Groot2
20-
// You still need BT::RegisterJsonDefinition<Position2D>(PositionToJson)
21-
void PositionToJson(nlohmann::json& j, const Position2D& p)
19+
BT_JSON_CONVERTER(Position2D, pos)
2220
{
23-
j["x"] = p.x;
24-
j["y"] = p.y;
21+
add_field("x", &pos.x);
22+
add_field("y", &pos.y);
2523
}
2624

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

9997
// Add this to allow Groot2 to visualize your custom type
100-
BT::RegisterJsonDefinition<Position2D>(PositionToJson);
98+
BT::RegisterJsonDefinition<Position2D>();
10199

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

include/behaviortree_cpp/json_export.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace BT {
1010

1111
/**
12-
* To add new type, you must follow these isntructions:
12+
* To add new type to the JSON library, you should follow these isntructions:
1313
* https://json.nlohmann.me/features/arbitrary_types/
1414
*
1515
* Considering for instance the type:
@@ -24,19 +24,18 @@ namespace BT {
2424
* void to_json(nlohmann::json& j, const Point2D& point);
2525
* void from_json(const nlohmann::json& j, Point2D& point);
2626
*
27-
* To avoir repeating yourself, we provide the macro BT_JSON_CONVERTION
28-
* that implements both those function, at once.
29-
* Usage:
27+
* To avoid repeating yourself, we provide the macro BT_JSON_CONVERTION
28+
* that implements both those function, at once. Usage:
3029
*
3130
* BT_JSON_CONVERTER(Point2D, point)
3231
* {
3332
* add_field("x", &point.x);
3433
* add_field("y", &point.y);
3534
* }
3635
*
37-
* Later, you MUST register the type in main using:
36+
* Later, you MUST register the type using:
3837
*
39-
* RegisterJsonDefinition<Point2D>();
38+
* BT::RegisterJsonDefinition<Point2D>();
4039
*/
4140

4241
//-----------------------------------------------------------------------------------

0 commit comments

Comments
 (0)