Drake
Drake C++ Documentation
drake::lcm Namespace Reference

Classes

class  DrakeLcm
 A wrapper around a real LCM instance. More...
 
class  DrakeLcmBase
 A concrete subclass of DrakeInterface that throws for all functions except the constructor and destructor. More...
 
class  DrakeLcmInterface
 A pure virtual interface that enables LCM to be mocked. More...
 
class  DrakeLcmLog
 A LCM interface for logging LCM messages to a file or playing back from a existing log. More...
 
struct  DrakeLcmParams
 The set of parameters for configuring DrakeLcm. More...
 
class  DrakeSubscriptionInterface
 A helper class returned by DrakeLcmInterface::Subscribe() that allows for (possibly automatic) unsubscription and/or queue capacity control. More...
 
class  Subscriber
 Subscribes to and stores a copy of the most recent message on a given channel, for some Message type. More...
 

Functions

template<typename Message >
void Publish (DrakeLcmInterface *lcm, const std::string &channel, const Message &message, std::optional< double > time_sec={})
 Publishes an LCM message on channel channel. More...
 
template<typename Message >
std::shared_ptr< DrakeSubscriptionInterfaceSubscribe (DrakeLcmInterface *lcm, const std::string &channel, std::function< void(const Message &)> handler, std::function< void()> on_error={})
 Subscribes to an LCM channel named channel and decodes messages of type Message. More...
 
int LcmHandleSubscriptionsUntil (DrakeLcmInterface *lcm, const std::function< bool(void)> &finished, int timeout_millis=100)
 Convenience function that repeatedly calls lcm->HandleSubscriptions() with a timeout value of timeout_millis, until finished() returns true. More...
 
template<typename Message >
std::vector< uint8_t > EncodeLcmMessage (const Message &message)
 Encodes an LCM message to a series of bytes. More...
 
template<typename Message >
Message DecodeLcmMessage (const std::vector< uint8_t > &bytes)
 Decodes an LCM message from a series of bytes. More...
 
template<typename Message >
bool AreLcmMessagesEqual (const Message &a, const Message &b)
 Compares two LCM messages of the same type to see if they are equal. More...
 
bool CompareLcmtDrakeSignalMessages (const lcmt_drake_signal &actual_message, const lcmt_drake_signal &expected_message)
 Compares two drake::lcmt_drake_signal messages are equal. More...
 

Function Documentation

◆ AreLcmMessagesEqual()

bool drake::lcm::AreLcmMessagesEqual ( const Message &  a,
const Message &  b 
)

Compares two LCM messages of the same type to see if they are equal.

◆ CompareLcmtDrakeSignalMessages()

bool drake::lcm::CompareLcmtDrakeSignalMessages ( const lcmt_drake_signal &  actual_message,
const lcmt_drake_signal &  expected_message 
)

Compares two drake::lcmt_drake_signal messages are equal.

Parameters
[in]actual_messageThe actual message to be compared against expected_message.
[in]expected_messageThe expected message to be compared against actual message.
Returns
true if actual_message and expected_message are equal.

◆ DecodeLcmMessage()

Message drake::lcm::DecodeLcmMessage ( const std::vector< uint8_t > &  bytes)

Decodes an LCM message from a series of bytes.

Exceptions
std::exceptionif decoding fails.

◆ EncodeLcmMessage()

std::vector<uint8_t> drake::lcm::EncodeLcmMessage ( const Message &  message)

Encodes an LCM message to a series of bytes.

◆ LcmHandleSubscriptionsUntil()

int drake::lcm::LcmHandleSubscriptionsUntil ( DrakeLcmInterface lcm,
const std::function< bool(void)> &  finished,
int  timeout_millis = 100 
)

Convenience function that repeatedly calls lcm->HandleSubscriptions() with a timeout value of timeout_millis, until finished() returns true.

Returns the total number of messages handled.

◆ Publish()

void drake::lcm::Publish ( DrakeLcmInterface lcm,
const std::string &  channel,
const Message &  message,
std::optional< double time_sec = {} 
)

Publishes an LCM message on channel channel.

Parameters
lcmThe LCM service on which to publish the message. Must not be null.
channelThe channel on which to publish the message. Must not be the empty string.
messageThe message to publish.
time_secTime in seconds when the publish event occurred. If unknown, use the default value of nullopt.

◆ Subscribe()

std::shared_ptr<DrakeSubscriptionInterface> drake::lcm::Subscribe ( DrakeLcmInterface lcm,
const std::string &  channel,
std::function< void(const Message &)>  handler,
std::function< void()>  on_error = {} 
)

Subscribes to an LCM channel named channel and decodes messages of type Message.

See also drake::lcm::Subscriber for a simple way to passively observe received messages, without the need to write a handler function.

Parameters
lcmThe LCM service on which to subscribe. Must not be null.
channelThe channel on which to subscribe. Must not be the empty string.
handlerThe callback when a message is received and decoded without error.
on_errorThe callback when a message is received and cannot be decoded; if no error handler is given, an exception is thrown instead.
Returns
the object used to unsubscribe if that is supported, or else nullptr if unsubscribe is not supported. The unsubscribe-on-delete default is false, so that ignoring this result leaves the subscription intact. Refer to the DrakeSubscriptionInterface class overview for details.
Note
Depending on the specific DrakeLcmInterface implementation, the handler might be invoked on a different thread than this function.