From 1970ef875f346098388ba22217763a94ddf69d4b Mon Sep 17 00:00:00 2001 From: TSC21 Date: Wed, 2 Oct 2019 10:40:37 +0100 Subject: [PATCH] micrortps bridge: clean templates; add backwards compatibility; add ROS2 compatibility --- msg/templates/urtps/Publisher.cpp.em | 37 +++++--- msg/templates/urtps/Publisher.h.em | 10 +-- msg/templates/urtps/RtpsTopics.cpp.em | 6 +- msg/templates/urtps/RtpsTopics.h.em | 2 +- msg/templates/urtps/Subscriber.cpp.em | 32 ++++--- msg/templates/urtps/Subscriber.h.em | 12 +-- .../urtps/microRTPS_agent_CMakeLists.txt.em | 2 +- msg/templates/urtps/microRTPS_transport.h | 2 +- msg/templates/urtps/msg.idl.em | 41 ++++----- msg/tools/generate_microRTPS_bridge.py | 86 ++++++++++++------- msg/tools/px_generate_uorb_topic_files.py | 26 +++--- .../micrortps_client/CMakeLists.txt | 4 - 12 files changed, 147 insertions(+), 113 deletions(-) diff --git a/msg/templates/urtps/Publisher.cpp.em b/msg/templates/urtps/Publisher.cpp.em index a77f27932f..9683e7ed47 100644 --- a/msg/templates/urtps/Publisher.cpp.em +++ b/msg/templates/urtps/Publisher.cpp.em @@ -20,7 +20,7 @@ topic = alias if alias else spec.short_name /**************************************************************************** * * Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). - * Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved. + * Copyright (C) 2018-2019 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: @@ -54,7 +54,7 @@ topic = alias if alias else spec.short_name * @@file @(topic)_Publisher.cpp * This file contains the implementation of the publisher functions. * - * This file was generated by the tool fastcdrgen. + * This file was adapted from the fastcdrgen tool. */ #include @@ -64,7 +64,9 @@ topic = alias if alias else spec.short_name #include +@[if 1.5 < fastrtpsgen_version <= 1.7]@ #include +@[else]@ #include "@(topic)_Publisher.h" @@ -76,26 +78,34 @@ topic = alias if alias else spec.short_name bool @(topic)_Publisher::init() { // Create RTPSParticipant - ParticipantAttributes PParam; PParam.rtps.builtin.domainId = 0; +@[if 1.5 < fastrtpsgen_version <= 1.7]@ PParam.rtps.builtin.leaseDuration = c_TimeInfinite; +@[else]@ + PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite; +@[end if]@ PParam.rtps.setName("@(topic)_publisher"); //You can put here the name you want mp_participant = Domain::createParticipant(PParam); if(mp_participant == nullptr) return false; - //Register the type - - Domain::registerType(mp_participant, (TopicDataType*) &myType); + // Register the type + Domain::registerType(mp_participant, static_cast(&myType)); // Create Publisher - PublisherAttributes Wparam; Wparam.topic.topicKind = NO_KEY; Wparam.topic.topicDataType = myType.getName(); //This type MUST be registered +@[if 1.5 < fastrtpsgen_version <= 1.7]@ Wparam.topic.topicName = "@(topic)_PubSubTopic"; - mp_publisher = Domain::createPublisher(mp_participant, Wparam, (PublisherListener*) &m_listener); +@[else]@ + Wparam.topic.topicName = "@(topic)PubSubTopic"; +@[end if]@ +@[if ros2_distro and ros2_distro != "ardent"]@ + Wparam.topic.topicName = "rt/" + Wparam.topic.topicName; +@[end if]@ + mp_publisher = Domain::createPublisher(mp_participant, Wparam, static_cast(&m_listener)); if(mp_publisher == nullptr) return false; //std::cout << "Publisher created, waiting for Subscribers." << std::endl; @@ -120,12 +130,15 @@ void @(topic)_Publisher::run() { while(m_listener.n_matched == 0) { - eClock::my_sleep(250); // Sleep 250 ms +@[if 1.5 < fastrtpsgen_version <= 1.7]@ + eClock::my_sleep(250); // Sleep 250 ms; +@[else]@ + std::this_thread::sleep_for(std::chrono::milliseconds(250)); // Sleep 250 ms +@[end if]@ } // Publication code - -@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_ st; @[else]@ @(topic) st; @@ -154,7 +167,7 @@ void @(topic)_Publisher::run() }while(std::cin >> ch); } -@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ void @(topic)_Publisher::publish(@(topic)_* st) @[else]@ void @(topic)_Publisher::publish(@(topic)* st) diff --git a/msg/templates/urtps/Publisher.h.em b/msg/templates/urtps/Publisher.h.em index 3f93f11d85..4971efdce7 100644 --- a/msg/templates/urtps/Publisher.h.em +++ b/msg/templates/urtps/Publisher.h.em @@ -20,7 +20,7 @@ topic = alias if alias else spec.short_name /**************************************************************************** * * Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). - * Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved. + * Copyright (C) 2018-2019 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: @@ -54,7 +54,7 @@ topic = alias if alias else spec.short_name * @@file @(topic)_Publisher.h * This header file contains the declaration of the publisher functions. * - * This file was generated by the tool fastcdrgen. + * This file was adapted from the fastcdrgen tool. */ @@ -64,7 +64,7 @@ topic = alias if alias else spec.short_name #include #include -@[if float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ #include "@(topic)_PubSubTypes.h" @[else]@ #include "@(topic)PubSubTypes.h" @@ -80,7 +80,7 @@ public: virtual ~@(topic)_Publisher(); bool init(); void run(); -@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ void publish(@(topic)_* st); @[else]@ void publish(@(topic)* st); @@ -97,7 +97,7 @@ private: void onPublicationMatched(Publisher* pub, MatchingInfo& info); int n_matched; } m_listener; -@[if float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_PubSubType myType; @[else]@ @(topic)PubSubType myType; diff --git a/msg/templates/urtps/RtpsTopics.cpp.em b/msg/templates/urtps/RtpsTopics.cpp.em index f0b6a6a9e7..5db5ee24ec 100644 --- a/msg/templates/urtps/RtpsTopics.cpp.em +++ b/msg/templates/urtps/RtpsTopics.cpp.em @@ -23,7 +23,7 @@ recv_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumer /**************************************************************************** * * Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). - * Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved. + * Copyright (C) 2018-2019 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: @@ -92,7 +92,7 @@ void RtpsTopics::publish(uint8_t topic_ID, char data_buffer[], size_t len) @[for topic in send_topics]@ case @(rtps_message_id(ids, topic)): // @(topic) { -@[ if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@ +@[ if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_ st; @[ else]@ @(topic) st; @@ -149,7 +149,7 @@ bool RtpsTopics::getMsg(const uint8_t topic_ID, eprosima::fastcdr::Cdr &scdr) case @(rtps_message_id(ids, topic)): // @(topic) if (_@(topic)_sub.hasMsg()) { -@[ if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@ +@[ if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_ msg = _@(topic)_sub.getMsg(); @[ else]@ @(topic) msg = _@(topic)_sub.getMsg(); diff --git a/msg/templates/urtps/RtpsTopics.h.em b/msg/templates/urtps/RtpsTopics.h.em index 97e1a63451..afe0dba74f 100644 --- a/msg/templates/urtps/RtpsTopics.h.em +++ b/msg/templates/urtps/RtpsTopics.h.em @@ -23,7 +23,7 @@ recv_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumer /**************************************************************************** * * Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). - * Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved. + * Copyright (C) 2018-2019 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: diff --git a/msg/templates/urtps/Subscriber.cpp.em b/msg/templates/urtps/Subscriber.cpp.em index d51fa69771..060474b200 100644 --- a/msg/templates/urtps/Subscriber.cpp.em +++ b/msg/templates/urtps/Subscriber.cpp.em @@ -20,7 +20,7 @@ topic = alias if alias else spec.short_name /**************************************************************************** * * Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). - * Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved. + * Copyright (C) 2018-2019 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: @@ -54,7 +54,7 @@ topic = alias if alias else spec.short_name * @@file @(topic)_Subscriber.cpp * This file contains the implementation of the subscriber functions. * - * This file was generated by the tool fastcdrgen. + * This file was adapted from the fastcdrgen tool. */ #include @@ -66,7 +66,6 @@ topic = alias if alias else spec.short_name #include "@(topic)_Subscriber.h" - @(topic)_Subscriber::@(topic)_Subscriber() : mp_participant(nullptr), mp_subscriber(nullptr) {} @(topic)_Subscriber::~@(topic)_Subscriber() { Domain::removeParticipant(mp_participant);} @@ -74,26 +73,34 @@ topic = alias if alias else spec.short_name bool @(topic)_Subscriber::init() { // Create RTPSParticipant - ParticipantAttributes PParam; - PParam.rtps.builtin.domainId = 0; //MUST BE THE SAME AS IN THE PUBLISHER + PParam.rtps.builtin.domainId = 0; // MUST BE THE SAME AS IN THE PUBLISHER +@[if 1.5 < fastrtpsgen_version <= 1.7]@ PParam.rtps.builtin.leaseDuration = c_TimeInfinite; +@[else]@ + PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite; +@[end if]@ PParam.rtps.setName("@(topic)_subscriber"); //You can put the name you want mp_participant = Domain::createParticipant(PParam); if(mp_participant == nullptr) return false; //Register the type - - Domain::registerType(mp_participant, (TopicDataType*) &myType); + Domain::registerType(mp_participant, static_cast(&myType)); // Create Subscriber - SubscriberAttributes Rparam; Rparam.topic.topicKind = NO_KEY; Rparam.topic.topicDataType = myType.getName(); //Must be registered before the creation of the subscriber +@[if 1.5 < fastrtpsgen_version <= 1.7]@ Rparam.topic.topicName = "@(topic)_PubSubTopic"; - mp_subscriber = Domain::createSubscriber(mp_participant, Rparam, (SubscriberListener*) &m_listener); +@[else]@ + Rparam.topic.topicName = "@(topic)PubSubTopic"; +@[end if]@ +@[if ros2_distro and ros2_distro != "ardent"]@ + Rparam.topic.topicName = "rt/" + Wparam.topic.topicName; +@[end if]@ + mp_subscriber = Domain::createSubscriber(mp_participant, Rparam, static_cast(&m_listener)); if(mp_subscriber == nullptr) return false; return true; @@ -101,6 +108,8 @@ bool @(topic)_Subscriber::init() void @(topic)_Subscriber::SubListener::onSubscriptionMatched(Subscriber* sub, MatchingInfo& info) { + (void)sub; + if (info.status == MATCHED_MATCHING) { n_matched++; @@ -116,8 +125,7 @@ void @(topic)_Subscriber::SubListener::onSubscriptionMatched(Subscriber* sub, Ma void @(topic)_Subscriber::SubListener::onNewDataMessage(Subscriber* sub) { // Take data - if(sub->takeNextData(&msg, &m_info)) -@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_ st; @[else]@ @(topic) st; @@ -148,7 +156,7 @@ bool @(topic)_Subscriber::hasMsg() return m_listener.has_msg; } -@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_ @(topic)_Subscriber::getMsg() @[else]@ @(topic) @(topic)_Subscriber::getMsg() diff --git a/msg/templates/urtps/Subscriber.h.em b/msg/templates/urtps/Subscriber.h.em index 24c33f15a7..46865c2361 100644 --- a/msg/templates/urtps/Subscriber.h.em +++ b/msg/templates/urtps/Subscriber.h.em @@ -20,7 +20,7 @@ topic = alias if alias else spec.short_name /**************************************************************************** * * Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). - * Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved. + * Copyright (C) 2018-2019 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: @@ -54,7 +54,7 @@ topic = alias if alias else spec.short_name * @@file @(topic)_Subscriber.h * This header file contains the declaration of the subscriber functions. * - * This file was generated by the tool fastcdrgen. + * This file was adapted from the fastcdrgen tool. */ @@ -64,7 +64,7 @@ topic = alias if alias else spec.short_name #include #include #include -@[if float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ #include "@(topic)_PubSubTypes.h" @[else]@ #include "@(topic)PubSubTypes.h" @@ -81,7 +81,7 @@ public: bool init(); void run(); bool hasMsg(); -@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_ getMsg(); @[else]@ @(topic) getMsg(); @@ -100,7 +100,7 @@ private: SampleInfo_t m_info; int n_matched; int n_msg; -@[if (ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal") and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_ msg; @[else]@ @(topic) msg; @@ -108,7 +108,7 @@ private: bool has_msg = false; } m_listener; -@[if float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ @(topic)_PubSubType myType; @[else]@ @(topic)PubSubType myType; diff --git a/msg/templates/urtps/microRTPS_agent_CMakeLists.txt.em b/msg/templates/urtps/microRTPS_agent_CMakeLists.txt.em index 6c10919c65..bba1c29fc3 100644 --- a/msg/templates/urtps/microRTPS_agent_CMakeLists.txt.em +++ b/msg/templates/urtps/microRTPS_agent_CMakeLists.txt.em @@ -1,7 +1,7 @@ ################################################################################ # # Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). -# Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved. +# Copyright (C) 2018-2019 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: diff --git a/msg/templates/urtps/microRTPS_transport.h b/msg/templates/urtps/microRTPS_transport.h index 32073bcdc5..1285867799 100644 --- a/msg/templates/urtps/microRTPS_transport.h +++ b/msg/templates/urtps/microRTPS_transport.h @@ -1,7 +1,7 @@ /**************************************************************************** * * Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). - * Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved. + * Copyright (C) 2018-2019 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: diff --git a/msg/templates/urtps/msg.idl.em b/msg/templates/urtps/msg.idl.em index 51f6df36da..1574cd14f7 100644 --- a/msg/templates/urtps/msg.idl.em +++ b/msg/templates/urtps/msg.idl.em @@ -57,11 +57,10 @@ def get_include_directives(spec): if genmsg.msgs.is_valid_constant_type(genmsg.msgs.bare_msg_type(field.type)): continue builtin_type = str(field.base_type).replace('px4/', '') -@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@ - include_directive = '#include "%s_.idl"' % builtin_type -@[else]@ - include_directive = '#include "%s.idl"' % builtin_type -@[end if]@ + if 1.5 < fastrtpsgen_version <= 1.7: + include_directive = '#include "%s_.idl"' % builtin_type + else: + include_directive = '#include "%s.idl"' % builtin_type builtin_types.add(builtin_type) include_directives.add(include_directive) return sorted(include_directives) @@ -78,18 +77,16 @@ def get_idl_type_name(field_type): def add_msg_field(field): if (not field.is_header): if field.is_array: -@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@ - print(' {0}__{1}_array_{2} {3}_;'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name)) + if 1.5 < fastrtpsgen_version <= 1.7: + print(' {0}__{1}_array_{2} {3}_;'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name)) + else: + print(' {0}__{1}_array_{2} {3};'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name)) else: - base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type) + if 1.5 < fastrtpsgen_version <= 1.7: + base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type) + else: + base_type = get_idl_type_name(field.base_type) if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type) print(' {0} {1}_;'.format(base_type, field.name)) -@[else]@ - print(' {0}__{1}_array_{2} {3};'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name)) - else: - base_type = get_idl_type_name(field.base_type) if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type) - print(' {0} {1};'.format(base_type, field.name)) -@[end if]@ - def add_msg_fields(): for field in spec.parsed_fields(): @@ -99,12 +96,10 @@ def add_msg_fields(): def add_array_typedefs(): for field in spec.parsed_fields(): if not field.is_header and field.is_array: -@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@ - base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else -@[else]@ - base_type = get_idl_type_name(field.base_type) if get_idl_type_name(field.base_type) in builtin_types else -@[end if]@ - base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type) + if 1.5 < fastrtpsgen_version <= 1.7: + base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type) + else: + base_type = get_idl_type_name(field.base_type) if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type) array_type = 'typedef {0} {1}__{2}_array_{3}[{4}];'.format(base_type, topic, get_idl_type_name(field.base_type).replace(" ", "_"), field.array_len, field.array_len) if array_type not in array_types: array_types.add(array_type) @@ -132,14 +127,14 @@ def add_msg_constants(): @add_msg_constants() @# Array types @add_array_typedefs() -@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ struct @(topic)_ @[else]@ struct @(topic) @[end if]@ { @add_msg_fields() -@[if ros2_distro == "ardent" or ros2_distro == "bouncy" or ros2_distro == "crystal" and float(fastrtps_version) < 1.9]@ +@[if 1.5 < fastrtpsgen_version <= 1.7]@ }; // struct @(topic)_ #pragma keylist @(topic)_ diff --git a/msg/tools/generate_microRTPS_bridge.py b/msg/tools/generate_microRTPS_bridge.py index 247a11ae88..cf7b1edf2f 100644 --- a/msg/tools/generate_microRTPS_bridge.py +++ b/msg/tools/generate_microRTPS_bridge.py @@ -238,7 +238,37 @@ if fastrtpsgen_include is not None and fastrtpsgen_include != '': os.path.abspath( args.fastrtpsgen_include) + " " -ros2_distro = "" if args.ros2_distro == None else args.ros2_distro +# get FastRTPSGen version +# Note: since Fast-RTPS 1.8.x release, FastRTPSGen is now a separated +# repository and not included in the Fast-RTPS project. +# The starting version since this separation is 1.0.0, which doesn't +# follow the Fast-RTPS version convention +fastrtpsgen_version = 0.0 +if(os.path.exists(fastrtpsgen_path)): + fastrtpsgen_version_out = subprocess.check_output( + [fastrtpsgen_path, "-version"]).strip()[-5:-2] + if not fastrtpsgen_version_out: + raise Exception( + "FastRTPSGen failed with code error %s" % fastrtpsgen_version) + else: + fastrtpsgen_version = float(fastrtpsgen_version_out) +else: + raise Exception( + "FastRTPSGen not found. Specify the location of fastrtpsgen with the -f flag") + +# get ROS 2 version, if exists +ros2_distro = "" +try: + rosversion_out = subprocess.check_output(["rosversion", "-d"]) + rosversion_out = rosversion_out.rstrip() + if rosversion_out not in ["", "kinetic", "lunar", "melodic"]: + ros2_distro = rosversion_out +except OSError as e: + if e.errno == errno.ENOENT: + if args.ros2_distro != None: + ros2_distro = args.ros2_distro + else: + raise # If nothing specified it's generated both if agent == False and client == False: @@ -297,30 +327,21 @@ uRTPS_SUBSCRIBER_H_TEMPL_FILE = 'Subscriber.h.em' def generate_agent(out_dir): - # get FastRTPSGen version - if(os.path.exists(fastrtpsgen_path)): - fastrtps_vers = subprocess.check_output( - [fastrtpsgen_path, "-version"]).strip()[-5:-2] - if not fastrtps_vers: - raise Exception( - "FastRTPSGen failed with code error %s" % fastrtps_vers) - else: - raise Exception( - "FastRTPSGen not found. Specify the location of fastrtpsgen with the -f flag") + global fastrtpsgen_version if classifier.msgs_to_send: for msg_file in classifier.msgs_to_send: if gen_idl: if out_dir != agent_out_dir: px_generate_uorb_topic_files.generate_idl_file(msg_file, msg_dir, "", os.path.join(out_dir, "/idl"), urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtps_vers, ros2_distro, classifier.msg_id_map) + package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtpsgen_version, ros2_distro, classifier.msg_id_map) else: px_generate_uorb_topic_files.generate_idl_file(msg_file, msg_dir, "", idl_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, ros2_distro, fastrtps_vers, classifier.msg_id_map) + package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtpsgen_version, ros2_distro, classifier.msg_id_map) px_generate_uorb_topic_files.generate_topic_file(msg_file, msg_dir, "", out_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_PUBLISHER_SRC_TEMPL_FILE) + package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_PUBLISHER_SRC_TEMPL_FILE) px_generate_uorb_topic_files.generate_topic_file(msg_file, msg_dir, "", out_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_PUBLISHER_H_TEMPL_FILE) + package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_PUBLISHER_H_TEMPL_FILE) if classifier.alias_msgs_to_send: for msg_file in classifier.alias_msgs_to_send: @@ -332,28 +353,28 @@ def generate_agent(out_dir): if gen_idl: if out_dir != agent_out_dir: px_generate_uorb_topic_files.generate_idl_file(msg_name, msg_dir, msg_alias, os.path.join(out_dir, "/idl"), urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtps_vers, ros2_distro, classifier.msg_id_map) + package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtpsgen_version, ros2_distro, classifier.msg_id_map) else: px_generate_uorb_topic_files.generate_idl_file(msg_name, msg_dir, msg_alias, idl_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtps_vers, ros2_distro, classifier.msg_id_map) + package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtpsgen_version, ros2_distro, classifier.msg_id_map) px_generate_uorb_topic_files.generate_topic_file(msg_name, msg_dir, msg_alias, out_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_PUBLISHER_SRC_TEMPL_FILE) + package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_PUBLISHER_SRC_TEMPL_FILE) px_generate_uorb_topic_files.generate_topic_file(msg_name, msg_dir, msg_alias, out_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_PUBLISHER_H_TEMPL_FILE) + package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_PUBLISHER_H_TEMPL_FILE) if classifier.msgs_to_receive: for msg_file in classifier.msgs_to_receive: if gen_idl: if out_dir != agent_out_dir: px_generate_uorb_topic_files.generate_idl_file(msg_file, msg_dir, "", os.path.join(out_dir, "/idl"), urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtps_vers, ros2_distro, classifier.msg_id_map) + package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtpsgen_version, ros2_distro, classifier.msg_id_map) else: px_generate_uorb_topic_files.generate_idl_file(msg_file, msg_dir, "", idl_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtps_vers, ros2_distro, classifier.msg_id_map) + package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtpsgen_version, ros2_distro, classifier.msg_id_map) px_generate_uorb_topic_files.generate_topic_file(msg_file, msg_dir, "", out_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_SUBSCRIBER_SRC_TEMPL_FILE) + package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_SUBSCRIBER_SRC_TEMPL_FILE) px_generate_uorb_topic_files.generate_topic_file(msg_file, msg_dir, "", out_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_SUBSCRIBER_H_TEMPL_FILE) + package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_SUBSCRIBER_H_TEMPL_FILE) if classifier.alias_msgs_to_receive: for msg_file in classifier.alias_msgs_to_receive: @@ -365,24 +386,24 @@ def generate_agent(out_dir): if gen_idl: if out_dir != agent_out_dir: px_generate_uorb_topic_files.generate_idl_file(msg_name, msg_dir, msg_alias, os.path.join(out_dir, "/idl"), urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtps_vers, ros2_distro, classifier.msg_id_map) + package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtpsgen_version, ros2_distro, classifier.msg_id_map) else: px_generate_uorb_topic_files.generate_idl_file(msg_name, msg_dir, msg_alias, idl_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtps_vers, ros2_distro, classifier.msg_id_map) + package, px_generate_uorb_topic_files.INCL_DEFAULT, fastrtpsgen_version, ros2_distro, classifier.msg_id_map) px_generate_uorb_topic_files.generate_topic_file(msg_name, msg_dir, msg_alias, out_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_SUBSCRIBER_SRC_TEMPL_FILE) + package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_SUBSCRIBER_SRC_TEMPL_FILE) px_generate_uorb_topic_files.generate_topic_file(msg_name, msg_dir, msg_alias, out_dir, urtps_templates_dir, - package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_SUBSCRIBER_H_TEMPL_FILE) + package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_SUBSCRIBER_H_TEMPL_FILE) px_generate_uorb_topic_files.generate_uRTPS_general(classifier.msgs_to_send, classifier.alias_msgs_to_send, classifier.msgs_to_receive, classifier.alias_msgs_to_receive, msg_dir, out_dir, - urtps_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_AGENT_TEMPL_FILE) + urtps_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_AGENT_TEMPL_FILE) px_generate_uorb_topic_files.generate_uRTPS_general(classifier.msgs_to_send, classifier.alias_msgs_to_send, classifier.msgs_to_receive, classifier.alias_msgs_to_receive, msg_dir, out_dir, - urtps_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_AGENT_TOPICS_H_TEMPL_FILE) + urtps_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_AGENT_TOPICS_H_TEMPL_FILE) px_generate_uorb_topic_files.generate_uRTPS_general(classifier.msgs_to_send, classifier.alias_msgs_to_send, classifier.msgs_to_receive, classifier.alias_msgs_to_receive, msg_dir, out_dir, - urtps_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_AGENT_TOPICS_SRC_TEMPL_FILE) + urtps_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_AGENT_TOPICS_SRC_TEMPL_FILE) if cmakelists: px_generate_uorb_topic_files.generate_uRTPS_general(classifier.msgs_to_send, classifier.alias_msgs_to_send, classifier.msgs_to_receive, classifier.alias_msgs_to_receive, msg_dir, out_dir, - urtps_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtps_vers, ros2_distro, uRTPS_AGENT_CMAKELISTS_TEMPL_FILE) + urtps_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_AGENT_CMAKELISTS_TEMPL_FILE) # Final steps to install agent mkdir_p(os.path.join(out_dir, "fastrtpsgen")) @@ -438,6 +459,7 @@ def mkdir_p(dirpath): def generate_client(out_dir): + global fastrtpsgen_version # Rename work in the default path if default_client_out != out_dir: @@ -452,7 +474,7 @@ def generate_client(out_dir): os.rename(def_file, def_file.replace(".h", ".h_")) px_generate_uorb_topic_files.generate_uRTPS_general(classifier.msgs_to_send, classifier.alias_msgs_to_send, classifier.msgs_to_receive, classifier.alias_msgs_to_receive, msg_dir, - out_dir, uorb_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, uRTPS_CLIENT_TEMPL_FILE) + out_dir, uorb_templates_dir, package, px_generate_uorb_topic_files.INCL_DEFAULT, classifier.msg_id_map, fastrtpsgen_version, ros2_distro, uRTPS_CLIENT_TEMPL_FILE) # Final steps to install client cp_wildcard(os.path.join(urtps_templates_dir, diff --git a/msg/tools/px_generate_uorb_topic_files.py b/msg/tools/px_generate_uorb_topic_files.py index 0821393ba9..fbb0a2d932 100755 --- a/msg/tools/px_generate_uorb_topic_files.py +++ b/msg/tools/px_generate_uorb_topic_files.py @@ -170,7 +170,7 @@ def generate_output_from_file(format_idx, filename, outputdir, package, template return generate_by_template(output_file, template_file, em_globals) -def generate_idl_file(filename_msg, msg_dir, alias, outputdir, templatedir, package, includepath, fastrtps_ver, ros2_distro, ids): +def generate_idl_file(filename_msg, msg_dir, alias, outputdir, templatedir, package, includepath, fastrtpsgen_version, ros2_distro, ids): """ Generates an .idl from .msg file """ @@ -178,11 +178,11 @@ def generate_idl_file(filename_msg, msg_dir, alias, outputdir, templatedir, pack if (alias != ""): em_globals = get_em_globals( - msg, alias, package, includepath, ids, fastrtps_ver, ros2_distro, MsgScope.NONE) + msg, alias, package, includepath, ids, fastrtpsgen_version, ros2_distro, MsgScope.NONE) spec_short_name = alias else: em_globals = get_em_globals( - msg, "", package, includepath, ids, fastrtps_ver, ros2_distro, MsgScope.NONE) + msg, "", package, includepath, ids, fastrtpsgen_version, ros2_distro, MsgScope.NONE) spec_short_name = em_globals["spec"].short_name # Make sure output directory exists: @@ -201,7 +201,7 @@ def generate_idl_file(filename_msg, msg_dir, alias, outputdir, templatedir, pack def generate_uRTPS_general(filename_send_msgs, filename_alias_send_msgs, filename_receive_msgs, filename_alias_receive_msgs, - msg_dir, outputdir, templatedir, package, includepath, ids, fastrtps_ver, ros2_distro, template_name): + msg_dir, outputdir, templatedir, package, includepath, ids, fastrtpsgen_version, ros2_distro, template_name): """ Generates source file by msg content """ @@ -227,19 +227,19 @@ def generate_uRTPS_general(filename_send_msgs, filename_alias_send_msgs, filenam em_globals_list = [] if send_msgs: em_globals_list.extend([get_em_globals( - f, "", package, includepath, ids, fastrtps_ver, ros2_distro, MsgScope.SEND) for f in send_msgs]) + f, "", package, includepath, ids, fastrtpsgen_version, ros2_distro, MsgScope.SEND) for f in send_msgs]) if alias_send_msgs: em_globals_list.extend([get_em_globals( - f[0], f[1], package, includepath, ids, fastrtps_ver, ros2_distro, MsgScope.SEND) for f in alias_send_msgs]) + f[0], f[1], package, includepath, ids, fastrtpsgen_version, ros2_distro, MsgScope.SEND) for f in alias_send_msgs]) if receive_msgs: em_globals_list.extend([get_em_globals( - f, "", package, includepath, ids, fastrtps_ver, ros2_distro, MsgScope.RECEIVE) for f in receive_msgs]) + f, "", package, includepath, ids, fastrtpsgen_version, ros2_distro, MsgScope.RECEIVE) for f in receive_msgs]) if alias_receive_msgs: em_globals_list.extend([get_em_globals( - f[0], f[1], package, includepath, ids, fastrtps_ver, ros2_distro, MsgScope.RECEIVE) for f in alias_receive_msgs]) + f[0], f[1], package, includepath, ids, fastrtpsgen_version, ros2_distro, MsgScope.RECEIVE) for f in alias_receive_msgs]) merged_em_globals = merge_em_globals_list(em_globals_list) @@ -254,7 +254,7 @@ def generate_uRTPS_general(filename_send_msgs, filename_alias_send_msgs, filenam return generate_by_template(output_file, template_file, merged_em_globals) -def generate_topic_file(filename_msg, msg_dir, alias, outputdir, templatedir, package, includepath, ids, fastrtps_ver, ros2_distro, template_name): +def generate_topic_file(filename_msg, msg_dir, alias, outputdir, templatedir, package, includepath, ids, fastrtpsgen_version, ros2_distro, template_name): """ Generates a sources and headers from .msg file """ @@ -262,11 +262,11 @@ def generate_topic_file(filename_msg, msg_dir, alias, outputdir, templatedir, pa if (alias): em_globals = get_em_globals( - msg, alias, package, includepath, ids, fastrtps_ver, ros2_distro, MsgScope.NONE) + msg, alias, package, includepath, ids, fastrtpsgen_version, ros2_distro, MsgScope.NONE) spec_short_name = alias else: em_globals = get_em_globals( - msg, "", package, includepath, ids, fastrtps_ver, ros2_distro, MsgScope.NONE) + msg, "", package, includepath, ids, fastrtpsgen_version, ros2_distro, MsgScope.NONE) spec_short_name = em_globals["spec"].short_name # Make sure output directory exists: @@ -280,7 +280,7 @@ def generate_topic_file(filename_msg, msg_dir, alias, outputdir, templatedir, pa return generate_by_template(output_file, template_file, em_globals) -def get_em_globals(filename_msg, alias, package, includepath, ids, fastrtps_ver, ros2_distro, scope): +def get_em_globals(filename_msg, alias, package, includepath, ids, fastrtpsgen_version, ros2_distro, scope): """ Generates em globals dictionary """ @@ -309,7 +309,7 @@ def get_em_globals(filename_msg, alias, package, includepath, ids, fastrtps_ver, "scope": scope, "package": package, "alias": alias, - "fastrtps_version": fastrtps_ver, + "fastrtpsgen_version": fastrtpsgen_version, "ros2_distro": ros2_distro } diff --git a/src/modules/micrortps_bridge/micrortps_client/CMakeLists.txt b/src/modules/micrortps_bridge/micrortps_client/CMakeLists.txt index 2512dd2c7e..964d7136e4 100644 --- a/src/modules/micrortps_bridge/micrortps_client/CMakeLists.txt +++ b/src/modules/micrortps_bridge/micrortps_client/CMakeLists.txt @@ -33,9 +33,6 @@ set(msg_out_path ${CMAKE_CURRENT_BINARY_DIR}) -#set(ROS2_DISTRO $ENV{ROS_DISTRO}) -set(ROS2_DISTRO "") - if (NOT "${config_rtps_send_topics}" STREQUAL "" OR NOT "${config_rtps_receive_topics}" STREQUAL "") set(send_topic_files) @@ -84,7 +81,6 @@ if (NOT "${config_rtps_send_topics}" STREQUAL "" OR NOT "${config_rtps_receive_t --agent-outdir ${CMAKE_CURRENT_BINARY_DIR}/micrortps_agent --client-outdir ${CMAKE_CURRENT_BINARY_DIR}/micrortps_client --idl-dir ${CMAKE_CURRENT_BINARY_DIR}/micrortps_agent/idl - --ros2-distro ${ROS2_DISTRO} #>micrortps_bridge.log > /dev/null DEPENDS ${send_topic_files} ${receive_topic_files} COMMENT "Generating RTPS topic bridge"