microRTPS: simplify the attribution of the RTPS IDs by makiing it automatic

1. The RTPS IDs are now automatically assigned to the topics
2. Only the topics that get defined to be sent or received in the urtps_bridge_topics.yaml (renamed, since now it doesn't contain IDs) receive the IDs
3. Any addition or removal on the urtps_bridge_topics.yaml file might update the topic IDs - this will require that the agent and the client ID list has to be in sync. This will further require a robustification of the way we check the IDs and the message definitions when starting the bridge.
This commit is contained in:
TSC21
2021-08-12 08:44:53 +02:00
committed by Nuno Marques
parent f557fbc99f
commit c478e2985a
19 changed files with 226 additions and 802 deletions
+6 -80
View File
@@ -2,7 +2,7 @@
################################################################################
#
# Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
# Copyright (c) 2018-2019 PX4 Development Team. All rights reserved.
# Copyright (c) 2018-2021 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -42,7 +42,6 @@ import os
import argparse
import shutil
import px_generate_uorb_topic_files
import px_generate_uorb_topic_helper
from uorb_rtps_classifier import Classifier
import subprocess
import glob
@@ -70,81 +69,11 @@ except ImportError as e:
sys.exit(1)
def check_rtps_id_uniqueness(classifier):
"""
Checks if there are no ID's for different msgs repeated on the map
"""
repeated_ids = dict()
full_send_list = dict(list(msg for msg in list(classifier.msgs_to_send.items(
))) + list(list(msg[0].items())[0] for msg in classifier.alias_msgs_to_send))
full_receive_list = dict(list(msg for msg in list(classifier.msgs_to_receive.items(
))) + list(list(msg[0].items())[0] for msg in classifier.alias_msgs_to_receive))
full_ignore_list = dict(list(msg for msg in list(classifier.msgs_to_ignore.items(
))) + list(list(msg[0].items())[0] for msg in classifier.alias_msgs_to_ignore))
# check if there are repeated ID's on the messages to send
for key, value in list(full_send_list.items()):
if list(full_send_list.values()).count(value) > 1:
repeated_ids.update({key: value})
# check if there are repeated ID's on the messages to receive
for key, value in list(full_receive_list.items()):
if list(full_receive_list.values()).count(value) > 1:
repeated_ids.update({key: value})
# check if there are repeated ID's on the messages to ignore
for key, value in list(full_ignore_list.items()):
if list(full_ignore_list.values()).count(value) > 1:
repeated_ids.update({key: value})
# check if there are repeated IDs between classified and unclassified msgs
# check send and ignore lists
send_ignore_common_ids = list(set(full_ignore_list.values(
)).intersection(list(full_send_list.values())))
for item in list(full_send_list.items()):
for repeated in send_ignore_common_ids:
if item[1] == repeated:
repeated_ids.update({item[0]: item[1]})
for item in list(full_ignore_list.items()):
for repeated in send_ignore_common_ids:
if item[1] == repeated:
repeated_ids.update({item[0]: item[1]})
# check receive and ignore lists
receive_ignore_common_ids = list(set(full_ignore_list.values(
)).intersection(list(full_receive_list.values())))
for item in list(full_receive_list.items()):
for repeated in receive_ignore_common_ids:
if item[1] == repeated:
repeated_ids.update({item[0]: item[1]})
for item in list(full_ignore_list.items()):
for repeated in receive_ignore_common_ids:
if item[1] == repeated:
repeated_ids.update({item[0]: item[1]})
all_msgs = {}
all_msgs.update(full_send_list)
all_msgs.update(full_receive_list)
all_msgs.update(full_ignore_list)
all_ids = list()
all_ids = list(all_msgs.values())
all_ids.sort()
if not repeated_ids:
print("All good. RTPS ID's are unique")
else:
raise AssertionError(", ".join('%s' % msgs for msgs in list(repeated_ids.keys())) +
" have their ID's repeated. Please choose from the following pool:\n" +
", ".join('%d' % id for id in px_generate_uorb_topic_helper.check_available_ids(all_ids)))
default_client_out = "src/modules/micrortps_bridge/micrortps_client"
default_agent_out = "src/modules/micrortps_bridge/micrortps_agent"
default_uorb_templates_dir = "templates/uorb_microcdr"
default_urtps_templates_dir = "templates/urtps"
default_rtps_id_file = "tools/uorb_rtps_message_ids.yaml"
default_urtps_topics_file = "tools/urtps_bridge_topics.yaml"
default_package_name = px_generate_uorb_topic_files.PACKAGE
parser = argparse.ArgumentParser()
@@ -168,7 +97,7 @@ parser.add_argument("-b", "--uorb-templates-dir", dest='uorb_templates', type=st
parser.add_argument("-q", "--urtps-templates-dir", dest='urtps_templates', type=str,
help="uRTPS templates, by default using relative path to msgdir 'templates/urtps'", default=default_urtps_templates_dir)
parser.add_argument("-y", "--rtps-ids-file", dest='yaml_file', type=str,
help="RTPS msg IDs definition path, by default using relative path to msgdir 'tools/uorb_rtps_message_ids.yaml'", default=default_rtps_id_file)
help="Setup uRTPS bridge topics file path, by default using relative path to msgdir 'tools/urtps_bridge_topics.yaml'", default=default_urtps_topics_file)
parser.add_argument("-p", "--package", dest='package', type=str,
help="Msg package naming, by default px4", default=default_package_name)
parser.add_argument("-o", "--agent-outdir", dest='agentdir', type=str,
@@ -319,13 +248,10 @@ uorb_templates_dir = (args.uorb_templates if os.path.isabs(args.uorb_templates)
urtps_templates_dir = (args.urtps_templates if os.path.isabs(args.urtps_templates)
else os.path.join(msg_dir, args.urtps_templates))
# parse yaml file into a map of ids
# parse yaml file into a map of ids and messages to send and receive
classifier = (Classifier(os.path.abspath(args.yaml_file), msg_dir) if os.path.isabs(args.yaml_file)
else Classifier(os.path.join(msg_dir, args.yaml_file), msg_dir))
# check if there are no ID's repeated
check_rtps_id_uniqueness(classifier)
uRTPS_CLIENT_TEMPL_FILE = 'microRTPS_client.cpp.em'
uRTPS_AGENT_TOPICS_H_TEMPL_FILE = 'RtpsTopics.h.em'
@@ -359,7 +285,7 @@ def generate_agent(out_dir):
if classifier.alias_msgs_to_send:
for msg_file in classifier.alias_msgs_to_send:
msg_alias = list(msg_file[0].keys())[0]
msg_alias = msg_file[0]
msg_name = msg_file[1]
if gen_idl:
if out_dir != agent_out_dir:
@@ -389,7 +315,7 @@ def generate_agent(out_dir):
if classifier.alias_msgs_to_receive:
for msg_file in classifier.alias_msgs_to_receive:
msg_alias = list(msg_file[0].keys())[0]
msg_alias = msg_file[0]
msg_name = msg_file[1]
if gen_idl:
if out_dir != agent_out_dir: