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.0.tar.gz (9.5 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.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rosmsg_dict_converter-0.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for rosmsg_dict_converter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 22c753b3471dac9beeefa7b01310ad08d932cfdc2dd4a97a5e44606ed1ac1ab0
MD5 070bc6d3a3e7ee97b3fc6c3c98ca8028
BLAKE2b-256 2f463a970f72a1e0b9a5ac4634c6a347826aaa0ce6e9cd9a554f39279d3f864e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rosmsg_dict_converter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6400276d0cf15f30f155ccbc8a8784556c6345c70ac21ab1720db867fef0c45
MD5 1eacba8ede54f3fdc27b269a797299f7
BLAKE2b-256 3436be725a77cd73c3424a713dc835be6c2c37cc147ba3b8b78452415517f975

See more details on using hashes here.

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