Class LCM
object --+
|
lcm.LCM
The LCM class provides a connection to an LCM network.
usage:
m = LCM ([provider])
provider is a string specifying the LCM network to join. Since the
Python LCM bindings are a wrapper around the C implementation, consult
the C API documentation on how provider should be formatted. provider
may be None or the empty string, in which case a default network is
chosen.
To subscribe to a channel:
def msg_handler(channel, data):
# message handling code here. For example:
print("received %d byte message on %s" % (len(data), channel))
m.subscribe(channel, msg_handler)
To transmit a raw binary string:
m.publish("CHANNEL_NAME", data)
In general, LCM is used with python modules compiled by lcm-gen, each
of which provides the instance method encode() and the static method
decode(). Thus, if one had a compiled type named example_t, the following
message handler would decode the message:
def msg_handler(channel, data):
msg = example_t.decode(data)
and the following usage would publish a message:
msg = example_t()
# ... set member variables of msg
m.publish("CHANNEL_NAME", msg.encode())
|
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature |
|
|
int
|
fileno()
Returns a file descriptor suitable for use with select, poll, etc. |
|
|
None
|
handle()
waits for and dispatches the next incoming message |
|
|
int
|
|
None
|
publish(channel,
data)
Publishes a message to an LCM network |
|
|
LCMSubscription
|
subscribe(channel,
callback)
Registers a callback function to handle messages received on the
specified channel. |
|
|
None
|
unsubscribe(subscription_object)
Unregisters a message handler so that it will no longer be invoked
when a message on the specified channel is received |
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__init__(...)
(Constructor)
|
|
x.__init__(...) initializes x; see help(type(x)) for signature
- Overrides:
object.__init__
|
handle_timeout(timeout_millis)
|
|
New in LCM 1.1.0
waits for and dispatches the next incoming message, with a
timeout.
Raises ValueError if @p timeout_millis is invalid, or IOError if
another error occurs.
- Parameters:
timeout_millis - the amount of time to wait, in milliseconds. @return 0 if the
function timed out, >1 if a message was handled.
- Returns: int
|
Publishes a message to an LCM network
- Parameters:
channel - specifies the channel to which the message should be published.
data - binary string containing the message to publish
- Returns: None
|
subscribe(channel,
callback)
|
|
Registers a callback function to handle messages received on the
specified channel.
Multiple handlers can be registered for the same channel
- Parameters:
channel - LCM channel to subscribe to. Can also be a GLib/PCRE regular
expression. Implicitly treated as the regex
"^channel$"
callback - Message handler, must accept two arguments. When a message is
received, callback is invoked with two arguments corresponding to
the actual channel on which the message was received, and a
binary string containing the raw message bytes.
- Returns: LCMSubscription
|
unsubscribe(subscription_object)
|
|
Unregisters a message handler so that it will no longer be invoked
when a message on the specified channel is received
- Parameters:
subscription_object - An LCMSubscription object, as returned by a call to subscribe()
- Returns: None
|