Ask Your Question
1

ROS1_bridge: How to map multiple messages and variables with custom datatypes between ROS1- ROS2 using mapping rule yaml file?

asked 2018-09-07 07:25:27 -0500

Rucha gravatar image

updated 2018-09-11 05:44:13 -0500

If there are multiple messages from one ros1 package are to be mapped to multiple messages from one ros2 package, how it should be done using yaml file? I need such mapping in following use-cases:

1) Suppose ros1 package has messages like A.msg, B.msg and ROS2 package has messages like X.msg, Y.msg and I want to map variables of messages as A <-> X, B<->Y. So I tried the mapping in YAML file as: I


 ros1_package_name: 'ros1_test'
 ros1_message_name: 'A'
 ros2_package_name: 'ros2_test'
 ros2_message_name: 'X' 

 fields_1_to_2:
  a_var: 'x_var'

 ros1_package_name: 'ros1_test'
 ros1_message_name: 'B'
 ros2_package_name: 'ros2_test'
 ros2_message_name: 'Y' 

 fields_1_to_2:
  b_var: 'y_var'

If this mapping is used, ROS1 bridge only maps B<->Y. The A<->X mapping is not done; Probably because it is overwritten. So how exactly such multiple message mapping should be done?

2) In this scenario, the problem is with mapping variables of custom datatype consider that A.msg is a message in ROS1 package. X.msg, Y.msg are the messages in ROS2 package; which are as follows:

A. msg (ROS1 message)

int32 a_var

X.msg (ROS2 message)

Y x_var

Y.msg (ROS2 message)

int32 y1
float32 y2
int32 y3

In this case, how to map A.msg <->X.msg and variables a_var <-> x_var.y1 using mapping rules in yaml file?

Looking forward to suggestions and answers.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-09-07 10:15:31 -0500

Dirk Thomas gravatar image

Your YAML snippet looks incorrect. See the documentation for an example:

-
  ros1_package_name: 'ros1_pkg_name'
  ros1_message_name: 'ros1_msg_name'
  ros2_package_name: 'ros2_pkg_name'
  ros2_message_name: 'ros2_msg_name'
  fields_1_to_2:
    foo: 'foo'
    ros1_bar: 'ros2_bar'

Note the dash (-) in the very first line which makes all the following key-values a first item in a list. In order to enumerate multiple entries each of them must have that leading line with that dash (indicating a separate item in the list):

-
  ros1_package_name: 'ros1_pkgA_name'
  ros1_message_name: 'ros1_msgA_name'
  ros2_package_name: 'ros2_pkgA_name'
  ros2_message_name: 'ros2_msgA_name'
  fields_1_to_2:
    foo: 'foo'
    ros1_bar: 'ros2_bar'
-
  ros1_package_name: 'ros1_pkgB_name'
  ros1_message_name: 'ros1_msgB_name'
  ros2_package_name: 'ros2_pkgB_name'
  ros2_message_name: 'ros2_msgB_name'
  fields_1_to_2:
    foo: 'foo'
    ros1_bar: 'ros2_bar'
edit flag offensive delete link more

Comments

Thank you for the answer of scenario 1. I had put '-' as a first line of file but forgot to paste in code snippet of question; However, I did not put '-' before next mapping, so it was not working. Now I added it, and works fine. Could you please suggest solution for scenario 2 ? It is not solved.

Rucha gravatar image Rucha  ( 2018-09-11 05:25:12 -0500 )edit

I guess you have tried a_var <-> x_var.y1 and it didn't work? To support this use case the logic in the ros1_bridge would need to be extended. Please consider to provide a pull request for this use case.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-09-11 11:11:15 -0500 )edit

Yes, I had tried this mapping, but it didn't work. I will have to use this use-case multiple times in my work, so it would be good if such mapping is supported by ros1_bridge.

Rucha gravatar image Rucha  ( 2018-09-12 07:57:44 -0500 )edit

I will try to extend ros1_bridge to support such mapping. Since I am new to this, I wanted to know exactly which code segment needs to be focused for field mapping in ros1_bridge and some starting point to implement this functionality.

Rucha gravatar image Rucha  ( 2018-09-12 08:12:46 -0500 )edit

The rule parsing happens in the Python module ros1_bridge/__init__.py:336 and at some point generates the C++ code which is performing the actual mapping in this template: resource/pkg_factories.cpp.em.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-09-12 10:45:18 -0500 )edit

this point about a dash needing to separate mapped pairs should really be in the tutorial i.e. https://github.com/ros2/ros1_bridge/b...

blarghflargle gravatar image blarghflargle  ( 2020-08-17 23:47:26 -0500 )edit

@blarghflargle The dash is part of the example snippets already. This is just YAML and for a list of items each item is identified by a dash. Please consider to contribute a pull request to the documentation if you want to propose any improvements,

Dirk Thomas gravatar image Dirk Thomas  ( 2020-08-18 00:14:31 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2018-09-07 07:25:27 -0500

Seen: 871 times

Last updated: Sep 11 '18