1 #ifndef BT_FLATBUFFER_HELPER_H 2 #define BT_FLATBUFFER_HELPER_H 48 std::vector<flatbuffers::Offset<BT_Serialization::TreeNode>> fb_nodes;
51 std::vector<uint16_t> children_uid;
52 if (
auto control = dynamic_cast<BT::ControlNode*>(node))
54 children_uid.reserve(control->children().size());
55 for (
const auto& child : control->children())
57 children_uid.push_back(child->UID());
60 else if (
auto decorator = dynamic_cast<BT::DecoratorNode*>(node))
62 const auto& child = decorator->child();
63 children_uid.push_back(child->UID());
66 std::vector<flatbuffers::Offset<BT_Serialization::KeyValue>> params;
68 for (
const auto& it : init_params)
80 fb_nodes.push_back(tn);
86 builder.
Finish(behavior_tree);
95 using namespace std::chrono;
97 auto usec = duration_cast<microseconds>(timestamp).
count();
98 uint32_t t_sec = usec / 1000000;
99 uint32_t t_usec = usec % 1000000;
101 flatbuffers::WriteScalar(&buffer[0], t_sec);
102 flatbuffers::WriteScalar(&buffer[4], t_usec);
103 flatbuffers::WriteScalar(&buffer[8], UID);
113 #endif // BT_FLATBUFFER_HELPER_H flatbuffers::Offset< KeyValue > CreateKeyValueDirect(flatbuffers::FlatBufferBuilder &_fbb, const char *key=nullptr, const char *value=nullptr)
std::array< uint8_t, 12 > SerializedTransition
virtual NodeType type() const =0
const std::string & name() const
static raw_event_t * buffer
const NodeParameters & initializationParameters() const
void Finish(Offset< T > root, const char *file_identifier=nullptr)
Finish serializing a buffer by writing the root offset.
flatbuffers::Offset< TreeNode > CreateTreeNode(flatbuffers::FlatBufferBuilder &_fbb, uint16_t uid=0, flatbuffers::Offset< flatbuffers::Vector< uint16_t >> children_uid=0, Type type=Type::UNDEFINED, Status status=Status::IDLE, flatbuffers::Offset< flatbuffers::String > instance_name=0, flatbuffers::Offset< flatbuffers::String > registration_name=0, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< KeyValue >>> params=0)
Offset< String > CreateString(const char *str, size_t len)
Store a string in the buffer, which can contain any binary data.
BT_Serialization::Type convertToFlatbuffers(NodeType type)
Helper class to hold data needed in creation of a FlatBuffer. To serialize data, you typically call o...
std::unordered_map< std::string, std::string > NodeParameters
Offset< Vector< T > > CreateVector(const T *v, size_t len)
Serialize an array into a FlatBuffer vector.
static volatile int count
flatbuffers::Offset< BehaviorTree > CreateBehaviorTree(flatbuffers::FlatBufferBuilder &_fbb, uint16_t root_uid=0, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< TreeNode >>> nodes=0)
NodeStatus status() const
void CreateFlatbuffersBehaviorTree(flatbuffers::FlatBufferBuilder &builder, BT::TreeNode *root_node)
const std::string & registrationName() const
registrationName is the ID used by BehaviorTreeFactory to create an instance.
std::chrono::high_resolution_clock::duration Duration
void applyRecursiveVisitor(const TreeNode *root_node, const std::function< void(const TreeNode *)> &visitor)
SerializedTransition SerializeTransition(uint16_t UID, Duration timestamp, NodeStatus prev_status, NodeStatus status)