rosonic
This is the library to make you as fast as Sonic in developing python-based ROS packages. The name does not actually come from Sonic, but "ROS (made pyth)onic" since the main motivation is making ROS nodes, well, more pythonic. Doing this allows for a more comfortable workflow, the code becomes more "natural" and easier to understand.
To alleviate some of the issues described in Motivation
rosonic tries to gently "force" the user to follow a design pattern. Namely,
rosonic conceptualizes a ROS node as a class in a simple, pythonic way with
reasonable default behaviours.
Requirements
rosonic has been developed for ROS Melodic and above, i.e Python 2.7,
Python 3.6 and above. However, at writing moment only Python 3.6 has been
tested. As soon as I'm transitioning my other projects to Noetic then I will
drop any support for Python 2.7.
Installation
This package is available on PyPI and can be installed as a normal pip package.
pip install rosonic
Usage
Creating a Node
The rosonic barebones, do-nothing ROS node now looks like this
#! /usr/bin/env python
from rosonic import Node
class my_node(Node):
pass
if __name__ == '__main__':
my_node()
The default behaviour of a rosonic.Node will be to call rospy.spin. This is
useful for the "Subscriber" and "Pub-Sub" patterns in
Motivation, then we only need to implement initialization
and callbacks. For the initialization, just create a normal __init__ for the
class that doesn't take any arguments. Any resources, e.g. pub, can be set as
object fields (self.pub) and callbacks can be implemented as methods.
class my_node(Node):
def __init__(self):
self.pub = rospy.Publisher(...)
rospy.Subscriber(..., self.callback)
def callback(self):
self.pub.publish(...)
When calling my_node() you (in order) initialize the ROS node with
the class name, load parameters, create the my_node instance and call
my_node.main. The default main method will call the spin which in turn,
by default, calls rospy.spin.
def main(self):
while self.keep_alive():
self.spin()
self.shutdown()
def spin(self):
rospy.spin()
The added bonus of these defaults is that it is very easy to do the "Publisher"
pattern as well. You specify a rate, write __init__ as before and overload
the spin method. If, however, you want completely different still then you
need to overload main, which is fairly simple in itself!
from rosonic import Node, Rate
class my_node(Node):
rate = 10
def __init__(self):
...
def spin(self):
...
Parameters as class attributes
It isn't the mountain ahead that wears you out - it's the grain of sand in your shoe
What's the easiest way to declare a parameter? Maybe like this...
#! /usr/bin/env python
from rosonic import Node, Parameter
class my_node(Node):
IMAGE1 = Parameter('~image1', 'image1')
IMAGE2 = Parameter('~image2', 'image2')
USE_FILTER = Parameter('~use_filter', True)
...
if __name__ == '__main__':
my_node()
That's the rosonic way at least! You don't have to care about asserting
existence or managing scoping rules. Since they are class fields you have them
available all the time. If Parameter is not given a default value nor is the
optional argument set, then Parameter checks for existence at load time.
A very slim implementation
rosonic tries to be very slim. There is some complexity regarding class
fields. However, it takes 5 minutes to look through the ROS relevant parts. So,
see the implementation as the real documentation!
Metadata
Release files for rosonic 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rosonic-0.2.2.tar.gz | 8.6 kB | Without provenance | Details for rosonic-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rosonic-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for rosonic-0.2.2-py3-none-any.whl |
Total release size: 17.3 kB
Release files / rosonic-0.2.2.tar.gz
| Download URL | rosonic-0.2.2.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09e368e52424fe8d72e4f5a43a0b24c493123f9e0a5af69e4b8c84fc5b6c284c
|
|
BLAKE2b-256 checksum How to use checksums |
cc5d17cc76bb718d93c1decb2355378b57783fd09dfb0688593333081aae5697
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Release files / rosonic-0.2.2-py3-none-any.whl
| Download URL | rosonic-0.2.2-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d6279f1682adeb1f6a9c8c237f487b83728a97b6494edfe49a0ea2f01a3f61e
|
|
BLAKE2b-256 checksum How to use checksums |
2c26258de0ef5d65d5d864d59cef13c0a9658551f43968b39113054e5993cf1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Security for rosonic 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.