1 #ifndef BT_FLATBUFFER_HELPER_H 2 #define BT_FLATBUFFER_HELPER_H 65 std::vector<flatbuffers::Offset<Serialization::TreeNode>> fb_nodes;
69 std::vector<uint16_t> children_uid;
70 if (auto control = dynamic_cast<BT::ControlNode*>(node))
72 children_uid.reserve(control->children().size());
73 for (const auto& child : control->children())
75 children_uid.push_back(child->UID());
78 else if (
auto decorator = dynamic_cast<BT::DecoratorNode*>(node))
80 const auto& child = decorator->child();
81 children_uid.push_back(child->UID());
84 std::vector<flatbuffers::Offset<Serialization::PortConfig>> ports;
88 builder, it.first.c_str(), it.second.c_str()));
93 builder, it.first.c_str(), it.second.c_str()));
105 fb_nodes.push_back(tn);
108 std::vector<flatbuffers::Offset<Serialization::NodeModel>> node_models;
110 for (
const auto& node_it: tree.manifests)
112 const auto&
manifest = node_it.second;
113 std::vector<flatbuffers::Offset<Serialization::PortModel>> port_models;
115 for (
const auto& port_it:
manifest.ports)
117 const auto& port_name = port_it.first;
118 const auto& port = port_it.second;
121 builder.CreateString( port_name.c_str() ),
124 builder.CreateString( port.description().c_str() )
126 port_models.push_back(port_model);
133 builder.CreateVector(port_models) );
135 node_models.push_back(node_model);
139 builder.CreateVector(fb_nodes),
140 builder.CreateVector(node_models));
155 int64_t usec = duration_cast<microseconds>(timestamp).
count();
156 int64_t t_sec = usec / 1000000;
157 int64_t t_usec = usec % 1000000;
159 flatbuffers::WriteScalar(&buffer[0], t_sec);
160 flatbuffers::WriteScalar(&buffer[4], t_usec);
161 flatbuffers::WriteScalar(&buffer[8], UID);
171 #endif // BT_FLATBUFFER_HELPER_H flatbuffers::Offset< NodeModel > CreateNodeModel(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset< flatbuffers::String > registration_name=0, NodeType type=NodeType::UNDEFINED, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< PortModel >>> ports=0)
flatbuffers::Offset< BehaviorTree > CreateBehaviorTree(flatbuffers::FlatBufferBuilder &_fbb, uint16_t root_uid=0, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< TreeNode >>> nodes=0, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< NodeModel >>> node_models=0)
const std::string & name() const
Name of the instance, not the type.
const NodeConfiguration & config() const
static raw_event_t * buffer
flatbuffers::Offset< TreeNode > CreateTreeNode(flatbuffers::FlatBufferBuilder &_fbb, uint16_t uid=0, flatbuffers::Offset< flatbuffers::Vector< uint16_t >> children_uid=0, NodeStatus status=NodeStatus::IDLE, flatbuffers::Offset< flatbuffers::String > instance_name=0, flatbuffers::Offset< flatbuffers::String > registration_name=0, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< PortConfig >>> port_remaps=0)
Offset< String > CreateString(const char *str, size_t len)
Store a string in the buffer, which can contain any binary data.
void CreateFlatbuffersBehaviorTree(flatbuffers::FlatBufferBuilder &builder, const BT::Tree &tree)
std::array< uint8_t, 12 > SerializedTransition
Helper class to hold data needed in creation of a FlatBuffer. To serialize data, you typically call o...
Serialization::NodeType convertToFlatbuffers(BT::NodeType type)
std::string demangle(char const *name)
PortsRemapping output_ports
Abstract base class for Behavior Tree Nodes.
Offset< Vector< T > > CreateVector(const T *v, size_t len)
Serialize an array into a FlatBuffer vector.
static volatile int count
flatbuffers::Offset< PortModel > CreatePortModel(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset< flatbuffers::String > port_name=0, PortDirection direction=PortDirection::INPUT, flatbuffers::Offset< flatbuffers::String > type_info=0, flatbuffers::Offset< flatbuffers::String > description=0)
NodeStatus status() const
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
const std::string & registrationName() const
registrationName is the ID used by BehaviorTreeFactory to create an instance.
NodeType
Enumerates the possible types of nodes.
std::chrono::high_resolution_clock::duration Duration
PortsRemapping input_ports
void applyRecursiveVisitor(const TreeNode *root_node, const std::function< void(const TreeNode *)> &visitor)
flatbuffers::Offset< PortConfig > CreatePortConfigDirect(flatbuffers::FlatBufferBuilder &_fbb, const char *port_name=nullptr, const char *remap=nullptr)
SerializedTransition SerializeTransition(uint16_t UID, Duration timestamp, NodeStatus prev_status, NodeStatus status)