Skip to content

Commit

Permalink
Apply automatic mapping rules in case only package+message mapping ex…
Browse files Browse the repository at this point in the history
…ists (#382)

* Fix message mapping by removing early return so other rules can still be applied

In determine_field_mapping, there was an early return inside a loop over all mapping rules.
IF there we any mapping rules but they don't specify field mappings, the early return made the function return without creating mappings automatically.

For a particular message type, ROS 1's uuid_msgs/UniqueID vs ROS 2's unique_identifier_msgs/UUID, the message definition is exacly the same but type name is not.
The only mapping fule defined in for unique_identifier_msgs/UUID is that it maps to uuid_msgs/UniqueID, but no field mappings are needed because the definitions are the same.

But, then we hit the early return (because the for-loop is ran without any rule applying to the message at hand and thus not `continue`-ing in a code branch handling a rule)
and return without applying the normal automatic field mapping generation rules.

By removing the early return, the other rules are applied and the mapping rules for handling the exact same message defintions are applied

Signed-off-by: Loy van Beek <loy.vanbeek@mojin-robotics.de>

* Account for fields mapped by rules when checking for missed fields

The code after the early return mentioned in the previous commit assumed all fields would match by name,
which was of course true. But not anymore, so the missing check now only fails when the missing fields are also not already accounted for via a mapping

Signed-off-by: Loy van Beek <loy.vanbeek@mojin-robotics.de>

* Fix flake8 violations

Signed-off-by: Loy van Beek <loy.vanbeek@mojin-robotics.de>

Signed-off-by: Loy van Beek <loy.vanbeek@mojin-robotics.de>
  • Loading branch information
LoyVanBeek authored Nov 6, 2022
1 parent 81f8b08 commit 2381bf4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ros1_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,21 +785,27 @@ def determine_field_mapping(ros1_msg, ros2_msg, mapping_rules, msg_idx):
file=sys.stderr)
continue
mapping.add_field_pair(ros1_selected_fields, ros2_selected_fields)
return mapping

# apply name based mapping of fields
ros1_field_missing_in_ros2 = False

ros1_fields_not_mapped = []
for ros1_field in ros1_spec.parsed_fields():
for ros2_member in ros2_spec.structure.members:
if ros1_field.name.lower() == ros2_member.name:
# get package name and message name from ROS 1 field type
update_ros1_field_information(ros1_field, ros1_msg.package_name)
mapping.add_field_pair(ros1_field, ros2_member)
break
else:

ros1_fields_mapped_to_a_ros2_member = [field[0].name
for field
in mapping.fields_1_to_2.keys()]
if ros1_field.name not in ros1_fields_mapped_to_a_ros2_member:
# this allows fields to exist in ROS 1 but not in ROS 2
ros1_field_missing_in_ros2 = True
ros1_fields_not_mapped += [ros1_field]

ros1_field_missing_in_ros2 = any(ros1_fields_not_mapped)

if ros1_field_missing_in_ros2:
# if some fields exist in ROS 1 but not in ROS 2
Expand Down

0 comments on commit 2381bf4

Please sign in to comment.