Example #1
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 #2
0
 def __init__(self):
     # Initialize the ROS publisher node
     rospy.init_node('bridge_publisher')
     
     # Setup MTConnect to ROS Conversion
     self.config = bridge_library.obtain_dataMap()
     self.msg_parameters = ['url', 'url_port', 'machine_tool', 'xml_namespace']
     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]])
     
     # Check for url connectivity, dwell until system timeout
     bridge_library.check_connectivity((1,self.url,self.url_port))
     
     # Create the data lists for the topic names, types, manifests, data items, ROS publishers, and ROS messages
     self.topic_name_list = []
     self.topic_type_list = []
     self.lib_manifests = []
     self.data_items = []
     self.pub = []
     self.msg = []
     self.data_hold = None
     
     # Setup topic, data items, pub, etc. via configuration file
     self.setup_topic_data()
     
     # Hash table of persistent CNC event states, only updates when state changes
     self.di_current = self.init_di_dict()
     
     # Hash table to store changed CNC event states
     self.di_changed = None
     
     # 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, None, 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.di_current)
     
     # Use XML to establish current data item state dictionary
     for di in self.di_current.keys():
         name = bridge_library.split_event(di)
         for e in elements:
             rospy.loginfo('Element %s --> %s' % (e.tag, e.text))
             if name == e.attrib['name']:
                 self.di_current[di] = e.text
     
     # Confirm that data items in config file are present in XML
     for di_set in self.data_items:
         if not set(di_set).issubset(set(self.di_current.keys())):
             rospy.logerr('ERROR: INCORRECT EVENTS IN TOPIC CONFIG OR XML AGENT FILE')
             sys.exit()
     
     # Start a streaming XML connection
     response = bridge_library.xml_get_response((self.url, self.url_port, None, self.conn, self.mtool + "/sample?interval=1000&count=1000&from=" + seq))
     
     # Create queue for streaming XML
     self.XML_queue = Queue()
     
     # Create a ROS publishing thread
     self.ros_publisher()
     
     # Streams data from the agent...
     lp = LongPull(response)
     lp.long_pull(self.xml_callback) # Runs until user interrupts
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('robot_link')
     
     # Check for url connectivity, dwell until system timeout
     bridge_library.check_connectivity((1, 'localhost', 5000))
     bridge_library.check_connectivity((1, 'localhost', 5001))
     
     # Global variables
     self.XML_CNC_queue = Queue()
     self.XML_RBT_queue = Queue()
     self.cnc_capture_xml = True
     self.rbt_capture_xml = True
     self.cnc_conn = httplib.HTTPConnection('localhost', 5000)
     self.rbt_conn = httplib.HTTPConnection('localhost', 5001)
     self.ns = dict(m = 'urn:mtconnect.org:MTConnectStreams:1.2')
     self.data_items = {'MaterialLoad' : 'MaterialLoad', 'MaterialUnload' : 'MaterialUnload'}
     
     # Establish CNC XML connection, read in current XML
     cnc_response = bridge_library.xml_get_response(('localhost', 5000, None, self.cnc_conn, "/cnc/current"))
     cnc_body = cnc_response.read()
     
     # Parse the XML and determine the current sequence and XML Event elements
     seq, elements = bridge_library.xml_components(cnc_body, self.ns, self.data_items)
     
     # Start a streaming XML connection
     cnc_response = bridge_library.xml_get_response(('localhost', 5000, None, self.cnc_conn, "/cnc/sample?interval=1000&count=1000&from=" + seq))
     
     # Create CNC XML polling thread
     cnc_lp = LongPull(cnc_response)
     self.cnc_thread = threading.Thread(target = cnc_lp.long_pull, args = (self.cnc_xml_callback,))
     self.cnc_thread.daemon = True
     self.cnc_thread.start()
     rospy.loginfo('STARTED STREAMING CNC XML THREAD')
     
     # Establish Robot XML connection, read in current XML
     rbt_response = bridge_library.xml_get_response(('localhost', 5001, None, self.rbt_conn, "/Robot/current"))
     rbt_body = rbt_response.read()
     
     # Parse the XML and determine the current sequence and XML Event elements
     seq, elements = bridge_library.xml_components(rbt_body, self.ns, self.data_items)
     
     # Start a streaming XML connection
     rbt_response = bridge_library.xml_get_response(('localhost', 5001, None, self.rbt_conn, "/Robot/sample?interval=1000&count=1000&from=" + seq))
     
     # Create Robot XML polling thread
     rbt_lp = LongPull(rbt_response)
     self.rbt_thread = threading.Thread(target = rbt_lp.long_pull, args = (self.rbt_xml_callback,))
     self.rbt_thread.daemon = True
     self.rbt_thread.start()
     rospy.loginfo('STARTED STREAMING ROBOT XML THREAD')
     
     # Create robot initialization publisher thread
     self.t1 = threading.Thread(target = self.talker)
     self.t1.daemon = True
     self.t1.start()
     rospy.loginfo('STARTED ROBOT INITIALIZATION THREAD')
     
     # Create state sequence thread
     self.t2 = threading.Thread(target = self.run_actions)
     self.t2.daemon = True
     self.t2.start()
     rospy.loginfo('STARTED STATE MACHINE THREAD')
Example #5
0
    def __init__(self):
        # Initialize ROS generic client node
        rospy.init_node('robot_link')

        # Check for url connectivity, dwell until system timeout
        bridge_library.check_connectivity((1, 'localhost', 5000))
        bridge_library.check_connectivity((1, 'localhost', 5001))

        # Global variables
        self.XML_CNC_queue = Queue()
        self.XML_RBT_queue = Queue()
        self.cnc_capture_xml = True
        self.rbt_capture_xml = True
        self.cnc_conn = httplib.HTTPConnection('localhost', 5000)
        self.rbt_conn = httplib.HTTPConnection('localhost', 5001)
        self.ns = dict(m='urn:mtconnect.org:MTConnectStreams:1.2')
        self.data_items = {
            'MaterialLoad': 'MaterialLoad',
            'MaterialUnload': 'MaterialUnload'
        }

        # Establish CNC XML connection, read in current XML
        cnc_response = bridge_library.xml_get_response(
            ('localhost', 5000, None, self.cnc_conn, "/cnc/current"))
        cnc_body = cnc_response.read()

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

        # Start a streaming XML connection
        cnc_response = bridge_library.xml_get_response(
            ('localhost', 5000, None, self.cnc_conn,
             "/cnc/sample?interval=1000&count=1000&from=" + seq))

        # Create CNC XML polling thread
        cnc_lp = LongPull(cnc_response)
        self.cnc_thread = threading.Thread(target=cnc_lp.long_pull,
                                           args=(self.cnc_xml_callback, ))
        self.cnc_thread.daemon = True
        self.cnc_thread.start()
        rospy.loginfo('STARTED STREAMING CNC XML THREAD')

        # Establish Robot XML connection, read in current XML
        rbt_response = bridge_library.xml_get_response(
            ('localhost', 5001, None, self.rbt_conn, "/Robot/current"))
        rbt_body = rbt_response.read()

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

        # Start a streaming XML connection
        rbt_response = bridge_library.xml_get_response(
            ('localhost', 5001, None, self.rbt_conn,
             "/Robot/sample?interval=1000&count=1000&from=" + seq))

        # Create Robot XML polling thread
        rbt_lp = LongPull(rbt_response)
        self.rbt_thread = threading.Thread(target=rbt_lp.long_pull,
                                           args=(self.rbt_xml_callback, ))
        self.rbt_thread.daemon = True
        self.rbt_thread.start()
        rospy.loginfo('STARTED STREAMING ROBOT XML THREAD')

        # Create robot initialization publisher thread
        self.t1 = threading.Thread(target=self.talker)
        self.t1.daemon = True
        self.t1.start()
        rospy.loginfo('STARTED ROBOT INITIALIZATION THREAD')

        # Create state sequence thread
        self.t2 = threading.Thread(target=self.run_actions)
        self.t2.daemon = True
        self.t2.start()
        rospy.loginfo('STARTED STATE MACHINE THREAD')
Example #6
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()