This library is intended to be used for small projects that require a simple middleware for communication between processes. It is not intended to be a replacement for ROS.
See these discussions in ROS Discourse and this one in reddit/ROS.
Use pip to install the library:
pip install zerorosThe library is composed of three main classes: Publisher, Subscriber and
MessageBroker.
The MessageBroker class is used to create a message broker that can be used by
publishers and subscribers to communicate with each other.
from zeroros import MessageBroker
broker = MessageBroker()The Publisher class is used to publish messages to a topic. The constructor takes two
arguments: the topic name and the message type. The topic name is a string, while the
message type is a Python class. The message type is used to serialize and deserialize
messages.
from zeroros import Publisher
pub = Publisher("topic_name", String)
pub.publish("Hello world!")The Subscriber class is used to subscribe to a topic and receive messages. The constructor
takes two arguments: the topic name and the message type. The topic name is a string, while
the message type is a Python class. The message type is used to serialize and deserialize
messages.
import time
from zeroros import Subscriber
def callback(msg):
print(msg)
sub = Subscriber("topic_name", String, callback)
while True:
# Do something else
time.sleep(1)
# Stop the subscriber
sub.stop()The library comes with a few built-in messages that can be used out of the box. The following messages are available:
std_msgs.Stringstd_msgs.Intstd_msgs.Floatstd_msgs.Boolstd_msgs.Headergeometry_msgs.Vector3geometry_msgs.Vector3Stampedgeometry_msgs.Twistgeometry_msgs.Quaterniongeometry_msgs.Posegeometry_msgs.PoseStampedgeometry_msgs.PoseWithCovariancegeometry_msgs.TwistWithCovariancenav_msgs.Odometrynav_msgs.Pathsensors_msgs.LaserScan- More to come...
)