Skip to content

Commit

Permalink
Fix mapping generation for ROS actions
Browse files Browse the repository at this point in the history
This fixes a redefinition error when using `mapping_rules.yaml`
to bridge ROS actions.

I applied the patch done in ros2#268
for the ROS services to the ROS actions and it solved the redefinition
error.

Additional improvements:
- Iterate over both the ros1 and ros2 component directly in the for loop
  by using `zip`.

Signed-off-by: Erick Kramer <e.kramer@rethinkrobotics.com>
  • Loading branch information
ErickKramer committed Oct 26, 2023
1 parent db704a4 commit 5930dd6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ros1_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,17 +848,20 @@ def determine_common_actions(
for rule in mapping_rules:
for ros1_action in ros1_actions:
for ros2_action in ros2_actions:
pair = (ros1_action, ros2_action)
if pair in pairs:
continue
if rule.ros1_package_name == ros1_action.package_name and \
rule.ros2_package_name == ros2_action.package_name:
if rule.ros1_action_name is None and rule.ros2_action_name is None:
if ros1_action.message_name == ros2_action.message_name:
pairs.append((ros1_action, ros2_action))
pairs.append(pair)
else:
if (
rule.ros1_action_name == ros1_action.message_name and
rule.ros2_action_name == ros2_action.message_name
):
pairs.append((ros1_action, ros2_action))
pairs.append(pair)

for pair in pairs:
ros1_spec = load_ros1_action(pair[0])
Expand All @@ -883,17 +886,17 @@ def determine_common_actions(
if len(ros1_fields[direction]) != len(ros2_fields[direction]):
match = False
break
for i, ros1_field in enumerate(ros1_fields[direction]):
for ros1_field, ros2_field in zip(ros1_fields[direction], ros2_fields[direction]):
ros1_type = ros1_field[0]
ros2_type = str(ros2_fields[direction][i].type)
ros2_type = str(ros2_field.type)
ros1_name = ros1_field[1]
ros2_name = ros2_fields[direction][i].name
ros2_name = ros2_field.name
if ros1_name != ros2_name:
# if the message types have a custom mapping their names
# might not be equal, therefore check the message pairs

ros1_is_builtin = genmsg.msgs.is_builtin(genmsg.msgs.bare_msg_type(ros1_type))
ros2_is_builtin = ros2_fields[direction][i].type.is_primitive_type()
ros2_is_builtin = ros2_field.type.is_primitive_type()

# Check if types are primitive types
if not ros1_is_builtin or not ros2_is_builtin or ros1_type != ros2_type:
Expand Down

0 comments on commit 5930dd6

Please sign in to comment.