Skip to content

Commit 8b35d9d

Browse files
committed
update tutorial 12
1 parent 3d3b2e9 commit 8b35d9d

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

docs/tutorial-basics/tutorial_12_groot2.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,44 @@ struct Pose2D {
161161
}
162162
```
163163
164-
The following function should be implemented:
164+
You will need to include **behaviortree_cpp/json_export.h** and follow the
165+
following instructions, based on your BT.CPP version.
166+
167+
168+
### Version 4.3.5 or earlier
169+
170+
Implement this function, being carefull about using the namespace `nlohmann`:
165171
166172
```cpp
167-
void to_json(nlohmann::json& dest, const Pose2D& pose) {
173+
namespace nlohmann {
174+
void to_json(nlohmann::json& dest, const Pose2D& pose) {
168175
dest["x"] = pose.x;
169176
dest["y"] = pose.y;
170177
dest["theta"] = pose.theta;
178+
}
171179
}
180+
```
181+
182+
Then, registered the function adding this to you **main**:
183+
184+
```cpp
185+
BT::JsonExporter::get().addConverter<Pose2D>();
186+
```
187+
188+
### Version 4.3.6 or later
189+
190+
The implementation of the "to_json" function has no limitations in terms of name and namespace,
191+
as long it can be casted to `std::function<void(nlohmann::json&, const Pose2D&)>`, for instance:
192+
193+
```cpp
194+
void PoseToJson(nlohmann::json& dest, const Pose2D& pose) {
195+
dest["x"] = pose.x;
196+
dest["y"] = pose.y;
197+
dest["theta"] = pose.theta;
198+
}
199+
```
200+
201+
And registered the function adding this to you **main**:
202+
```cpp
203+
BT::RegisterJsonDefinition<Pose2D>(PoseToJson);
172204
```

0 commit comments

Comments
 (0)