예제 #1
0
    def test_rosnode_list(self):
        from ros import rosnode
        cmd = 'rosnode'

        nodes = ['/talker',
                 '/foo/talker',
                 '/bar/talker',
                 '/baz/talker1',
                 '/baz/talker2',
                 '/baz/talker3',
                 '/rosout',
                 ]
        l = rosnode.get_node_names()
        for t in nodes:
            self.assert_(t in l)
            
        try:
            rosnode._rosnode_cmd_list([cmd, 'list', 'one', 'two'])
            self.fail("should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
예제 #2
0
    def test_rosnode_list(self):
        from ros import rosnode
        cmd = 'rosnode'

        nodes = [
            '/talker',
            '/foo/talker',
            '/bar/talker',
            '/baz/talker1',
            '/baz/talker2',
            '/baz/talker3',
            '/rosout',
        ]
        l = rosnode.get_node_names()
        for t in nodes:
            self.assert_(t in l)

        try:
            rosnode._rosnode_cmd_list([cmd, 'list', 'one', 'two'])
            self.fail("should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
예제 #3
0
def get_nodes():
    """ Returns a list of all the nodes registered in the ROS system """
    return rosnode.get_node_names()
예제 #4
0
def get_nodes():
    """ Returns a list of all the nodes registered in the ROS system """
    return rosnode.get_node_names()
예제 #5
0
    def poll(self):
        # Read the current system state from the ROS master
        publishers, subscribers, _ = map(
            dict,
            rospy.get_master().getSystemState()[2])
        node_names = set(rosnode.get_node_names())
        topic_types = rospy.get_master().getPublishedTopics('')[2]

        # Update the dictionary of topic types
        for topic, type in topic_types:
            if self.topic_types.get(topic, None) != type:
                self.updates.set_topic_type(topic, type)
                self.topic_types[topic] = type

        # Create new nodes (needed for nodes without any pub/sub topics)
        for name in node_names:
            self.node(name)

        # Link up published topics
        for topic in publishers:
            if topic in TOPIC_NAMES_TO_IGNORE:
                continue
            for name in publishers[topic]:
                if name in NODE_NAMES_TO_IGNORE:
                    continue
                node = self.node(name)
                if node is not None:
                    node.output(topic)
                node_names.add(name)

        # Link up subscribed topics
        for topic in subscribers:
            if topic in TOPIC_NAMES_TO_IGNORE:
                continue
            for name in subscribers[topic]:
                if name in NODE_NAMES_TO_IGNORE:
                    continue
                node = self.node(name)
                if node is not None:
                    node.input(topic)
                node_names.add(name)

        # Remove old node names
        killed_names = self.names_to_stop_avoiding - node_names
        self.names_to_stop_avoiding -= killed_names
        self.names_to_avoid -= killed_names

        # Remove old slots
        for name, node in self.nodes.items() + self.owned_nodes.items():
            for input in node.inputs.values():
                if input.topic not in subscribers or node.name not in subscribers[
                        input.topic]:
                    del node.inputs[input.topic]
            for output in node.outputs.values():
                if output.topic not in publishers or node.name not in publishers[
                        output.topic]:
                    del node.outputs[output.topic]

        # Remove old nodes
        for name in self.nodes.keys():
            if name not in node_names:
                del self.nodes[name]

        # Update owned nodes
        for name in self.owned_nodes:
            node = self.owned_nodes[name]

            # Check on the process
            if node.status == 'Starting...' and node.name in node_names:
                node.status = ''
                self.updates.update_owned_node(node)
            node.poll()

            # Remember all observed topics for when we restart this node in the future
            if node.path not in self.db.topics:
                self.db.topics[node.path] = set(), set()
            published, subscribed = self.db.topics[node.path]
            published |= set(topic for topic in node.outputs
                             if node.outputs[topic].original_topic is None)
            subscribed |= set(topic for topic in node.inputs
                              if node.inputs[topic].original_topic is None)

        # Save all observed topics
        self.db.save()

        # Keep polling killed child processes until they actually die
        for process in list(self.killed_processes):
            process.poll()
            if process.returncode is not None:
                self.killed_processes.remove(process)

        # Update launch files
        for launch_file in list(self.launch_files.values()):
            launch_file.poll()
예제 #6
0
파일: ride.py 프로젝트: asmodehn/ride
    def poll(self):
        # Read the current system state from the ROS master
        publishers, subscribers, _ = map(dict, rospy.get_master().getSystemState()[2])
        node_names = set(rosnode.get_node_names())
        topic_types = rospy.get_master().getPublishedTopics('')[2]

        # Update the dictionary of topic types
        for topic, type in topic_types:
            if self.topic_types.get(topic, None) != type:
                self.updates.set_topic_type(topic, type)
                self.topic_types[topic] = type

        # Create new nodes (needed for nodes without any pub/sub topics)
        for name in node_names:
            self.node(name)

        # Link up published topics
        for topic in publishers:
            if topic in TOPIC_NAMES_TO_IGNORE:
                continue
            for name in publishers[topic]:
                if name in NODE_NAMES_TO_IGNORE:
                    continue
                node = self.node(name)
                if node is not None:
                    node.output(topic)
                node_names.add(name)

        # Link up subscribed topics
        for topic in subscribers:
            if topic in TOPIC_NAMES_TO_IGNORE:
                continue
            for name in subscribers[topic]:
                if name in NODE_NAMES_TO_IGNORE:
                    continue
                node = self.node(name)
                if node is not None:
                    node.input(topic)
                node_names.add(name)

        # Remove old node names
        killed_names = self.names_to_stop_avoiding - node_names
        self.names_to_stop_avoiding -= killed_names
        self.names_to_avoid -= killed_names

        # Remove old slots
        for name, node in self.nodes.items() + self.owned_nodes.items():
            for input in node.inputs.values():
                if input.topic not in subscribers or node.name not in subscribers[input.topic]:
                    del node.inputs[input.topic]
            for output in node.outputs.values():
                if output.topic not in publishers or node.name not in publishers[output.topic]:
                    del node.outputs[output.topic]

        # Remove old nodes
        for name in self.nodes.keys():
            if name not in node_names:
                del self.nodes[name]

        # Update owned nodes
        for name in self.owned_nodes:
            node = self.owned_nodes[name]

            # Check on the process
            if node.status == 'Starting...' and node.name in node_names:
                node.status = ''
                self.updates.update_owned_node(node)
            node.poll()

            # Remember all observed topics for when we restart this node in the future
            if node.path not in self.db.topics:
                self.db.topics[node.path] = set(), set()
            published, subscribed = self.db.topics[node.path]
            published |= set(topic for topic in node.outputs if node.outputs[topic].original_topic is None)
            subscribed |= set(topic for topic in node.inputs if node.inputs[topic].original_topic is None)

        # Save all observed topics
        self.db.save()

        # Keep polling killed child processes until they actually die
        for process in list(self.killed_processes):
            process.poll()
            if process.returncode is not None:
                self.killed_processes.remove(process)

        # Update launch files
        for launch_file in list(self.launch_files.values()):
            launch_file.poll()