将本机DDS系统与ROS2接口 [英] Interfacing a native DDS system with ROS2

查看:161
本文介绍了将本机DDS系统与ROS2接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要与基于ROS2的发布者和基于RTI Connext的订户进行通信,它们两者都需要具有兼容的QoS设置。

To communicate to a ROS2 based publisher and a RTI Connext based subscriber, both of them need to have a compatible QoS settings.

我正在使用RTI Connector for python并使用XML Application Creation运行订户。

I am using RTI Connector for python and using the XML Application Creation to run the subscriber.

我在ROS2中运行了 talker_py ,其中默认并订阅以下消息RTI Connext Pro。

I run a talker_py in ROS2 which has a default QoS and subscribe to these messages in RTI Connext Pro.

ROS2 IDL看起来像这样:

The ROS2 IDL is looks like this :

{
     module msg
     {
         module dds_ {
            struct String_ {
                String data_;
            };
         };
     };
};

我使用 rtiddsgen 实用工具进行转换将其转换为XML文件。这是转换后的XML:

I use the rtiddsgen utility tool to convert it into a XML file. Here is the converted 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 ,看起来像是:

I added the <types> to my USER_QoS.xml and it looks like :

<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连接器用于python时,此处的第一步是尝试加载 USER_QoS.xml 文件,它始终显示错误无法解析.xml文件。我强烈认为这是因为在< types> 定义中存在关键字 module

Now when I use the RTI Connector for python, the first step here is trying to load the USER_QoS.xml file and it always give the error Unable to parse the .xml file. I strongly feel that this is because of the presence of the keyword module in the <types> definition.

这是RTI连接器的python脚本:

Here is the python script for the RTI Connector:

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 关键字。可能是这样吗?

I feel that the connector is not able to parse this module keyword. Could it be the case ?

推荐答案

当我尝试进行设置时,连接器提供的输出比您指定的还要多。

When I try your setup, Connector provides more output than what you have indicated. Among others:

RTIXMLParser_validateOnStartTag:Parse error at line 15: Unexpected tag 'durablitiy'

这是XML中的错误,根据其架构,标记名称应为耐久性

This is an error in your XML, according to the its schema the tag name should be durability.

然后,您似乎在复制生成的< types> 标记及其标签时出现了复制粘贴错误。内容转换为XML。为此,连接器给出以下错误:

Then you seem to have made copy-paste errors copying the generated <types> tag and its contents into your XML. For that, connector gives the following error:

RTIXMLParser_parseFromFile_ex:Parse error at line 50: not well-formed (invalid token)

实际上,您的第50行结尾处有多余的报价:

Indeed your line 50 has a superfluous quote at the end:

<member name="data_" type="std_msgs::msg::dds_::string" "/>

此外, type 属性的值与您尝试生成的XML不同在此处插入,其中包含:

Also, the value of the type attribute is different from the generated XML that you tried to insert here, which has:

<member name="data_" type="string"/>

更正这些错误后,Connector会正确实例化。

After correcting those errors, Connector instantiates properly.

到根据其架构验证XML文件,您可以/应该使用关联的XSD架构定义

To validate your XML file against its schema, you can/should use the associated XSD schema definition.

这篇关于将本机DDS系统与ROS2接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆