Drake
DrakeLcmLog Class Reference

A LCM interface for logging LCM messages to a file or playing back from a existing log. More...

#include <drake/lcm/drake_lcm_log.h>

Inheritance diagram for DrakeLcmLog:
[legend]
Collaboration diagram for DrakeLcmLog:
[legend]

Public Member Functions

 DrakeLcmLog (const std::string &file_name, bool is_write, bool overwrite_publish_time_with_system_clock=false)
 Constructs a DrakeLcmLog. More...
 
void Publish (const std::string &channel, const void *data, int data_size, double second) override
 Writes an entry occurred at timestamp with content data to the log file. More...
 
void Subscribe (const std::string &channel, DrakeLcmMessageHandlerInterface *handler) override
 Subscribes handler to channel. More...
 
double GetNextMessageTime () const override
 Returns the time in seconds for the next logged message's occurrence time or infinity if there are no more messages in the current log. More...
 
void DispatchMessageAndAdvanceLog (double current_time) override
 Let MSG be the next message event in the log, if current_time matches MSG's timestamp, for every DrakeLcmMessageHandlerInterface sub that's subscribed to MSG's channel, invoke sub's HandleMessage method. More...
 
bool is_write_only () const
 Returns true if this instance is constructed in write-only mode. More...
 
double timestamp_to_second (uint64_t timestamp) const
 Converts timestamp (in microseconds) to time (in seconds) relative to the starting time passed to the constructor. More...
 
uint64_t second_to_timestamp (double sec) const
 Converts time (in seconds) relative to the starting time passed to the constructor to a timestamp in microseconds. More...
 
void StartReceiveThread () override
 Starts the receive thread. More...
 
void StopReceiveThread () override
 Stops the receive thread. More...
 
Does not allow copy, move, or assignment
 DrakeLcmLog (const DrakeLcmLog &)=delete
 
DrakeLcmLogoperator= (const DrakeLcmLog &)=delete
 
 DrakeLcmLog (DrakeLcmLog &&)=delete
 
DrakeLcmLogoperator= (DrakeLcmLog &&)=delete
 
- Public Member Functions inherited from DrakeLcmInterface
 DrakeLcmInterface ()=default
 
virtual ~DrakeLcmInterface ()=default
 
 DrakeLcmInterface (const DrakeLcmInterface &)=delete
 
DrakeLcmInterfaceoperator= (const DrakeLcmInterface &)=delete
 
 DrakeLcmInterface (DrakeLcmInterface &&)=delete
 
DrakeLcmInterfaceoperator= (DrakeLcmInterface &&)=delete
 

Detailed Description

A LCM interface for logging LCM messages to a file or playing back from a existing log.

Note the user is responsible for offsetting the clock used to generate the log and the clock used for playback. For example, if the log is generated by some external logger (the lcm-logger binary), which uses the unix epoch time clock to record message arrival time, the user need to offset those timestamps properly to match and the clock used for playback.

Constructor & Destructor Documentation

DrakeLcmLog ( const DrakeLcmLog )
delete
DrakeLcmLog ( DrakeLcmLog &&  )
delete
DrakeLcmLog ( const std::string &  file_name,
bool  is_write,
bool  overwrite_publish_time_with_system_clock = false 
)
explicit

Constructs a DrakeLcmLog.

Parameters
file_nameLog's file name for reading or writing.
is_writeIf false, this instance reads from the Lcm log identified by file_name. If true, this instance writes to the Lcm log whose name is given by file_name.
overwrite_publish_time_with_system_clockThis parameter only affects the Publish method in write-only mode. If true, override the second parameter passed to Publish method, and use host system's clock to generate the timestamp for the logged message. This is used to mimic lcm-logger's behavior. It also implicitly records how fast the messages are generated in real time.
Exceptions
std::runtime_errorif unable to open file.

Member Function Documentation

void DispatchMessageAndAdvanceLog ( double  current_time)
overridevirtual

Let MSG be the next message event in the log, if current_time matches MSG's timestamp, for every DrakeLcmMessageHandlerInterface sub that's subscribed to MSG's channel, invoke sub's HandleMessage method.

Then, this function advances the log by exactly one message. This function does nothing if MSG is null (end of log) or current_time does not match MSG's timestamp.

Exceptions
std::logic_errorif this instance is not constructed in read-only mode.

Reimplemented from DrakeLcmInterface.

Here is the call graph for this function:

double GetNextMessageTime ( ) const
overridevirtual

Returns the time in seconds for the next logged message's occurrence time or infinity if there are no more messages in the current log.

Exceptions
std::logic_errorif this instance is not constructed in read-only mode.

Reimplemented from DrakeLcmInterface.

Here is the call graph for this function:

bool is_write_only ( ) const
inline

Returns true if this instance is constructed in write-only mode.

DrakeLcmLog& operator= ( const DrakeLcmLog )
delete
DrakeLcmLog& operator= ( DrakeLcmLog &&  )
delete
void Publish ( const std::string &  channel,
const void *  data,
int  data_size,
double  second 
)
overridevirtual

Writes an entry occurred at timestamp with content data to the log file.

The current implementation blocks until writing is done.

Parameters
channelChannel name.
dataPointer to raw bytes.
data_sizeNumber of bytes in data.
secondTime in seconds when the message is published. Since messages are save to the log file in the order of Publish calls, this function should only be called with non-decreasing second. Note that this parameter can be overwritten by the host system's clock if overwrite_publish_time_with_system_clock is true at construction time.
Exceptions
std::logic_errorif this instance is not constructed in write-only mode.

Implements DrakeLcmInterface.

Here is the call graph for this function:

uint64_t second_to_timestamp ( double  sec) const
inline

Converts time (in seconds) relative to the starting time passed to the constructor to a timestamp in microseconds.

Here is the caller graph for this function:

void StartReceiveThread ( )
inlineoverridevirtual

Starts the receive thread.

This must be called for subscribers to receive any messages.

Precondition
StartReceiveThread() was not called.

Implements DrakeLcmInterface.

void StopReceiveThread ( )
inlineoverridevirtual

Stops the receive thread.

This must be called prior to any subscribers being destroyed. Note that the receive thread will be automatically stopped by this class's destructor, so usage of this method will be extremely rare. It will only be needed if this class's instance and the subscribers to LCM channels are owned by different classes. In such a scenario, this method can be used to ensure the receive thread is destroyed before the subscribers are destroyed.

Precondition
StartReceiveThread() was called.

Implements DrakeLcmInterface.

void Subscribe ( const std::string &  channel,
DrakeLcmMessageHandlerInterface handler 
)
overridevirtual

Subscribes handler to channel.

Multiple handlers can subscribe to the same channel.

Exceptions
std::logic_errorif this instance is not constructed in read-only mode.

Implements DrakeLcmInterface.

double timestamp_to_second ( uint64_t  timestamp) const
inline

Converts timestamp (in microseconds) to time (in seconds) relative to the starting time passed to the constructor.

Here is the caller graph for this function:


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