Go to the documentation of this file.00001
00002 import sys
00003 import time
00004
00005 import rosgraph
00006 import rosnode
00007 import rospy
00008 from opcua import Server, ua
00009
00010 import ros_services
00011 import ros_topics
00012
00013
00014
00015 def nextname(hierachy, index_of_last_processed):
00016 try:
00017 output = ""
00018 counter = index_of_last_processed + 1
00019 while counter < len(hierachy):
00020 output += hierachy[counter]
00021 counter += 1
00022 return output
00023 except Exception as e:
00024 rospy.logerr("Error encountered ", e)
00025
00026
00027 def own_rosnode_cleanup():
00028 pinged, unpinged = rosnode.rosnode_ping_all()
00029 if unpinged:
00030 master = rosgraph.Master(rosnode.ID)
00031
00032 rosnode.cleanup_master_blacklist(master, unpinged)
00033
00034
00035 class ROSServer:
00036 def __init__(self):
00037 self.namespace_ros = rospy.get_param("/rosopcua/namespace")
00038 self.topicsDict = {}
00039 self.servicesDict = {}
00040 self.actionsDict = {}
00041 rospy.init_node("rosopcua")
00042 self.server = Server()
00043 self.server.set_endpoint("opc.tcp://0.0.0.0:21554/")
00044 self.server.set_server_name("ROS ua Server")
00045 self.server.start()
00046
00047 uri_topics = "http://ros.org/topics"
00048
00049 uri_services = "http://ros.org/services"
00050 uri_actions = "http://ros.org/actions"
00051 idx_topics = self.server.register_namespace(uri_topics)
00052 idx_services = self.server.register_namespace(uri_services)
00053 idx_actions = self.server.register_namespace(uri_actions)
00054
00055 objects = self.server.get_objects_node()
00056
00057 topics_object = objects.add_object(idx_topics, "ROS-Topics")
00058 services_object = objects.add_object(idx_services, "ROS-Services")
00059 actions_object = objects.add_object(idx_actions, "ROS_Actions")
00060 while not rospy.is_shutdown():
00061
00062 ros_services.refresh_services(self.namespace_ros, self, self.servicesDict, idx_services, services_object)
00063 ros_topics.refresh_topics_and_actions(self.namespace_ros, self, self.topicsDict, self.actionsDict,
00064 idx_topics, idx_actions, topics_object, actions_object)
00065
00066 time.sleep(60)
00067 self.server.stop()
00068 quit()
00069
00070 def find_service_node_with_same_name(self, name, idx):
00071 rospy.logdebug("Reached ServiceCheck for name " + name)
00072 for service in self.servicesDict:
00073 rospy.logdebug("Found name: " + str(self.servicesDict[service].parent.nodeid.Identifier))
00074 if self.servicesDict[service].parent.nodeid.Identifier == name:
00075 rospy.logdebug("Found match for name: " + name)
00076 return self.servicesDict[service].parent
00077 return None
00078
00079 def find_topics_node_with_same_name(self, name, idx):
00080 rospy.logdebug("Reached TopicCheck for name " + name)
00081 for topic in self.topicsDict:
00082 rospy.logdebug("Found name: " + str(self.topicsDict[topic].parent.nodeid.Identifier))
00083 if self.topicsDict[topic].parent.nodeid.Identifier == name:
00084 rospy.logdebug("Found match for name: " + name)
00085 return self.topicsDict[topic].parent
00086 return None
00087
00088 def find_action_node_with_same_name(self, name, idx):
00089 rospy.logdebug("Reached ActionCheck for name " + name)
00090 for topic in self.actionsDict:
00091 rospy.logdebug("Found name: " + str(self.actionsDict[topic].parent.nodeid.Identifier))
00092 if self.actionsDict[topic].parent.nodeid.Identifier == name:
00093 rospy.logdebug("Found match for name: " + name)
00094 return self.actionsDict[topic].parent
00095 return None
00096
00097
00098 def main(args):
00099 rosserver = ROSServer()
00100
00101
00102 if __name__ == "__main__":
00103 main(sys.argv)