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

ROSTransportのパラメータの情報を設定する #263

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
29 changes: 27 additions & 2 deletions OpenRTM_aist/GlobalFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def addFactory(self, id, creator, prop=None):
if id in self._creators:
return self.ALREADY_EXISTS

self._creators[id] = creator
self._creators[id] = FactoryEntry(id, creator, prop)
return self.FACTORY_OK

# ReturnCode removeFactory(const Identifier& id)
Expand All @@ -76,9 +76,34 @@ def createObject(self, id):
if id not in self._creators:
print("Factory.createObject return None id: ", id)
return None
obj_ = self._creators[id]()
obj_ = self._creators[id].creator()
return obj_

def getProperties(self, id):
if not id in self._creators:
print("Factory.getProperties return None id: ", id)
return None
return self._creators[id].prop


class FactoryEntry:
def __init__(self, id, creator, prop=None):
self._id = id
self._creator = creator
self._prop = prop

@property
def id(self):
return self._id

@property
def creator(self):
return self._creator

@property
def prop(self):
return self._prop


gfactory = None

Expand Down
30 changes: 30 additions & 0 deletions OpenRTM_aist/InPortBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,10 +1175,25 @@ def initProviders(self):

# InPortProvider supports "push" dataflow type
if provider_types:
prop_options = OpenRTM_aist.Properties()
self._rtcout.RTC_DEBUG("dataflow_type push is supported")
self.appendProperty("dataport.dataflow_type", "push")
for provider_type in provider_types:
self.appendProperty("dataport.interface_type", provider_type)
prop_if = factory.getProperties(provider_type)
if prop_if is None:
prop_if = OpenRTM_aist.Properties()

prop_node = prop_options.getNode(provider_type)
prop_node.mergeProperties(prop_if)

prop = OpenRTM_aist.Properties()
OpenRTM_aist.NVUtil.copyToProperties(
prop, self._profile.properties)
prop_dataport = prop.getNode("dataport.interface_option")
prop_dataport.mergeProperties(prop_options)
OpenRTM_aist.NVUtil.copyFromProperties(
self._profile.properties, prop)

self._providerTypes = provider_types
return
Expand Down Expand Up @@ -1219,10 +1234,25 @@ def initConsumers(self):

# OutPortConsumer supports "pull" dataflow type
if consumer_types:
prop_options = OpenRTM_aist.Properties()
self._rtcout.RTC_PARANOID("dataflow_type pull is supported")
self.appendProperty("dataport.dataflow_type", "pull")
for consumer_type in consumer_types:
self.appendProperty("dataport.interface_type", consumer_type)
prop_if = factory.getProperties(consumer_type)
if prop_if is None:
prop_if = OpenRTM_aist.Properties()

prop_node = prop_options.getNode(consumer_type)
prop_node.mergeProperties(prop_if)

prop = OpenRTM_aist.Properties()
OpenRTM_aist.NVUtil.copyToProperties(
prop, self._profile.properties)
prop_dataport = prop.getNode("dataport.interface_option")
prop_dataport.mergeProperties(prop_options)
OpenRTM_aist.NVUtil.copyFromProperties(
self._profile.properties, prop)

self._consumerTypes = consumer_types
return
Expand Down
31 changes: 31 additions & 0 deletions OpenRTM_aist/OutPortBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,11 +1185,27 @@ def initProviders(self):
provider_types = provider_types + list(set_ptypes)

# OutPortProvider supports "pull" dataflow type

if provider_types:
prop_options = OpenRTM_aist.Properties()
self._rtcout.RTC_DEBUG("dataflow_type pull is supported")
self.appendProperty("dataport.dataflow_type", "pull")
for provider_type in provider_types:
self.appendProperty("dataport.interface_type", provider_type)
prop_if = factory.getProperties(provider_type)
if prop_if is None:
prop_if = OpenRTM_aist.Properties()

prop_node = prop_options.getNode(provider_type)
prop_node.mergeProperties(prop_if)

prop = OpenRTM_aist.Properties()
OpenRTM_aist.NVUtil.copyToProperties(
prop, self._profile.properties)
prop_dataport = prop.getNode("dataport.interface_option")
prop_dataport.mergeProperties(prop_options)
OpenRTM_aist.NVUtil.copyFromProperties(
self._profile.properties, prop)

self._providerTypes = provider_types

Expand Down Expand Up @@ -1229,10 +1245,25 @@ def initConsumers(self):

# InPortConsumer supports "push" dataflow type
if consumer_types:
prop_options = OpenRTM_aist.Properties()
self._rtcout.RTC_PARANOID("dataflow_type push is supported")
self.appendProperty("dataport.dataflow_type", "push")
for consumer_type in consumer_types:
self.appendProperty("dataport.interface_type", consumer_type)
prop_if = factory.getProperties(consumer_type)
if prop_if is None:
prop_if = OpenRTM_aist.Properties()

prop_node = prop_options.getNode(consumer_type)
prop_node.mergeProperties(prop_if)

prop = OpenRTM_aist.Properties()
OpenRTM_aist.NVUtil.copyToProperties(
prop, self._profile.properties)
prop_dataport = prop.getNode("dataport.interface_option")
prop_dataport.mergeProperties(prop_options)
OpenRTM_aist.NVUtil.copyFromProperties(
self._profile.properties, prop)

self._consumerTypes = consumer_types

Expand Down
156 changes: 141 additions & 15 deletions OpenRTM_aist/ext/transport/ROSTransport/ROSInPort.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def __init__(self):
self._messageType = "ros:std_msgs/Float32"
self._roscorehost = ""
self._roscoreport = ""
self._so_reuseaddr = True
self._so_keepalive = True
self._tcp_keepcnt = 9
self._tcp_keepidle = 60
self._tcp_keepintvl = 10
self._tcp_nodelay = True
self._sock_timeout = 60.0

self._tcp_connecters = []
self._con_mutex = threading.RLock()
Expand Down Expand Up @@ -225,6 +232,44 @@ def init(self, prop):
"marshaling_type", "ros:std_msgs/Float32")
self._topic = prop.getProperty("ros.topic", "chatter")
self._topic = "/" + self._topic

self._so_reuseaddr = OpenRTM_aist.toBool(prop.getProperty(
"ros.so_reuseaddr"), "YES", "NO", True)

self._so_keepalive = OpenRTM_aist.toBool(prop.getProperty(
"ros.so_keepalive"), "YES", "NO", True)

try:
self._tcp_keepcnt = int(prop.getProperty(
"ros.tcp_keepcnt"))
except ValueError as error:
pass
# self._rtcout.RTC_ERROR(error)

try:
self._tcp_keepidle = int(prop.getProperty(
"ros.tcp_keepidle"))
except ValueError as error:
pass
# self._rtcout.RTC_ERROR(error)

try:
self._tcp_keepintvl = int(prop.getProperty(
"ros.tcp_keepintvl"))
except ValueError as error:
pass
# self._rtcout.RTC_ERROR(error)

self._tcp_nodelay = OpenRTM_aist.toBool(prop.getProperty(
"ros.tcp_nodelay"), "YES", "NO", True)

try:
self._sock_timeout = float(prop.getProperty(
"ros.sock.timeout"))
except ValueError as error:
pass
# self._rtcout.RTC_ERROR(error)

self._roscorehost = prop.getProperty("ros.roscore.host")
self._roscoreport = prop.getProperty("ros.roscore.port")

Expand All @@ -234,9 +279,10 @@ def init(self, prop):
ROSInPort.ROS_MASTER_URI)
env = os.getenv(ROSInPort.ROS_MASTER_URI)
if env:
self._rtcout.RTC_VERBOSE("$%s: %s", (ROSInPort.ROS_MASTER_URI, env))
env = env.replace("http://","")
env = env.replace("https://","")
self._rtcout.RTC_VERBOSE(
"$%s: %s", (ROSInPort.ROS_MASTER_URI, env))
env = env.replace("http://", "")
env = env.replace("https://", "")
envsplit = env.split(":")
self._roscorehost = envsplit[0]
if len(envsplit) >= 2:
Expand All @@ -248,7 +294,6 @@ def init(self, prop):
if not self._roscoreport:
self._roscoreport = ROSInPort.ROS_DEFAULT_MASTER_PORT


self._rtcout.RTC_VERBOSE("topic name: %s", self._topic)
self._rtcout.RTC_VERBOSE(
"roscore address: %s:%s",
Expand All @@ -268,7 +313,7 @@ def init(self, prop):
info_type = info.datatype()
else:
self._rtcout.RTC_ERROR("can not found %s", self._messageType)
return
raise MemoryError("Message Type ERROR")

self._rtcout.RTC_VERBOSE("caller id: %s", self._callerid)

Expand All @@ -282,7 +327,8 @@ def init(self, prop):
self._callerid, self._topic, info_type, self._topicmgr.getURI())
except xmlrpclib.Fault as err:
self._rtcout.RTC_ERROR("XML-RPC ERROR: %s", err.faultString)
return
raise MemoryError("XML-RPC ERROR")

self.connect(self._callerid, self._topic, val)

##
Expand Down Expand Up @@ -340,13 +386,47 @@ def connect(self, caller_id, topic, publishers):
else:
_, dest_addr, dest_port = result
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT, 9)
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 60)
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, 10)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
sock.settimeout(60.0)
so_reuseaddr = 1
if not self._so_reuseaddr:
so_reuseaddr = 0
sock.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR, so_reuseaddr)
so_keepalive = 1
if not self._so_keepalive:
so_keepalive = 0
sock.setsockopt(socket.SOL_SOCKET,
socket.SO_KEEPALIVE, so_keepalive)
if self._so_keepalive:
sock.setsockopt(
socket.SOL_TCP, socket.TCP_KEEPCNT, self._tcp_keepcnt)
sock.setsockopt(
socket.SOL_TCP, socket.TCP_KEEPIDLE, self._tcp_keepidle)
sock.setsockopt(
socket.SOL_TCP, socket.TCP_KEEPINTVL, self._tcp_keepintvl)

tcp_nodelay = 1
if not self._tcp_nodelay:
tcp_nodelay = 0

sock.setsockopt(socket.IPPROTO_TCP,
socket.TCP_NODELAY, tcp_nodelay)
sock.settimeout(self._sock_timeout)

self._rtcout.RTC_VERBOSE(
"SO_REUSEADDR: %s", self._so_reuseaddr)
self._rtcout.RTC_VERBOSE(
"SO_KEEPALIVE: %s", self._so_keepalive)
self._rtcout.RTC_VERBOSE(
"TCP_KEEPCNT: %d", self._tcp_keepcnt)
self._rtcout.RTC_VERBOSE(
"TCP_KEEPIDLE: %d", self._tcp_keepidle)
self._rtcout.RTC_VERBOSE(
"TCP_KEEPINTVL: %d", self._tcp_keepintvl)
self._rtcout.RTC_VERBOSE(
"TCP_NODELAY: %d", self._tcp_nodelay)
self._rtcout.RTC_VERBOSE(
"Socket timeout: %lf", self._sock_timeout)

sock.connect((dest_addr, dest_port))

fileno = sock.fileno()
Expand Down Expand Up @@ -391,9 +471,12 @@ def connect(self, caller_id, topic, publishers):
"Can not found %s", self._messageType)

sock.setblocking(1)
tcp_nodelay = '1'
if not self._tcp_nodelay:
tcp_nodelay = '0'
fields = {'topic': topic,
'message_definition': info_message_definition,
'tcp_nodelay': '0',
'tcp_nodelay': tcp_nodelay,
'md5sum': info_md5sum,
'type': info_type,
'callerid': self._callerid}
Expand Down Expand Up @@ -794,6 +877,45 @@ def recieve(self):
return


ros_sub_option = [
"topic.__value__", "chatter",
"topic.__widget__", "text",
"topic.__constraint__", "none",
"roscore.host.__value__", "",
"roscore.host.__widget__", "text",
"roscore.host.__constraint__", "none",
"roscore.port.__value__", "",
"roscore.port.__widget__", "text",
"roscore.port.__constraint__", "none",
"node.name.__value__", "",
"node.name.__widget__", "text",
"node.name.__constraint__", "none",
"node.anonymous.__value__", "NO",
"node.anonymous.__widget__", "radio",
"node.anonymous.__constraint__", "(YES, NO)",
"so_reuseaddr.__value__", "YES",
"so_reuseaddr.__widget__", "radio",
"so_reuseaddr.__constraint__", "(YES, NO)",
"so_keepalive.__value__", "YES",
"so_keepalive.__widget__", "radio",
"so_keepalive.__constraint__", "(YES, NO)",
"tcp_nodelay.__value__", "YES",
"tcp_nodelay.__widget__", "radio",
"tcp_nodelay.__constraint__", "(YES, NO)",
"tcp_keepcnt.__value__", "9",
"tcp_keepcnt.__widget__", "spin",
"tcp_keepcnt.__constraint__", "1 <= x <= 10000",
"tcp_keepidle.__value__", "60",
"tcp_keepidle.__widget__", "spin",
"tcp_keepidle.__constraint__", "1 <= x <= 10000",
"tcp_keepintvl.__value__", "10",
"tcp_keepintvl.__widget__", "spin",
"tcp_keepintvl.__constraint__", "1 <= x <= 10000",
"ros.sock.timeout.__value__", "60",
"ros.sock.timeout.__widget__", "spin",
"ros.sock.timeout.__constraint__", "1 <= x <= 10000",
""
]
##
# @if jp
# @brief モジュール登録関数
Expand All @@ -805,7 +927,11 @@ def recieve(self):
#
# @endif
#


def ROSInPortInit():
prop = OpenRTM_aist.Properties(defaults_str=ros_sub_option)
factory = OpenRTM_aist.InPortProviderFactory.instance()
factory.addFactory("ros",
ROSInPort)
ROSInPort,
prop)
Loading
Loading