ROS 2 interface definitions, serialization, hashes, and ROS Python conversions
Project description
ROS 2 PyTerfaces IDL
ROS 2 message and service definitions, metadata and serialization in Python.
Create new message types, (de)serialize them, compute the RIHS01 hash, and
convert to and from ROS 2 Python messages. All ROS 2 common_interfaces are
reimplemented, and every message tested to interoperate with ROS.
Based on Cyclone DDS IDL, but specialized for ROS 2.
[!NOTE] This is a low level tool to send/receive raw payload with ROS 2, and to set up communications on the RMW.
Table of Contents
Install
pip install git+https://github.com/2lian/ros2-pyterfaces.git
Example
Message
from dataclasses import dataclass
from ros2_pyterfaces.idl import IdlStruct, types
@dataclass
class Vector3(IdlStruct, typename="geometry_msgs/msg/Vector3"):
x: types.float64 = 0.0
y: types.float64 = 0.0
z: types.float64 = 0.0
my_msg: Vector3 = Vector3(1,2,3)
# serialization
blob_bytes: bytes = my_msg.serialize()
my_msg_again: Vector3 = Vector3.deserialize(blob_bytes)
# ROS 2 metadata
json_type_description = Vector3.json_type_description()
ros_hash = Vector3.hash_rihs01()
# ROS 2 conversion
ros_msg_type = Vector3.to_ros_type()
ros_msg = my_msg.to_ros()
our_msg: Vector3 = Vector3.from_ros(ros_msg)
Service
Services follow the ROS naming pattern: *_Request, *_Response, *_Event,
plus a small wrapper type. The serializable types are the request, response,
and event dataclasses. The top-level service type is usually created with
make_idl_service(...). If you omit event_type=... (most cases), the factory
generates a matching event type for you.
from dataclasses import dataclass
from ros2_pyterfaces import idl
# Same classes definition as Messages for *_Request *_Response
@dataclass
class SetBool_Request(idl.IdlStruct, typename="std_srvs/srv/SetBool_Request"):
data: bool = False
@dataclass
class SetBool_Response(idl.IdlStruct, typename="std_srvs/srv/SetBool_Response"):
success: bool = False
message: str = ""
# Top-level service type
SetBool = idl.make_idl_service(SetBool_Request, SetBool_Response)
# Serialization
some_request: SetBool_Request = SetBool.Request(data=True)
some_response: SetBool_Response = SetBool.Response(success=True, message="yey")
# ROS 2 metadata
json_type_description = SetBool.json_type_description()
ros_hash = SetBool.hash_rihs01()
# ROS 2 conversion
ros_srv_type = SetBool.to_ros_type()
ros_request = some_request.to_ros()
request_again = SetBool.Request.from_ros(ros_request)
ros_response = some_response.to_ros()
response_again = SetBool.Response.from_ros(ros_response)
[!WARNING] Not implemented yet:
- Actions
Attribution
The low-level IDL model, serialization behavior, and part of the user API are dependent on (fantastic) Cyclone DDS Python's idl: https://github.com/eclipse-cyclonedds/cyclonedds-python.
Replicated ROS 2 Messages Repos
Included Interfaces
ros2_pyterfaces.builtin_interfaces: msg.pyros2_pyterfaces.composition_interfaces: srv.pyros2_pyterfaces.diagnostic_msgs: msg.py, srv.pyros2_pyterfaces.geometry_msgs: msg.pyros2_pyterfaces.lifecycle_msgs: msg.py, srv.pyros2_pyterfaces.nav_msgs: msg.py, srv.pyros2_pyterfaces.rcl_interfaces: msg.py, srv.pyros2_pyterfaces.rosgraph_msgs: msg.pyros2_pyterfaces.sensor_msgs: msg.py, srv.pyros2_pyterfaces.service_msgs: msg.pyros2_pyterfaces.shape_msgs: msg.pyros2_pyterfaces.statistics_msgs: msg.pyros2_pyterfaces.std_msgs: msg.pyros2_pyterfaces.std_srvs: srv.pyros2_pyterfaces.stereo_msgs: msg.pyros2_pyterfaces.test_msgs: msg.pyros2_pyterfaces.type_description_interfaces: msg.py, srv.pyros2_pyterfaces.trajectory_msgs: msg.pyros2_pyterfaces.unique_identifier_msgs: msg.pyros2_pyterfaces.visualization_msgs: msg.py, srv.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ros2_pyterfaces-0.1.1.tar.gz.
File metadata
- Download URL: ros2_pyterfaces-0.1.1.tar.gz
- Upload date:
- Size: 34.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b079257525d665083ee09d97e9dfffd549ebe76e008b3acf8d95778cd0ea7c6
|
|
| MD5 |
681501cd99b05860adc1df56cf3767dc
|
|
| BLAKE2b-256 |
8bc400ba91f31dad78423c2178e293e062e4b1a6e3c7384dd4f58344273ad87c
|
File details
Details for the file ros2_pyterfaces-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ros2_pyterfaces-0.1.1-py3-none-any.whl
- Upload date:
- Size: 37.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
277b6758fcd8b42df79853ee0318f2fc0b8b80f14680ad6dfb999c5f1d768238
|
|
| MD5 |
1214e9ba3bd57d0cd987b071b857b84f
|
|
| BLAKE2b-256 |
eec3a089da8d9e22fdfa07e4afbe93bc7b2e781f4485f423df84b6478e1d7012
|