Class robot_interfaces::RobotLogger

template<typename Action, typename Observation>
class RobotLogger

Log robot data (observations, actions, status) to file.

Logs for each time step the time index, timestamp, and the values Observation, Action, and Status. The data is written to a text file, one line per time step with values separated by spaces. This format can easily be read e.g. with NumPy or Pandas.

There are different ways of using the logger:

  1. Using start() and stop_and_save(): The logger runs a thread in which it copies all data to an internal buffer while the robot is running. When calling stop_and_save() the content of the buffer is stored to a file (either binary or text). This is the recommended method for most applications.

  2. Using save_current_robot_data() or save_current_robot_data_binary(): Call this to log data that is currently held in the robot data time series. For this method, the logger doesn’t use an own buffer, so no data is copied while the robot is running. However, the possible time span for logging is limited by the size of the robot data time series.

Template Parameters:
  • Action – Type of the robot action. Must derive from Loggable.

  • Observation – Type of the robot observation. Must derive from Loggable.

Public Types

enum class Format

Enumeration of possible log file formats.

Values:

enumerator BINARY
enumerator CSV
enumerator CSV_GZIP
enumerator BINARY
enumerator CSV
enumerator CSV_GZIP
enum class Format

Enumeration of possible log file formats.

Values:

enumerator BINARY
enumerator CSV
enumerator CSV_GZIP
enumerator BINARY
enumerator CSV
enumerator CSV_GZIP
typedef RobotLogEntry<Action, Observation> LogEntry
typedef RobotLogEntry<Action, Observation> LogEntry

Public Functions

inline RobotLogger(std::shared_ptr<robot_interfaces::RobotData<Action, Observation>> robot_data, size_t buffer_limit)

Initialize logger.

Parameters:
  • robot_data – Pointer to the robot data instance.

  • buffer_limit – Max. size of the log buffer (in timesteps). If the buffer is full, old time steps will be dropped as new ones are added.

RobotLogger(RobotLogger&&) = default
inline virtual ~RobotLogger()
inline void start()

Start logging using an internal buffer.

The buffer is limited by the buffer_limit argument of the constructor. If the limit is reached, the logger stops automatically.

If the logger is already running, this is a noop.

inline void stop()

Stop logging.

If the logger is already stopped, this is a noop.

inline void reset()

Clear the log buffer.

inline void stop_and_save(const std::string &filename, Format log_format)

Stop logging and save logged messages to a file.

Parameters:

filename – Path to the output file. Existing files will be overwritten.

inline void save_current_robot_data(const std::string &filename, long int start_index = 0, long int end_index = -1)

Write current content of robot data to CSV log file.

Write data of the time steps [start_index, end_index) to a log file. This assumes that the specified range is completely included in the active robot data buffer. If this is not the case, only the time steps which are still held in the buffer will be logged.

With the default values for start_index and end_index, the whole content of the current buffer is logged.

Parameters:
  • filename – Path to the log file. Existing files will be overwritten!

  • start_index – Time index at which to start logging. If not specified, the whole buffer is logged.

  • end_index – Time index at which to stop logging. This is exclusive, i.e. the specified time index itself will not be part of the log. If set to a negative value (default) or a value greater than the newest time index, the newest time index is used instead (see newest_timeindex()).

Throws:

std::runtime_error – If called while the logger thread is running. In case the logger thread was started via start(), it needs to be stopped by calling stop() before save_current_robot_data() can be used.

inline void save_current_robot_data_binary(const std::string &filename, long int start_index = 0, long int end_index = -1)

Like save_current_robot_data but using binary file format.

inline RobotLogger(std::shared_ptr<robot_interfaces::RobotData<Action, Observation>> robot_data, size_t buffer_limit)

Initialize logger.

Parameters:
  • robot_data – Pointer to the robot data instance.

  • buffer_limit – Max. size of the log buffer (in timesteps). If the buffer is full, old time steps will be dropped as new ones are added.

RobotLogger(RobotLogger&&) = default
inline virtual ~RobotLogger()
inline void start()

Start logging using an internal buffer.

The buffer is limited by the buffer_limit argument of the constructor. If the limit is reached, the logger stops automatically.

If the logger is already running, this is a noop.

inline void stop()

Stop logging.

If the logger is already stopped, this is a noop.

inline void reset()

Clear the log buffer.

inline void stop_and_save(const std::string &filename, Format log_format)

Stop logging and save logged messages to a file.

Parameters:

filename – Path to the output file. Existing files will be overwritten.

inline void save_current_robot_data(const std::string &filename, long int start_index = 0, long int end_index = -1)

Write current content of robot data to CSV log file.

Write data of the time steps [start_index, end_index) to a log file. This assumes that the specified range is completely included in the active robot data buffer. If this is not the case, only the time steps which are still held in the buffer will be logged.

With the default values for start_index and end_index, the whole content of the current buffer is logged.

Parameters:
  • filename – Path to the log file. Existing files will be overwritten!

  • start_index – Time index at which to start logging. If not specified, the whole buffer is logged.

  • end_index – Time index at which to stop logging. This is exclusive, i.e. the specified time index itself will not be part of the log. If set to a negative value (default) or a value greater than the newest time index, the newest time index is used instead (see newest_timeindex()).

Throws:

std::runtime_error – If called while the logger thread is running. In case the logger thread was started via start(), it needs to be stopped by calling stop() before save_current_robot_data() can be used.

inline void save_current_robot_data_binary(const std::string &filename, long int start_index = 0, long int end_index = -1)

Like save_current_robot_data but using binary file format.