Skip to main content

A ROS2 package for transmitting NumPy ndarrays between ROS2 nodes.

Project description

ROS2 Humble ROS2 Jazzy Python 3.10+ License: MIT Document Style Lint & Format / Test

ROS2 NDArray Message

A ROS2 package for transmitting NumPy ndarrays between ROS2 nodes.

Features

  • Custom ROS2 message type for numpy.ndarray
  • Bi-directional conversion between NumPy arrays and ROS2 messages
  • Multi-dimensional array support with various data types
  • Type-safe Python utilities with full type hints

Requirements

  • ROS2 Humble or higher
  • Python 3.10+

Installation

cd ~/ros2_ws/src
git clone https://github.com/Geson-anko/numpy_ndarray_msgs.git
cd ../
colcon build --packages-select numpy_ndarray_msgs
source install/setup.sh

Install Python Utility Package

pip install ros2-ndarray-msg-utils

Usage

Python Utility Package

import numpy as np
from ndarray_msg_utils import to_ros_msg, from_ros_msg, NDArray
from rclpy.clock import ROSClock

# Convert NumPy array to ROS2 message
array = np.array([[1, 2], [3, 4]], dtype=np.float32)

# Type Hint
msg: NDArray

msg = to_ros_msg(array)

# with Header
msg = to_ros_msg(array, timestamp=ROSClock().now(), frame_id="array_frame")

# Convert back to NumPy array
restored = from_ros_msg(msg)

PyTorch Support

pip install "ros2-ndarray-msg-utils[torch]"
import torch
from ndarray_msg_utils.torch import to_ros_msg, from_ros_msg

# Convert PyTorch tensor to ROS2 message
tensor = torch.tensor([[1, 2], [3, 4]], dtype=torch.float32)
msg = to_ros_msg(tensor)

# Convert back to PyTorch tensor
restored = from_ros_msg(msg)

License

MIT License

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

ros2_ndarray_msg_utils-0.2.0.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ros2_ndarray_msg_utils-0.2.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file ros2_ndarray_msg_utils-0.2.0.tar.gz.

File metadata

  • Download URL: ros2_ndarray_msg_utils-0.2.0.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ros2_ndarray_msg_utils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9a0d1f11bb503ae7a810ce873e61bf46b6717257161ebb2962e677b0046f8f3d
MD5 62f61bbe0c6b311dfe55224e2a120af7
BLAKE2b-256 f85f31d4dbf826212037481b8a598c3213211b5e5d94bd31c3d638850de91d65

See more details on using hashes here.

Provenance

The following attestation bundles were made for ros2_ndarray_msg_utils-0.2.0.tar.gz:

Publisher: publish-to-pypi.yml on Geson-anko/numpy_ndarray_msgs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ros2_ndarray_msg_utils-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ros2_ndarray_msg_utils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 624cc24e1af92326c2107b80043e730dd957956564bc49fb1034437ca0c7c6da
MD5 5163bac791f6900e536361706871870f
BLAKE2b-256 7c71376b8887b7fbeffe2f73eda263fe7579300b01008f617547858223eee21b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ros2_ndarray_msg_utils-0.2.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on Geson-anko/numpy_ndarray_msgs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page