mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
microRTPS: use FastRTPSGen '-typeros2' option to generate the typenaming required to interface the bridge with ROS2 topics
This commit is contained in:
parent
ab6606aa46
commit
2020b77a43
@ -101,13 +101,6 @@ bool @(topic)_Publisher::init()
|
||||
if(mp_participant == nullptr)
|
||||
return false;
|
||||
|
||||
@[if ros2_distro and (ros2_distro == "dashing" or ros2_distro == "eloquent")]@
|
||||
// Type name should match the expected type name on ROS2
|
||||
// Note: the change is being done here since the 'fastrtpsgen' example
|
||||
// generator does not allow to change the type naming on the template
|
||||
@(topic)DataType.setName("@(package)::msg::dds_::@(topic)_");
|
||||
@[end if]@
|
||||
|
||||
// Register the type
|
||||
Domain::registerType(mp_participant, static_cast<TopicDataType*>(&@(topic)DataType));
|
||||
|
||||
|
||||
@ -101,14 +101,6 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable* t_send
|
||||
if(mp_participant == nullptr)
|
||||
return false;
|
||||
|
||||
@[if ros2_distro and (ros2_distro == "dashing" or ros2_distro == "eloquent")]@
|
||||
// Type name should match the expected type name on ROS2
|
||||
// Note: the change is being done here since the 'fastrtpsgen' example
|
||||
// generator does not allow to change the type naming on the template of
|
||||
// "*PubSubTypes.cpp" file
|
||||
@(topic)DataType.setName("@(package)::msg::dds_::@(topic)_");
|
||||
@[end if]@
|
||||
|
||||
//Register the type
|
||||
Domain::registerType(mp_participant, static_cast<TopicDataType*>(&@(topic)DataType));
|
||||
|
||||
|
||||
@ -58,6 +58,16 @@ except ImportError as e:
|
||||
print("")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
from packaging import version
|
||||
except ImportError as e:
|
||||
print("Failed to import packaging: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it using:")
|
||||
print(" pip3 install --user packaging")
|
||||
print("")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_rtps_id_uniqueness(classifier):
|
||||
"""
|
||||
@ -227,6 +237,28 @@ if fastrtpsgen_include is not None and fastrtpsgen_include != '':
|
||||
os.path.abspath(
|
||||
args.fastrtpsgen_include) + " "
|
||||
|
||||
# get FastRTPSGen version
|
||||
# .. note:: since Fast-RTPS 1.8.0 release, FastRTPSGen is a separated repository
|
||||
# and not included in the Fast-RTPS project.
|
||||
# The starting version since this separation is 1.0.0, which follows its own
|
||||
# versioning
|
||||
fastrtpsgen_version = version.Version("1.0.0")
|
||||
if(os.path.exists(fastrtpsgen_path)):
|
||||
try:
|
||||
fastrtpsgen_version_out = subprocess.check_output(
|
||||
[fastrtpsgen_path, "-version"]).decode("utf-8").strip()[-5:]
|
||||
except OSError:
|
||||
raise
|
||||
|
||||
try:
|
||||
fastrtpsgen_version = version.parse(fastrtpsgen_version_out)
|
||||
except version.InvalidVersion:
|
||||
raise Exception(
|
||||
"'fastrtpsgen -version' returned None or an invalid version")
|
||||
else:
|
||||
raise Exception(
|
||||
"FastRTPSGen not found. Specify the location of fastrtpsgen with the -f flag")
|
||||
|
||||
# get FastRTPS version
|
||||
fastrtps_version = subprocess.check_output(
|
||||
"ldconfig -v | grep libfastrtps", shell=True).decode("utf-8").strip().split('so.')[-1]
|
||||
@ -386,10 +418,18 @@ def generate_agent(out_dir):
|
||||
os.chdir(os.path.join(out_dir, "fastrtpsgen"))
|
||||
if not glob.glob(os.path.join(idl_dir, "*.idl")):
|
||||
raise Exception("No IDL files found in %s" % idl_dir)
|
||||
|
||||
# If it is generating the bridge code for interfacing with ROS2, then set
|
||||
# the '-typeros2' option in fastrtpsgen.
|
||||
# .. note:: This is only available in FastRTPSGen 1.0.4 and above
|
||||
gen_ros2_typename = ""
|
||||
if ros2_distro and fastrtpsgen_version >= version.Version("1.0.4"):
|
||||
gen_ros2_typename = "-typeros2 "
|
||||
|
||||
for idl_file in glob.glob(os.path.join(idl_dir, "*.idl")):
|
||||
try:
|
||||
ret = subprocess.check_call(fastrtpsgen_path + " -d " + out_dir +
|
||||
"/fastrtpsgen -example x64Linux2.6gcc " + fastrtpsgen_include + idl_file, shell=True)
|
||||
"/fastrtpsgen -example x64Linux2.6gcc " + gen_ros2_typename + fastrtpsgen_include + idl_file, shell=True)
|
||||
except OSError:
|
||||
raise
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user