File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -161,12 +161,44 @@ struct Pose2D {
161
161
}
162
162
```
163
163
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`:
165
171
166
172
```cpp
167
- void to_json(nlohmann::json& dest, const Pose2D& pose) {
173
+ namespace nlohmann {
174
+ void to_json(nlohmann::json& dest, const Pose2D& pose) {
168
175
dest["x"] = pose.x;
169
176
dest["y"] = pose.y;
170
177
dest["theta"] = pose.theta;
178
+ }
171
179
}
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);
172
204
```
You can’t perform that action at this time.
0 commit comments