Drake
DrakeLcm Class Reference

A wrapper around a real LCM instance. More...

#include <drake/lcm/drake_lcm.h>

Public Member Functions

 DrakeLcm ()
 Constructs using LCM's default URL (either the default hard-coded URL, or else LCM_DEFAULT_URL environment variable if it is set). More...
 
 DrakeLcm (std::string lcm_url)
 Constructs using the given URL. More...
 
 ~DrakeLcm () override
 A destructor that forces the receive thread to be stopped. More...
 
void StartReceiveThread ()
 Starts the receive thread. More...
 
void StopReceiveThread ()
 Stops the receive thread. More...
 
bool IsReceiveThreadRunning () const
 Indicates that the receiving thread is running. More...
 
::lcm::LCM * get_lcm_instance ()
 An accessor to the real LCM instance encapsulated by this object. More...
 
std::string get_requested_lcm_url () const
 Returns the LCM URL passed into the constructor; this can be empty. More...
 
void Publish (const std::string &channel, const void *data, int data_size, optional< double > time_sec) override
 Publishes an LCM message on channel channel. More...
 
void Subscribe (const std::string &, HandlerFunction) override
 Subscribes to an LCM channel without automatic message decoding. More...
 
void Subscribe (const std::string &, DrakeLcmMessageHandlerInterface *) override
 A deprecated overload of Subscribe. More...
 
Does not allow copy, move, or assignment
 DrakeLcm (const DrakeLcm &)=delete
 
DrakeLcmoperator= (const DrakeLcm &)=delete
 
 DrakeLcm (DrakeLcm &&)=delete
 
DrakeLcmoperator= (DrakeLcm &&)=delete
 
- Public Member Functions inherited from DrakeLcmInterface
virtual ~DrakeLcmInterface ()=default
 
 DrakeLcmInterface (const DrakeLcmInterface &)=delete
 
DrakeLcmInterfaceoperator= (const DrakeLcmInterface &)=delete
 
 DrakeLcmInterface (DrakeLcmInterface &&)=delete
 
DrakeLcmInterfaceoperator= (DrakeLcmInterface &&)=delete
 

Additional Inherited Members

- Public Types inherited from DrakeLcmInterface
using HandlerFunction = std::function< void(const void *, int)>
 A callback used by DrakeLcmInterface::Subscribe(), with arguments: More...
 
- Protected Member Functions inherited from DrakeLcmInterface
 DrakeLcmInterface ()=default
 

Detailed Description

A wrapper around a real LCM instance.

Constructor & Destructor Documentation

◆ DrakeLcm() [1/4]

DrakeLcm ( const DrakeLcm )
delete

◆ DrakeLcm() [2/4]

DrakeLcm ( DrakeLcm &&  )
delete

◆ DrakeLcm() [3/4]

DrakeLcm ( )

Constructs using LCM's default URL (either the default hard-coded URL, or else LCM_DEFAULT_URL environment variable if it is set).

◆ DrakeLcm() [4/4]

DrakeLcm ( std::string  lcm_url)
explicit

Constructs using the given URL.

If empty, it will use the default URL as per the no-argument constructor.

◆ ~DrakeLcm()

~DrakeLcm ( )
override

A destructor that forces the receive thread to be stopped.

Member Function Documentation

◆ get_lcm_instance()

lcm::LCM * get_lcm_instance ( )

An accessor to the real LCM instance encapsulated by this object.

The returned pointer is guaranteed to be valid for the duration of this object's lifetime.

◆ get_requested_lcm_url()

std::string get_requested_lcm_url ( ) const

Returns the LCM URL passed into the constructor; this can be empty.

◆ IsReceiveThreadRunning()

bool IsReceiveThreadRunning ( ) const
inline

Indicates that the receiving thread is running.

◆ operator=() [1/2]

DrakeLcm& operator= ( const DrakeLcm )
delete

◆ operator=() [2/2]

DrakeLcm& operator= ( DrakeLcm &&  )
delete

◆ Publish()

void Publish ( const std::string &  channel,
const void *  data,
int  data_size,
optional< double time_sec 
)
overridevirtual

Publishes an LCM message on channel channel.

Parameters
[in]channelThe channel on which to publish the message. Must not be the empty string.
[in]dataA buffer containing the serialized bytes of the message to publish.
[in]data_sizeThe length of in bytes.
[in]time_secTime in seconds when the publish event occurred. If unknown, use drake::nullopt or a default-constructed optional.

Implements DrakeLcmInterface.

◆ StartReceiveThread()

void StartReceiveThread ( )

Starts the receive thread.

This must be called for subscribers to receive any messages.

Precondition
StartReceiveThread() was not called.

◆ StopReceiveThread()

void StopReceiveThread ( )

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.

◆ Subscribe() [1/2]

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

Subscribes to an LCM channel without automatic message decoding.

The handler will be invoked when a message arrives on channel channel.

Parameters
channelThe channel to subscribe to. Must not be the empty string.

Implements DrakeLcmInterface.

◆ Subscribe() [2/2]

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

A deprecated overload of Subscribe.

Implements DrakeLcmInterface.


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