Skip to main content

Provide a converter to convert ROS message to dict and vice versa

Project description

rosmsg_dict_converter

Description

This package provides a tool to convert a ROS message dictionary to a Python dictionary and vice versa.

Features

  • Convert a ROS message dictionary to a Python dictionary
  • Convert a Python dictionary to a ROS message dictionary
  • Allow populate empty lists with default values for the message types.
  • Also allows passing an existing message to update its fields with values from the dictionary.

Installation

pip install rosmsg_dict_converter

Usage

  1. ros_message_to_dict
from rosmsg_dict_converter.converver import ros_message_to_dict

from geometry_msgs.msg import Pose

# ros message to dict
pose = Pose()
pose_dict = ros_message_to_dict(pose)
  1. dict_to_ros_message
from rosmsg_dict_converter.converver import dict_to_ros_message

from geometry_msgs.msg import Pose

# dict to ros message
pose_dict = {
    'position': {
        'x': 1.0,
        'y': 2.0,
        'z': 3.0
    },
    'orientation': {
        'x': 0.0,
        'y': 0.0,
        'z': 0.0,
        'w': 1.0
    }
}
pose = dict_to_ros_message("geometry_msgs/Pose", pose_dict)
  1. populate_empty_lists
from rosmsg_dict_converter.converver import ros_message_to_dict,

from geometry_msgs.msg import PoseArray

# ros message to dict
pose_array = PoseArray()
pose_array_dict = ros_message_to_dict(pose_array, include_defaults=True)
# output
# pose_array_dict={'header': {'seq': 0, 'stamp': {'secs': 0, 'nsecs': 0}, 'frame_id': ''}, 'poses': [{'position': {'x': 0.0, 'y': 0.0, 'z': 0.0}, 'orientation': {'x': 0.0, 'y': 0.0, 'z': 0.0, 'w': 0.0}}]}
  1. update_ros_message
from rosmsg_dict_converter.converver import a_dict_to_ros_message,ros_message_to_dict
from geometry_msgs.msg import Point

point = Point()
point.x = 1.0

point_dict = ros_message_to_dict(point)
point_dict["y"] = 2.0

# the value of point.x is still 1.0
point = a_dict_to_ros_message(point, point_dict)
console.print(f"{point=}")

# output
# point=Point(x=1.0, y=2.0, z=0.0)

License

Apache License 2.0

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

rosmsg_dict_converter-0.1.2.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

rosmsg_dict_converter-0.1.2-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file rosmsg_dict_converter-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for rosmsg_dict_converter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f27b22c09cbee00d93bbf7eb25267658634496ac8634d70413874181ce6d8675
MD5 221a359d32becc94ca47f3a55d184afb
BLAKE2b-256 3c3012f5d37edc358014837306f2ad934779733ec28692af8b62c6d29b8a05d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rosmsg_dict_converter-0.1.2.tar.gz:

Publisher: ci.yaml on yumeminami/rosmsg_dict_converter

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

File details

Details for the file rosmsg_dict_converter-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for rosmsg_dict_converter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b6b046890dcb6703f04295d07d64b992928ecd612324c3918157d787253a0f2
MD5 b9f862fa79c81412c8fb9291dc5b42cc
BLAKE2b-256 59e686128b9453f229f11cedc93910d62f7fb93bac34c5ccdf6f7c4f0ac19c23

See more details on using hashes here.

Provenance

The following attestation bundles were made for rosmsg_dict_converter-0.1.2-py3-none-any.whl:

Publisher: ci.yaml on yumeminami/rosmsg_dict_converter

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