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.1.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.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rosmsg_dict_converter-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b9564304e063e72645083502e78eb1b24780ecdf3b515feb9c2564677cecf35a
MD5 f2f459ac4d2c5c243d5ab2df78cddeba
BLAKE2b-256 56d2fb85a8a24c2e15aac5aa85a4fa63f1001c5b111121f4f427a21190450edc

See more details on using hashes here.

Provenance

The following attestation bundles were made for rosmsg_dict_converter-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rosmsg_dict_converter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db072d73a203303348da6eac643582fc24e8374daf6829bc5fc7b757bcddde71
MD5 ae80efcb1d991f81b4f1e768185dac06
BLAKE2b-256 930d85fcc13728264f7098e80d8a406fe7e77de71f18ca57b3a065b9e7f81e40

See more details on using hashes here.

Provenance

The following attestation bundles were made for rosmsg_dict_converter-0.1.1-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