mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 04:43:34 +08:00
micrortps bridge: clean templates; add backwards compatibility; add ROS2 compatibility
This commit is contained in:
@@ -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 ["<unknown>", "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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user