eclipse-cyclonedds / cyclonedds-python

Other
54 stars 44 forks source link

does dds support vehicles to interaction on different devices? #165

Open CuteSmartTiger opened 1 year ago

CuteSmartTiger commented 1 year ago

I run two different cars on the same device, configured with the same domain, and the batches can send and receive information interactively; however, if the two processes are not on the same device, or on different network segments, what should I do the configuration for interaction, is there an example?

CuteSmartTiger commented 1 year ago

i write a xml config file,it comes error. it will be better if can give python example and xml config

thijsmie commented 1 year ago

Hi @CuteSmartTiger,

Most of the time, if you have two devices in the same LAN, CycloneDDS "should just work". If your network setup gets more complicated, you can configure network interfaces via the CycloneDDS XML config file, which you mentioned you did. If it is not working, can you share your XML configuration, your network setup and any errors you run into?

CuteSmartTiger commented 1 year ago

xml as follow

<?xml version="1.0" encoding="UTF-8" ?>
<CycloneDDS xmlns="https://cdds.io/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://cdds.io/config https://raw.githubusercontent.com/eclipse-cyclonedds/cyclonedds/master/etc/cyclonedds.xsd">
    <Domain Id="any">
        <General>
            <Interfaces>
                <NetworkInterface name="inter" address="192.168.158.128" priority="default" multicast="default" />
            </Interfaces>
            <AllowMulticast>default</AllowMulticast>
            <MaxMessageSize>65500B</MaxMessageSize>
        </General>
        <Discovery>
            <EnableTopicDiscoveryEndpoints>true</EnableTopicDiscoveryEndpoints>
        </Discovery>
        <Internal>
            <Watermarks>
                <WhcHigh>500kB</WhcHigh>
            </Watermarks>
        </Internal>
        <Tracing>
            <Verbosity>config</Verbosity>
            <OutputFile>cdds.log.${CYCLONEDDS_PID}</OutputFile>
        </Tracing>
    </Domain>
</CycloneDDS>

python code as follow

from os import environ
environ['CYCLONEDDS_URI'] = '/home/xiaoyao/selfproject/selftool/etc/cyclonedds.xml'

from dataclasses import dataclass
from cyclonedds.domain import DomainParticipant,Domain
from cyclonedds.core import Qos, Policy
from cyclonedds.pub import DataWriter
from cyclonedds.sub import DataReader
from cyclonedds.topic import Topic
from cyclonedds.idl import IdlStruct
from cyclonedds.idl.annotations import key
from time import sleep
import numpy as np

try:
    from names import get_full_name

    name = get_full_name()
except:
    import os

    name = f"{os.getpid()}"

@dataclass
class Chatter(IdlStruct, typename="Chatter"):
    name: str
    key("name")
    message: str
    count: int

rng = np.random.default_rng()
dp = DomainParticipant()
tp = Topic(dp, "Hello", Chatter, qos=Qos(Policy.Reliability.Reliable(0)))
dw = DataWriter(dp, tp)
dr = DataReader(dp, tp)
count = 0

if __name__ == '__main__':
    while True:
        sample = Chatter(name=name, message="Hello, World!", count=count)
        count = count + 1
        print("Writing ", sample)
        dw.write(sample)
        for sample in dr.take(10):
            print("Read ", sample)
        sleep(rng.exponential())
eboasson commented 1 year ago

@CuteSmartTiger what error are you getting? Your config seems valid to me