ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Use custom class objects as ros2 msg type

asked 2023-06-14 07:23:35 -0500

benpbabu gravatar image

I'm working with ros2 humble in python, trying to implement two nodes say Node1 & Node2. Node2 is subscribed to Node1. My requirement is for Node1 to publish a box object (containing a nested dictionary structure) to Node2. Since box is not a supported format I'm currently converting the box object to string and publishing, which beats the purpose of box. I would like to create a custom message type/interface to send the box object as such. How can I achieve this? Thanks in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-14 08:48:31 -0500

Andreas Z gravatar image

What you want is a custom message interface. This requires building an interface package and defining your custom .msg file. It is not recommended to convert complex datatypes into strings end then decode.

The custom interfaces are explained in this tutorial https://docs.ros.org/en/humble/Tutori...

You could store one single dictionary key value pair as a separate custom message like so

# DictEntry.msg
string key
string value

And then make your Box datatype holding a list of these DictEntrys

# BoxDict
DictEntry[] data
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2023-06-14 07:23:35 -0500

Seen: 794 times

Last updated: Jun 14 '23