Metadata-Version: 2.4
Name: rosmsg_dict_converter
Version: 0.1.2
Summary: Provide a  converter to convert ROS message to dict and vice versa
Author: Wing mun Fung
Author-email: fengrongman@gmail.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rich
Requires-Dist: pydantic
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: license-file
Dynamic: requires-dist
Dynamic: summary

# 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

```bash
pip install rosmsg_dict_converter
```

## Usage

1. ros_message_to_dict

```python
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)
```

2. dict_to_ros_message

```python
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)
```

3. populate_empty_lists

```python
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}}]}
```

4. update_ros_message

```python
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](LICENSE)
