Karana.KUtils.ros#
Contains classes for interacting with ROS.
Classes#
This class provides a simplified interface for ros pub/sub. |
Package Contents#
- class Karana.KUtils.ros.EasyPubSub(name)#
This class provides a simplified interface for ros pub/sub.
It creates a node and runs an executor on a background thread. Publishers are lazily created the first time a message is published on a topic. Subscriptions simply cache their latest value. The method, processSubscriptions, can be called as part of the simulation loop to sweep through all subscriptions which have new messages and invoke their callbacks.
- queue_size = 10#
- property executor: rclpy.executors.MultiThreadedExecutor#
Get the executor.
- Returns:
The executor.
- Return type:
MultiThreadedExecutor
- close()#
Shutdown the executor, node, and rclpy context.
- publish(topic: str, msg: Any)#
Publish a message.
Note: all messages on the same topic must have the same type
- Parameters:
topic (str) – The name of the topic the message will be published to
msg (Any) – The ROS message to publish
- subscribe(topic: str, msg_type, callback: collections.abc.Callable) str#
Subscribe to a topic.
Note: there can be multiple subscriptions to the same topic as long as they use a consistent message type.
- Parameters:
topic (str) – The name of the topic to subscribe to
msg_type – The type of ROS message to subscribe to
callback (Callable) – The user callback to handle an incoming message. This will be called whenever processSubscriptions is called and a new message has arrived since the last time it was called. If multiple messages have arrived, only the most recent one will be used.
- Returns:
A unique string which identifies this subscription
- Return type:
str
- unsubscribe(uuid: str)#
Remove an existing subscription.
- Parameters:
uuid (str) – A unique id previously returned by subscribe
- processSubscriptions()#
Invoke callbacks for all subscriptions with new values.