Open b-adkins opened 2 months ago
I had assumed that Groot was only considering that the root-level JSON was an object or primitive. But I tried a workaround where I added a trivial key to the JSON serializer:
namespace std
{
void to_json(nlohmann::json& j, const std::vector<double>& x)
{
j["vector"] = nlohmann::json::array();
for(const double& element : x)
{
j["vector"].push_back(element);
}
std::cout << j.dump(2) << std::endl;
}
void from_json(const nlohmann::json&, std::vector<double>&)
{
// Not implemented, but it's not used for Groot
throw std::runtime_error("Not implemented");
}
}
Console output showing it was run:
[INFO] [1726172162.754222982] [bt_action_server]: Tree finished with status: SUCCESS
{
"vector": [
-0.111,
0.0,
0.0
]
}
Groot2 crashed with the same error. I am guessing then that it will crash on JSON arrays anywhere. This severely limits the data types that can go in the Blackboard.
A workaround: add trivial keys for the array elements
void to_json(nlohmann::json& j, const std::vector<double>& x)
{
for(unsigned i = 0; i < x.size(); i++)
{
std::stringstream key;
key << i;
j[key.str()] = x[i];
}
}
It looks pretty good, like this is just how Groot shows arrays.
Versions:
behaviortree_cpp
4f66447 and 4.6.2behaviortree_ros2
adec04bPlatform: Ubuntu 22.04
Behavior
I put a C++ vector on the Blackboard. I tried to visualize it in Groot, but Groot crashed when I clicked the checkmark to visualize the tree.
The exception is
(Groot2 was able to visualize a primitive - a double - or a more complex ROS2 type, a geometry_msgs/msg/Point, without problem.)
Hypothesized Cause
I am guessing that the Groot2 JSON parser assumes that
the rootany element will be a JSON object or primitive. If that is the case, then it needs to also handle a JSON array.To reproduce
Register a JsonDefinition for a vector.
Create a behavior with the following output ports that writes a vector to them:
Use a behavior tree runner with a Groot2Publisher (I used the
BT::TreeExecutionServer
frombehaviortree_ros2
)XML for the tree:
I experienced the same behavior when using the auto-generated
<TreeNodesModel>
Groot2 console log:
The contents of crash_log.txt: