BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
BT::SqliteLogger Class Reference

The SqliteLogger is a logger that will store the tree and all the status transitions in a SQLite database (single file). More...

#include <bt_sqlite_logger.h>

Inheritance diagram for BT::SqliteLogger:
Collaboration diagram for BT::SqliteLogger:

Public Types

using ExtraCallback = std::function< std::string(Duration, const TreeNode &, NodeStatus, NodeStatus)>
 

Public Member Functions

 SqliteLogger (const Tree &tree, std::filesystem::path const &file, bool append=false)
 To correctly read this log with Groot2, you must use the suffix ".db3". Constructor will throw otherwise.
 
 SqliteLogger (const SqliteLogger &)=delete
 
SqliteLoggeroperator= (const SqliteLogger &)=delete
 
 SqliteLogger (SqliteLogger &&)=delete
 
SqliteLoggeroperator= (SqliteLogger &&)=delete
 
void setAdditionalCallback (ExtraCallback func)
 
virtual void callback (Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
 
void execSqlStatement (std::string statement)
 
virtual void flush () override
 
- Public Member Functions inherited from BT::StatusChangeLogger
 StatusChangeLogger (TreeNode *root_node)
 Construct and immediately subscribe to status changes.
 
 StatusChangeLogger (const StatusChangeLogger &other)=delete
 
StatusChangeLoggeroperator= (const StatusChangeLogger &other)=delete
 
 StatusChangeLogger (StatusChangeLogger &&other)=delete
 
StatusChangeLoggeroperator= (StatusChangeLogger &&other)=delete
 
virtual void callback (BT::Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status)=0
 
virtual void flush ()=0
 
void setEnabled (bool enabled)
 
void setTimestampType (TimestampType type)
 
bool enabled () const
 
bool showsTransitionToIdle () const
 
void enableTransitionToIdle (bool enable)
 

Additional Inherited Members

- Protected Member Functions inherited from BT::StatusChangeLogger
 StatusChangeLogger ()=default
 Default constructor for deferred subscription. Call subscribeToTreeChanges() when ready.
 
void subscribeToTreeChanges (TreeNode *root_node)
 Subscribe to status changes. Call at end of constructor for deferred subscription.
 

Detailed Description

The SqliteLogger is a logger that will store the tree and all the status transitions in a SQLite database (single file).

SQL schema

CREATE TABLE IF NOT EXISTS Definitions ( session_id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT NOT NULL, xml_tree TEXT NOT NULL);

CREATE TABLE IF NOT EXISTS Nodes (" session_id INTEGER NOT NULL, fullpath VARCHAR, " node_uid INTEGER NOT NULL );

CREATE TABLE IF NOT EXISTS Transitions ( timestamp INTEGER PRIMARY KEY NOT NULL, session_id INTEGER NOT NULL, node_uid INTEGER NOT NULL, duration INTEGER, state INTEGER NOT NULL, extra_data VARCHAR );

You can append data to the same file; this allows you to store multiple experiments into the database. Yn that case, each recording has a unique session_id.

This is primarily meant to be used with Groot2, but the content of the tables is sufficiently self-explaining, and you can create your own tools to extract the information.

Constructor & Destructor Documentation

◆ SqliteLogger()

BT::SqliteLogger::SqliteLogger ( const Tree tree,
std::filesystem::path const &  file,
bool  append = false 
)

To correctly read this log with Groot2, you must use the suffix ".db3". Constructor will throw otherwise.

Parameters
treethe tree to log
filepathpath of the file where info will be stored
appendif true, add this recording to the database

Member Function Documentation

◆ callback()

virtual void BT::SqliteLogger::callback ( Duration  timestamp,
const TreeNode node,
NodeStatus  prev_status,
NodeStatus  status 
)
overridevirtual

◆ flush()

virtual void BT::SqliteLogger::flush ( )
overridevirtual

The documentation for this class was generated from the following file: