要与基于 ROS2 的发布者和基于 RTI Connext 的订阅者进行通信,它们都需要具有兼容的 QoS 设置。
我正在使用 RTI Connector for python 并使用 XML Application Creation 来运行订阅者。
我talker_py
在具有默认QoS 的 ROS2 中运行一个并在 RTI Connext Pro 中订阅这些消息。
ROS2 IDL 看起来像这样:
{
module msg
{
module dds_ {
struct String_ {
String data_;
};
};
};
};
我使用rtiddsgen
实用工具将其转换为 XML 文件。这是转换后的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/path/to/RTIInstall/rti_connext_dds-5.3.1/bin/../resource/app/app_support/rtiddsgen/schema/rti_dds_topic_types.xsd">
<module name="std_msgs">
<module name="msg">
<module name="dds_">
<struct name="String_">
<member name="data_" type="string"/>
</struct>
</module>
</module>
</module>
</types>
我添加<types>
到我的USER_QoS.xml
,它看起来像:
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/5.1.0/rti_dds_profiles.xsd" version="5.1.0">
<!-- Qos Library -->
<qos_library name="QosLibrary">
<qos_profile name="DefaultProfile" is_default_qos="true">
<datawriter_qos>
<history>
<kind>KEEP_LAST_HISTORY_QOS</kind>
<depth>1000</depth>
</history>
<reliability>
<kind>RELIABLE_RELIABILITY_QOS</kind>
</reliability>
<durablitiy>
<kind>VOLATILE_DURABILITY_QOS</kind>
</durablitiy>
</datawriter_qos>
<participant_qos>
<transport_builtin>
<mask>UDPV4 | SHMEM</mask>
</transport_builtin>
<!-- Turn on monitoring -->
<!-- Begin Monitoring
<property>
<value>
<element>
<name>rti.monitor.library</name>
<value>rtimonitoring</value>
</element>
<element>
<name>rti.monitor.create_function_ptr</name>
<value>$(NDDS_MONITOR)</value>
</element>
</value>
</property>
End Monitoring -->
</participant_qos>
</qos_profile>
</qos_library>
<!-- types -->
<types>
<module name="std_msgs">
<module name="msg">
<module name="dds_">
<struct name="String_" extensibility="extensible">
<member name="data_" type="std_msgs::msg::dds_::string" "/>
</struct>
</module>
</module>
</module>
</types>
<!-- Domain Library -->
<domain_library name="MyDomainLibrary">
<domain name="MyDomain" domain_id="0">
<register_type name="std_msgs::msg::dds_::String_" type_ref="std_msgs::msg::dds_::String_" />
<topic name="chatter" register_type_ref="std_msgs::msg::dds_::String_"/>
</domain>
</domain_library>
<!-- Participant library -->
<domain_participant_library name="MyParticipantLibrary">
<domain_participant name="Zero" domain_ref="MyDomainLibrary::MyDomain">
<subscriber name="MySubscriber">
<data_reader name="MyChatterReader" topic_ref="chatter" />
</subscriber>
</domain_participant>
</domain_participant_library>
</dds>
现在,当我使用 RTI Connector for python 时,这里的第一步是尝试加载USER_QoS.xml
文件,它总是给出错误Unable to parse the .xml file
。我强烈认为这是因为定义中存在module
关键字<types>
。
这是 RTI 连接器的 python 脚本:
from __future__ import print_function
from sys import path as sysPath
from os import path as osPath
from time import sleep
filepath = osPath.dirname(osPath.realpath(__file__))
sysPath.append(filepath + "/../../../")
import rticonnextdds_connector as rti
connector = rti.Connector("MyParticipantLibrary::Zero",
filepath + "/../User_QoS.xml")
inputDDS = connector.getInput("MySubscriber::MyChatterReader")
for i in range(1, 500):
inputDDS.take()
numOfSamples = inputDDS.samples.getLength()
for j in range(1, numOfSamples+1):
if inputDDS.infos.isValid(j):
# This gives you a dictionary
sample = inputDDS.samples.getDictionary(j)
x = sample['x']
# Or you can just access the field directly
toPrint = "Received x: " + repr(x)
print(toPrint)
sleep(2)
我觉得连接器无法解析这个module
关键字。会不会是这样?