Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to connect using IP address of the robot. #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions unitree_sdk2py/core/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from cyclonedds.internal import dds_c_t, InvalidSample

# for channel config
from .channel_config import ChannelConfigAutoDetermine, ChannelConfigHasInterface
from .channel_config import ChannelConfigAutoDetermine, ChannelConfigHasInterface, ChannelConfigHasIP

# for singleton
from ..utils.singleton import Singleton
Expand Down Expand Up @@ -201,7 +201,12 @@ def Init(self, id: int, networkInterface: str = None, qos: Qos = None):
if networkInterface is None:
config = ChannelConfigAutoDetermine
else:
config = ChannelConfigHasInterface.replace('$__IF_NAME__$', networkInterface)
if "." in networkInterface: # connect using IP
config = ChannelConfigHasIP.replace('$__IF_IP__$', networkInterface)
print(f"connecting using IP: {networkInterface}")
else: # connect using Iface
config = ChannelConfigHasInterface.replace('$__IF_NAME__$', networkInterface)
print(f"connecting using Iface: {networkInterface}")

try:
self.__domain = Domain(id, config)
Expand Down
11 changes: 11 additions & 0 deletions unitree_sdk2py/core/channel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@
</General>
</Domain>
</CycloneDDS>'''

ChannelConfigHasIP = '''<?xml version="1.0" encoding="UTF-8" ?>
<CycloneDDS>
<Domain Id="any">
<General>
<Interfaces>
<NetworkInterface address="$__IF_IP__$" priority="default" multicast="default"/>
</Interfaces>
</General>
</Domain>
</CycloneDDS>'''