【问题标题】:How to create an OpenSplice DDS topic using python and statically created topic classes?如何使用 python 和静态创建的主题类创建 OpenSplice DDS 主题?
【发布时间】:2021-04-27 13:58:16
【问题描述】:

我一直在尝试在 Ubuntu 20.04.2 LTS 上使用凌华科技的 Vortex OpenSplice Community edition 和 Python API(PyEnv 虚拟环境中的 Python 版本 3.6)。我已经关注PythonDCPSAPIGuide 并让 ($OSPL_HOME/tools/python/examples) 中的 python 示例正常工作。但是,我不知道如何使用idlpp 为静态生成的主题类创建与域参与者关联的主题。我怎么能做到这一点?

到目前为止我做了什么:

我有一个 IDL 文件,其中包含许多其他 IDL 文件的路径。我已使用以下 bash 脚本将这些 IDL 文件转换为 python 主题类:

#!/bin/bash

for FILE in *.idl; do
  $OSPL_HOME/bin/idlpp -I $OSPL_HOME/etc/idl -S -l python -d . $FILE
done

这将创建一系列 python 包(python 主题类),我将它们导入到同一目录中的 python 脚本中。

使用这些包,我想在我的 python 脚本中创建或注册一个域参与者的主题。例如下面的python代码,(但是'create_topic'函数不存在):

# myExampleDDSFile.py

from dds import *
from foo import foo_type # idlpp generated module/class
from foo2 import foo_type2 # idlpp generated module/class

dp = DomainParticipant()
topic = dp.create_topic('foo_topic',foo_type) # this function doesn't exist for a domain participant
pub = dp.create_publisher()

这可能吗?如果可以,我如何注册我在 python 中与域参与者静态创建的主题?


我注意到在提供的 python 示例(例如 $OSPL_HOME/tools/python/examples/example1.py)中,使用下面的代码动态注册了一个主题,但我认为这与静态生成的 python 主题类无关:

# example1.py snippet

dp = DomainParticipant()
gen_info = ddsutil.get_dds_classes_from_idl('example1.idl', 'basic::module_SequenceOfStruct::SequenceOfStruct_struct')
topic = gen_info.register_topic(dp, 'Example1')

我在source code 中也看不到相关功能。

如果这是一个简单的问题或者我遗漏了什么,我深表歉意 - 我对 Vortex OpenSplice DDS 非常陌生。

任何帮助将不胜感激。

【问题讨论】:

    标签: python data-distribution-service opensplice


    【解决方案1】:

    我无法与 OpenSplice 交谈,但您可以使用 CoreDX DDS 进行此操作。例如,给定 IDL 文件“hello.idl”:

    struct StringMsg
    {
       string msg;
    };
    

    运行

    coredx_ddl -l python -f hello.idl -d hello
    

    然后,下面的python就是一个例子,说明如何使用生成的'StringMsg'类型来构造一个Topic和一个DataReader:

    import time
    import dds.domain
    from  hello import StringMsg
    
    # Use default QoS, and no listener
    dp    = dds.domain.DomainParticipant( 0 )
    topic = dds.topic.Topic( StringMsg, "helloTopic", "StringMsg", dp )
    sub   = dds.sub.Subscriber( dp )
    dr    = dds.sub.DataReader( sub, topic )
    rc    = dr.create_readcondition( dds.core.SampleState.ANY_SAMPLE_STATE,
                                     dds.core.ViewState.ANY_VIEW_STATE,
                                     dds.core.InstanceState.ANY_INSTANCE_STATE )
    ws    = dds.cond.WaitSet()
    ws.attach_condition(rc)
    
    while True:
        t = dds.core.Duration.infinite()
        print('waiting for data...')
        ws.wait(t)
        while True:
            try:
                samples = dr.take( )
                for s in samples:
                    if s.info.valid_data:
                        print("received: {}".format(s.data.msg))
            except dds.core.Error:
                break;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-29
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多