def setup_topic_data(self):
        for topic, topic_type in self.config.items():
            if topic not in self.msg_parameters:
                self.topic_name_list.append(topic)
                
                # Only one type per topic
                type_key = topic_type.keys()[0]
                self.subscribed_list.append(type_key)
                
                # One set of data items per topic type
                self.data_items = [data_item for data_item in topic_type[type_key].keys()]
        
                # Add data items to the MTConnect Adapter - must be unique data items
                bridge_library.add_event((self.adapter, self.data_items, self.di_dict, False))
                
                # Extract package name and topic type name
                tokens = topic_type.keys()[0].split('/')
                package = tokens[0]
                type_name = tokens[1]
                
                # Load package manifest if unique
                if package not in self.lib_manifests:
                    roslib.load_manifest(package)
                    self.lib_manifests.append(package)
                
                # Import module and create topic type class,
                #    i.e. append <class 'mtconnect_msgs.msg._RobotStates.RobotStates'>
                rospy.loginfo('Class Instance --> ' + package + '.msg.' + type_name)
                type_handle = getattr(import_module(package + '.msg'), type_name)

                self.topic_type_list[topic] = type_handle
                self.msg_text[topic] = type_handle._full_text
                self.member_types[topic] = type_handle._slot_types
                self.member_names[topic] = type_handle.__slots__
        return
    def setup_topic_data(self):
        for topic, topic_type in self.config.items():
            if topic not in self.msg_parameters:
                self.topic_name_list.append(topic)

                # Only one type per topic
                type_key = topic_type.keys()[0]
                self.subscribed_list.append(type_key)

                # One set of data items per topic type
                self.data_items = [
                    data_item for data_item in topic_type[type_key].keys()
                ]

                # Add data items to the MTConnect Adapter - must be unique data items
                bridge_library.add_event(
                    (self.adapter, self.data_items, self.di_dict, False))

                # Extract package name and topic type name
                tokens = topic_type.keys()[0].split('/')
                package = tokens[0]
                type_name = tokens[1]

                # Load package manifest if unique
                if package not in self.lib_manifests:
                    roslib.load_manifest(package)
                    self.lib_manifests.append(package)

                # Import module and create topic type class,
                #    i.e. append <class 'mtconnect_msgs.msg._RobotStates.RobotStates'>
                rospy.loginfo('Class Instance --> ' + package + '.msg.' +
                              type_name)
                type_handle = getattr(import_module(package + '.msg'),
                                      type_name)

                self.topic_type_list[topic] = type_handle
                self.msg_text[topic] = type_handle._full_text
                self.member_types[topic] = type_handle._slot_types
                self.member_names[topic] = type_handle.__slots__
        return
Example #3
0
    def __init__(self):
        # Initialize ROS generic client node
        rospy.init_node('ActionClient')
        
        # Setup MTConnect to ROS Conversion
        self.config = bridge_library.obtain_dataMap()
        self.msg_parameters = ['url', 'url_port', 'machine_tool', 'xml_namespace', 'adapter_port', 'service']
        self.url = self.config[self.msg_parameters[0]]
        self.url_port = self.config[self.msg_parameters[1]]
        self.mtool = self.config[self.msg_parameters[2]]
        self.ns = dict(m = self.config[self.msg_parameters[3]])
        self.port = self.config[self.msg_parameters[4]]
        self.service = self.config[self.msg_parameters[5]]
        
        # Check for url connectivity, dwell until system timeout
        bridge_library.check_connectivity((1,self.url,self.url_port))
        
        # Setup MTConnect Adapter for robot status data items
        self.adapter = Adapter((self.url, self.port))
        
        # Create empty lists for actions, message type handles, etc.
        self.lib_manifests = []
        self.type_handle = None
        self.action_list = {}
        self.action_goals = {}
        self.package = None
        self.xml_goal = None
        self.di_dict = {} # XML data item dictionary to store MTConnect Adapter Events
        self.handshake = None
        
        # Setup action client data per the config file
        self.setup_topic_data()
        
        # Add data items to the MTConnect Adapter - must be unique data items
        bridge_library.add_event((self.adapter, self.action_list, self.di_dict, False))
        
        # Start the adapter
        rospy.loginfo('Start the Robot Link adapter')
        self.adapter.start()
        
        # Create robot Service Server thread for each machine tool action
        self.action_service = []
        for mt_action in self.action_goals.keys():
            self.action_service.append(ActionService(mt_action, self.adapter, self.di_dict, self.service_handle, self.service))
        
        # Establish XML connection, read in current XML
        while True:
            try:
                self.conn = HTTPConnection(self.url, self.url_port)
                response = bridge_library.xml_get_response((self.url, self.url_port, self.port, self.conn, self.mtool + "/current"))
                body = response.read()
                break
            except socket.error as e:
                rospy.loginfo('HTTP connection error %s' % e)
                time.sleep(10)
        
        # Parse the XML and determine the current sequence and XML Event elements
        seq, elements = bridge_library.xml_components(body, self.ns, self.action_list)

        # Start a streaming XML connection
        response = bridge_library.xml_get_response((self.url, self.url_port, self.port, self.conn, self.mtool + "/sample?interval=1000&count=1000&from=" + seq))
        
        # Create class lock
        self.lock = thread.allocate_lock()

        # Create XML polling thread
        lp = LongPull(response)
        lp.long_pull(self.xml_callback) # Runs until user interrupts
Example #4
0
    def __init__(self):
        # Initialize ROS generic client node
        rospy.init_node('ActionClient')

        # Setup MTConnect to ROS Conversion
        self.config = bridge_library.obtain_dataMap()
        self.msg_parameters = [
            'url', 'url_port', 'machine_tool', 'xml_namespace', 'adapter_port',
            'service'
        ]
        self.url = self.config[self.msg_parameters[0]]
        self.url_port = self.config[self.msg_parameters[1]]
        self.mtool = self.config[self.msg_parameters[2]]
        self.ns = dict(m=self.config[self.msg_parameters[3]])
        self.port = self.config[self.msg_parameters[4]]
        self.service = self.config[self.msg_parameters[5]]

        # Check for url connectivity, dwell until system timeout
        bridge_library.check_connectivity((1, self.url, self.url_port))

        # Setup MTConnect Adapter for robot status data items
        self.adapter = Adapter((self.url, self.port))

        # Create empty lists for actions, message type handles, etc.
        self.lib_manifests = []
        self.type_handle = None
        self.action_list = {}
        self.action_goals = {}
        self.package = None
        self.xml_goal = None
        self.di_dict = {
        }  # XML data item dictionary to store MTConnect Adapter Events
        self.handshake = None

        # Setup action client data per the config file
        self.setup_topic_data()

        # Add data items to the MTConnect Adapter - must be unique data items
        bridge_library.add_event(
            (self.adapter, self.action_list, self.di_dict, False))

        # Start the adapter
        rospy.loginfo('Start the Robot Link adapter')
        self.adapter.start()

        # Create robot Service Server thread for each machine tool action
        self.action_service = []
        for mt_action in self.action_goals.keys():
            self.action_service.append(
                ActionService(mt_action, self.adapter, self.di_dict,
                              self.service_handle, self.service))

        # Establish XML connection, read in current XML
        while True:
            try:
                self.conn = HTTPConnection(self.url, self.url_port)
                response = bridge_library.xml_get_response(
                    (self.url, self.url_port, self.port, self.conn,
                     self.mtool + "/current"))
                body = response.read()
                break
            except socket.error as e:
                rospy.loginfo('HTTP connection error %s' % e)
                time.sleep(10)

        # Parse the XML and determine the current sequence and XML Event elements
        seq, elements = bridge_library.xml_components(body, self.ns,
                                                      self.action_list)

        # Start a streaming XML connection
        response = bridge_library.xml_get_response(
            (self.url, self.url_port, self.port, self.conn,
             self.mtool + "/sample?interval=1000&count=1000&from=" + seq))

        # Create class lock
        self.lock = thread.allocate_lock()

        # Create XML polling thread
        lp = LongPull(response)
        lp.long_pull(self.xml_callback)  # Runs until user interrupts
Example #5
0
 def __init__(self):
     # Initialize ROS generic client node
     rospy.init_node('ActionServer')
     
     # Setup MTConnect to ROS Conversion
     self.config = bridge_library.obtain_dataMap()
     self.msg_parameters = ['url', 'url_port', 'machine_tool', 'xml_namespace', 'adapter_port']
     self.url = self.config[self.msg_parameters[0]]
     self.url_port = self.config[self.msg_parameters[1]]
     self.mtool = self.config[self.msg_parameters[2]]
     self.ns = dict(m = self.config[self.msg_parameters[3]])
     self.port = self.config[self.msg_parameters[4]]
     
     # Check for url connectivity, dwell until system timeout
     bridge_library.check_connectivity((1,self.url,self.url_port))
     
     # Setup MTConnect Adapter for robot status data items
     self.adapter = Adapter((self.url, self.port))
     
     # Create empty lists for actions, message type handles, etc.
     self.lib_manifests = []
     self.type_handle = None
     self.action_list = {}
     self.capture_xml = False
     self.di_dict = {} # XML data item dictionary to store MTConnect Adapter Events
     
     # Create a dictionary of _results to return upon action success
     self._resultDict = {}
     
     # Create a dictionary of action servers
     self._as = {}
     
     # Create a dictionary of server names
     self.server_name = {}
     
     # Setup action client data per the config file
     self.setup_topic_data()
     
     # Add data items to the MTConnect Adapter - must be unique data items
     bridge_library.add_event((self.adapter, self.action_list, self.di_dict, True))
     
     # Start the adapter
     rospy.loginfo('Start the Robot Link adapter')
     self.adapter.start()
     
     # Establish XML connection, read in current XML
     while True:
         try:
             self.conn = HTTPConnection(self.url, self.url_port)
             response = bridge_library.xml_get_response((self.url, self.url_port, self.port, self.conn, self.mtool + "/current"))
             body = response.read()
             break
         except socket.error as e:
             rospy.loginfo('HTTP connection error %s' % e)
             time.sleep(10)
     
     # Parse the XML and determine the current sequence and XML Event elements
     seq, elements = bridge_library.xml_components(body, self.ns, self.action_list)
     
     # Start a streaming XML connection
     response = bridge_library.xml_get_response((self.url, self.url_port, self.port, self.conn, self.mtool + "/sample?interval=1000&count=1000&from=" + seq))
     
     # Create queue for streaming XML
     self.XML_queue = Queue()
     
     # Create XML polling thread
     lp = LongPull(response)
     xml_thread = Thread(target = lp.long_pull, args = (self.xml_callback,))
     xml_thread.daemon = True
     xml_thread.start()