pydrake.lcm

class pydrake.lcm.DrakeLcm

Bases: pydrake.lcm.DrakeLcmInterface

A wrapper around a real LCM instance.

class pydrake.lcm.DrakeLcmInterface

A pure virtual interface that enables LCM to be mocked.

Because it must be pure, in general it will receive breaking API changes without notice. Users should not subclass this interface directly, but rather use one of the existing subclasses instead.

Similarly, method arguments will receive breaking API changes without notice. Users should not call this interface directly, but rather use drake::lcm::Publish() or drake::lcm::Subscribe() instead.

HandleSubscriptions(self: pydrake.lcm.DrakeLcmInterface, timeout_millis: int) → int

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.
Raises:RuntimeError when a subscribed handler throws.
Publish(self: pydrake.lcm.DrakeLcmInterface, channel: str, buffer: bytes, time_sec: Optional[float] = None) → None

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

Publishes an LCM message on channel channel.

Parameter channel:
The channel on which to publish the message. Must not be the empty string.
Parameter data:
A buffer containing the serialized bytes of the message to publish.
Parameter data_size:
The length of @data in bytes.
Parameter time_sec:
Time in seconds when the publish event occurred. If unknown, use nullopt or a default-constructed optional.
class pydrake.lcm.DrakeMockLcm

Bases: pydrake.lcm.DrakeLcmInterface

A mock LCM instance. This only manipulates LCM messages in memory, not on the wire. It is similar to a DrakeLcm object with a “memq://” URL, but is guaranteed to behave deterministically (without a hidden background thread).

Subscribe(self: pydrake.lcm.DrakeMockLcm, channel: str, handler: Callable[[bytes], None]) → None
class pydrake.lcm.Subscriber(lcm, channel, lcm_type)

Bases: object

Subscribes to and stores a copy of the most recent message on a given channel, for some message type. This class does NOT provide any mutex behavior for multi-threaded locking; it should only be used in cases where the governing DrakeLcmInterface.HandleSubscriptions is called from the same thread that owns all copies of this object.

__init__(lcm, channel, lcm_type)

Creates a subscriber and subscribes to channel on lcm.

Parameters:
  • lcm – LCM service instance (a pydrake.lcm.DrakeLcmInterface).
  • channel – LCM channel name.
  • lcm_type – Python class generated by lcmgen.
clear()