Drake
DrakeLcm Class Reference

Detailed Description

A wrapper around a real LCM instance.

#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 (std::string lcm_url, bool defer_initialization)
 (Advanced) Constructs using the given URL, but with the ability to defer launching the receive thread. More...
 
 ~DrakeLcm () override
 A destructor that forces the receive thread to be stopped. More...
 
::lcm::LCM * get_lcm_instance ()
 (Advanced.) An accessor to the underlying LCM instance. More...
 
std::string get_lcm_url () const
 Returns the LCM URL. More...
 
void Publish (const std::string &, const void *, int, std::optional< double >) override
 Most users should use the drake::lcm::Publish() free function, instead of this interface method. More...
 
std::shared_ptr< DrakeSubscriptionInterfaceSubscribe (const std::string &, HandlerFunction) override
 Most users should use the drake::lcm::Subscribe() free function or the drake::lcm::Subscriber wrapper class, instead of this interface method. More...
 
int HandleSubscriptions (int) override
 Invokes the HandlerFunction callbacks for all subscriptions' pending messages. 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 ()
 
 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 ()
 

Constructor & Destructor Documentation

◆ DrakeLcm() [1/5]

DrakeLcm ( const DrakeLcm )
delete

◆ DrakeLcm() [2/5]

DrakeLcm ( DrakeLcm &&  )
delete

◆ DrakeLcm() [3/5]

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/5]

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() [5/5]

DrakeLcm ( std::string  lcm_url,
bool  defer_initialization 
)

(Advanced) Constructs using the given URL, but with the ability to defer launching the receive thread.

Parameters
defer_initializationcontrols whether or not LCM's background receive thread will be launched immediately during the constructor (when false) or deferred until the first time it's needed (when true). This can be useful if the scheduling configuration for new threads varies between the construction time and and first use. For other constructor overloads, this setting defaults to false – the thread is launched immediately.

◆ ~DrakeLcm()

~DrakeLcm ( )
override

A destructor that forces the receive thread to be stopped.

Member Function Documentation

◆ get_lcm_instance()

::lcm::LCM* get_lcm_instance ( )

(Advanced.) An accessor to the underlying LCM instance.

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

◆ get_lcm_url()

std::string get_lcm_url ( ) const

Returns the LCM URL.

◆ HandleSubscriptions()

int HandleSubscriptions ( int  timeout_millis)
overridevirtual

Invokes the HandlerFunction callbacks for all subscriptions' pending messages.

If timeout_millis is >0, blocks for up to that long until at least one message is handled.

Returns
the number of messages handled, or 0 on timeout.
Exceptions
std::exceptionwhen a subscribed handler throws.

Implements DrakeLcmInterface.

◆ 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,
std::optional< double >  time_sec 
)
overridevirtual

Most users should use the drake::lcm::Publish() free function, instead of this interface method.

Publishes an LCM message on channel channel.

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

Implements DrakeLcmInterface.

◆ Subscribe()

std::shared_ptr<DrakeSubscriptionInterface> Subscribe ( const std::string &  channel,
HandlerFunction   
)
overridevirtual

Most users should use the drake::lcm::Subscribe() free function or the drake::lcm::Subscriber wrapper class, instead of this interface method.

Subscribes to an LCM channel without automatic message decoding. The handler will be invoked when a message arrives on channel channel.

The handler should never throw an exception, because it is indirectly called from C functions.

NOTE: Unlike upstream LCM, DrakeLcm does not support regexes for the channel argument.

Parameters
channelThe channel to subscribe to. Must not be the empty string.
Returns
the object used to manage the subscription if that is supported, or else nullptr if not supported. The unsubscribe-on-delete default is false. Refer to the DrakeSubscriptionInterface class overview for details.

Implements DrakeLcmInterface.


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