Refs #3365. Integration with rmw_microros

This commit is contained in:
Javier Moreno
2018-09-20 17:10:29 +02:00
parent becb074a2f
commit 331a44bc9c
5 changed files with 147 additions and 86 deletions
+1 -1
View File
@@ -68,6 +68,6 @@ install(
) )
install( install(
DIRECTORY cmake DIRECTORY cmake resource
DESTINATION share/${PROJECT_NAME} DESTINATION share/${PROJECT_NAME}
) )
+1 -1
View File
@@ -49,7 +49,7 @@ rosidl_write_generator_arguments(
ROS_INTERFACE_FILES "${rosidl_generate_interfaces_IDL_FILES}" ROS_INTERFACE_FILES "${rosidl_generate_interfaces_IDL_FILES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}" ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}" OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "NONE" TEMPLATE_DIR "${micro_ros_agent_DEFAULT_PROFILES_DIR}"
TARGET_DEPENDENCIES ${target_dependencies} TARGET_DEPENDENCIES ${target_dependencies}
ADDITIONAL_FILES ${_dds_idl_files} ADDITIONAL_FILES ${_dds_idl_files}
) )
+3
View File
@@ -9,3 +9,6 @@ normalize_path(micro_ros_agent_BIN "${micro_ros_agent_BIN}")
set(micro_ros_agent_GENERATOR_FILES "${micro_ros_agent_DIR}/../../../@PYTHON_INSTALL_DIR@/micro_ros_agent/__init__.py") set(micro_ros_agent_GENERATOR_FILES "${micro_ros_agent_DIR}/../../../@PYTHON_INSTALL_DIR@/micro_ros_agent/__init__.py")
normalize_path(micro_ros_agent_GENERATOR_FILES "${micro_ros_agent_GENERATOR_FILES}") normalize_path(micro_ros_agent_GENERATOR_FILES "${micro_ros_agent_GENERATOR_FILES}")
set(micro_ros_agent_DEFAULT_PROFILES_DIR "${micro_ros_agent_DIR}/../resource")
normalize_path(micro_ros_agent_DEFAULT_PROFILES_DIR "${micro_ros_agent_DEFAULT_PROFILES_DIR}")
+101 -82
View File
@@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import struct
import fcntl
import os import os
import sys
from rosidl_cmake import convert_camel_case_to_lower_case_underscore from rosidl_cmake import convert_camel_case_to_lower_case_underscore
from rosidl_cmake import expand_template from rosidl_cmake import expand_template
@@ -21,6 +24,7 @@ from rosidl_cmake import get_newest_modification_time
from rosidl_parser import parse_message_file from rosidl_parser import parse_message_file
from rosidl_parser import parse_service_file from rosidl_parser import parse_service_file
from rosidl_parser import validate_field_types from rosidl_parser import validate_field_types
from shutil import copyfile
from pathlib import Path from pathlib import Path
@@ -33,6 +37,34 @@ def generate_micro_ros_agent_xml_support(args):
'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore,
} }
# Set file format
file_format = ".xml"
ros2_prefix = "rt/"
# Check destination dir
dest_dir = args['output_dir']
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
# Check source dir
srcs_dir = os.path.join(dest_dir, "srcs")
if not os.path.exists(srcs_dir):
os.makedirs(srcs_dir)
# Copy all included xml files
for filename in os.listdir(args['template_dir']):
if filename.endswith(file_format):
template_src_path = os.path.join(args['template_dir'], filename)
template_dest_path = os.path.join(srcs_dir, filename)
if not os.path.isfile(template_dest_path):
copyfile(template_src_path, template_dest_path)
# Iterate throw all msgs/srvs
for idl_file in args['ros_interface_files']: for idl_file in args['ros_interface_files']:
extension = os.path.splitext(idl_file)[1] extension = os.path.splitext(idl_file)[1]
if extension == '.msg': if extension == '.msg':
@@ -50,97 +82,84 @@ def generate_micro_ros_agent_xml_support(args):
data.update(functions) data.update(functions)
# Make destinatino dir # Generate source file path
if not os.path.exists(args['output_dir']): src_file = os.path.join(srcs_dir, "%s_%s_%s.xml" % (spec.base_type.pkg_name, subfolder, spec.msg_name))
os.makedirs(args['output_dir'])
# Check if publixher exists
pub_file_path = os.path.join(args['output_dir'], 'publisher.xml')
pub_file = Path(pub_file_path)
if not pub_file.is_file():
publ = open(pub_file_path, 'a')
publ.write("<profiles>\n")
else:
publ = open(pub_file_path)
lines = publ.readlines()
publ.close()
publ = open(pub_file_path,'w')
publ.writelines([item for item in lines[:-1]])
#publ = open(pub_file_path, "w")
#publ.seek(publ.seek(-1,2) - len("</profiles>\n"))
# Publisher
publ.write(" <publisher profile_name=\"default_xrce_publisher_profile\">\n") file_content = " <publisher profile_name=\"%s_%s_%s_p\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
publ.write(" <topic>\n") file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
publ.write(" <kind>NO_KEY</kind>\n") file_content += " <kind>NO_KEY</kind>\n"
publ.write(" <name>%sPubSubTopic</name>\n" % (spec.msg_name)) file_content += " <name>%s%s_%s_%s</name>\n" % (ros2_prefix, spec.base_type.pkg_name, subfolder, spec.msg_name)
publ.write(" <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)) file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
publ.write(" <historyQos>\n") file_content += " <historyQos>\n"
publ.write(" <kind>KEEP_LAST</kind>\n") file_content += " <kind>KEEP_LAST</kind>\n"
publ.write(" <depth>5</depth>\n") file_content += " <depth>5</depth>\n"
publ.write(" </historyQos>\n") file_content += " </historyQos>\n"
publ.write(" <durability>\n") file_content += " <durability>\n"
publ.write(" <kind>TRANSIENT_LOCAL</kind>\n") file_content += " <kind>TRANSIENT_LOCAL</kind>\n"
publ.write(" </durability>\n") file_content += " </durability>\n"
publ.write(" </topic>\n") file_content += " </topic>\n"
publ.write(" </publisher>\n") file_content += " </publisher>\n"
publ.write("</profiles>\n")
publ.close()
# Subscriber
# Check if subcriber exists file_content += " <subscriber profile_name=\"%s_%s_%s_s\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
subs_file_path = os.path.join(args['output_dir'], 'subscriber.xml') file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
subs_file = Path(subs_file_path) file_content += " <kind>NO_KEY</kind>\n"
if not subs_file.is_file(): file_content += " <name>%s%s_%s_%s</name>\n" % (ros2_prefix, spec.base_type.pkg_name, subfolder, spec.msg_name)
subs = open(subs_file_path, 'a') file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
subs.write("<profiles>\n") file_content += " <historyQos>\n"
else: file_content += " <kind>KEEP_LAST</kind>\n"
subs = open(subs_file_path) file_content += " <depth>5</depth>\n"
lines = subs.readlines() file_content += " </historyQos>\n"
subs.close() file_content += " <durability>\n"
subs = open(subs_file_path,'w') file_content += " <kind>TRANSIENT_LOCAL</kind>\n"
subs.writelines([item for item in lines[:-1]]) file_content += " </durability>\n"
file_content += " </topic>\n"
file_content += " </subscriber>\n"
subs.write(" <subscriber profile_name=\"default_xrce_subscriber_profile\">\n") # Topic
subs.write(" <topic>\n") file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
subs.write(" <kind>NO_KEY</kind>\n") file_content += " <name>%s%s_%s_%s</name>\n" % (ros2_prefix, spec.base_type.pkg_name, subfolder, spec.msg_name)
subs.write(" <name>%sPubSubTopic</name>\n" % (spec.msg_name)) file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
subs.write(" <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)) file_content += " </topic>\n"
subs.write(" <historyQos>\n")
subs.write(" <kind>KEEP_LAST</kind>\n")
subs.write(" <depth>5</depth>\n")
subs.write(" </historyQos>\n")
subs.write(" <durability>\n")
subs.write(" <kind>TRANSIENT_LOCAL</kind>\n")
subs.write(" </durability>\n")
subs.write(" </topic>\n")
subs.write(" </subscriber>\n")
subs.write("</profiles>\n")
subs.close()
# Check if topic exists # Write file content
topi_file_path = os.path.join(args['output_dir'], 'topic.xml') fd1 = open(src_file, "w")
topi_file = Path(topi_file_path) fcntl.lockf(fd1, fcntl.LOCK_EX)
if not topi_file.is_file(): fd1.write(file_content)
topi = open(topi_file_path, 'a') fd1.close()
topi.write("<dds>\n")
else:
topi = open(topi_file_path) # Open collect file
lines = topi.readlines() collec_file = os.path.join(args['output_dir'], "DEFAULT_FASTRTPS_PROFILES.xml")
topi.close() fd2 = open(collec_file, "w")
topi = open(topi_file_path,'w') fcntl.lockf(fd2, fcntl.LOCK_EX)
topi.writelines([item for item in lines[:-1]])
# Generate head
fd2.write("<profiles>\n")
# Append all files contents
for filename in os.listdir(srcs_dir):
if filename.endswith(".xml"):
fd3 = open(os.path.join(srcs_dir, filename), "r+")
fcntl.lockf(fd3, fcntl.LOCK_EX)
fd2.write(fd3.read())
fd3.close()
# Generate tail
fd2.write("</profiles>\n")
# Close file
fd2.close()
topi.write(" <topic>\n")
topi.write(" <name>%sPubSubTopic</name>\n" % (spec.msg_name))
topi.write(" <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name))
topi.write(" </topic>\n")
topi.write("</dds>\n")
topi.close()
#elif extension == '.srv': #elif extension == '.srv':
+39
View File
@@ -0,0 +1,39 @@
<participant profile_name="participant_profile">
<rtps>
<builtin>
<leaseDuration>
<durationbyname>INFINITE</durationbyname>
</leaseDuration>
<domainId>0</domainId>
</builtin>
<name>DataReader_participant_subscriber</name>
</rtps>
</participant>
<publisher profile_name="publisher_profile">
<topic>
<kind>WITH_KEY</kind>
<name>Square</name>
<dataType>ShapeType</dataType>
<historyQos>
<kind>KEEP_LAST</kind>
<depth>5</depth>
</historyQos>
<durability>
<kind>TRANSIENT_LOCAL</kind>
</durability>
</topic>
</publisher>
<subscriber profile_name="subscriber_profile">
<topic>
<kind>WITH_KEY</kind>
<name>Square</name>
<dataType>ShapeType</dataType>
<historyQos>
<kind>KEEP_LAST</kind>
<depth>5</depth>
</historyQos>
<durability>
<kind>TRANSIENT_LOCAL</kind>
</durability>
</topic>
</subscriber>