Example #1
0
    def _launch_master(self):
        """
        Launches master if requested. 
        @return: True if a master was launched, False if a master was
        already running.
        @rtype: bool
        @raise RLException: if master launch fails
        """
        m = self.config.master
        is_running = m.is_running()

        if self.is_core and is_running:
            raise RLException(
                "roscore cannot run as another roscore/master is already running. \nPlease kill other roscore/master processes before relaunching.\nThe ROS_MASTER_URI is %s"
                % (m.uri))

        if not is_running:
            validate_master_launch(m, self.is_core, self.is_rostest)

            printlog("auto-starting new master")
            p = create_master_process(self.run_id, m.type, get_ros_root(),
                                      m.get_port(), self.num_workers,
                                      self.timeout)
            self.pm.register_core_proc(p)
            success = p.start()
            if not success:
                raise RLException("ERROR: unable to auto-start master process")
            timeout_t = time.time() + _TIMEOUT_MASTER_START
            while not m.is_running() and time.time() < timeout_t:
                time.sleep(0.1)

        if not m.is_running():
            raise RLException("ERROR: could not contact master [%s]" % m.uri)

        printlog_bold("ROS_MASTER_URI=%s" % m.uri)
        # TODO: although this dependency doesn't cause anything bad,
        # it's still odd for launch to know about console stuff. This
        # really should be an event.
        update_terminal_name(m.uri)

        # Param Server config params
        param_server = m.get()

        # #773: unique run ID
        self._check_and_set_run_id(param_server, self.run_id)

        if self.server_uri:
            # store parent XML-RPC URI on param server
            # - param name is the /roslaunch/hostname:port so that multiple roslaunches can store at once
            hostname, port = rosgraph.network.parse_http_host_and_port(
                self.server_uri)
            hostname = _hostname_to_rosname(hostname)
            self.logger.info("setting /roslaunch/uris/%s__%s' to %s" %
                             (hostname, port, self.server_uri))
            param_server.setParam(_ID,
                                  '/roslaunch/uris/%s__%s' % (hostname, port),
                                  self.server_uri)

        return not is_running
Example #2
0
    def _launch_master(self):
        """
        Launches master if requested. 
        @return: True if a master was launched, False if a master was
        already running.
        @rtype: bool
        @raise RLException: if master launch fails
        """
        m = self.config.master
        is_running = m.is_running()

        if self.is_core and is_running:
            raise RLException("roscore cannot run as another roscore/master is already running. \nPlease kill other roscore/master processes before relaunching.\nThe ROS_MASTER_URI is %s"%(m.uri))

        if not is_running:
            validate_master_launch(m, self.is_core, self.is_rostest)

            printlog("auto-starting new master")
            p = create_master_process(self.run_id, m.type, get_ros_root(), m.get_port(), self.num_workers, self.timeout)
            self.pm.register_core_proc(p)
            success = p.start()
            if not success:
                raise RLException("ERROR: unable to auto-start master process")
            timeout_t = time.time() + _TIMEOUT_MASTER_START
            while not m.is_running() and time.time() < timeout_t:
                time.sleep(0.1)

        if not m.is_running():
            raise RLException("ERROR: could not contact master [%s]"%m.uri)
        
        printlog_bold("ROS_MASTER_URI=%s"%m.uri)
        # TODO: although this dependency doesn't cause anything bad,
        # it's still odd for launch to know about console stuff. This
        # really should be an event.
        update_terminal_name(m.uri)

        # Param Server config params
        param_server = m.get()
        
        # #773: unique run ID
        self._check_and_set_run_id(param_server, self.run_id)

        if self.server_uri:
            # store parent XML-RPC URI on param server
            # - param name is the /roslaunch/hostname:port so that multiple roslaunches can store at once
            hostname, port = rosgraph.network.parse_http_host_and_port(self.server_uri)
            hostname = _hostname_to_rosname(hostname)
            self.logger.info("setting /roslaunch/uris/%s__%s' to %s"%(hostname, port, self.server_uri))
            param_server.setParam(_ID, '/roslaunch/uris/%s__%s'%(hostname, port),self.server_uri)

        return not is_running
Example #3
0
    def _launch_master(self):
        """
        Launches master if requested. Must be run after L{_setup_master()}.
        @raise RLException: if master launch fails
        """
        m = self.config.master
        auto = m.auto
        is_running = m.is_running()

        if self.is_core and is_running:
            raise RLException(
                "roscore cannot run as another roscore/master is already running. \nPlease kill other roscore/master processes before relaunching.\nThe ROS_MASTER_URI is %s"
                % (m.uri))

        self.logger.debug("launch_master [%s]", auto)
        if auto in [m.AUTO_START, m.AUTO_RESTART] and not is_running:
            if auto == m.AUTO_START:
                printlog(
                    "starting new master (master configured for auto start)")
            elif auto == m.AUTO_RESTART:
                printlog(
                    "starting new master (master configured for auto restart)")

            _, urlport = roslib.network.parse_http_host_and_port(m.uri)
            if urlport <= 0:
                raise RLException(
                    "ERROR: master URI is not a valid XML-RPC URI. Value is [%s]"
                    % m.uri)

            p = create_master_process(self.run_id, m.type, get_ros_root(),
                                      urlport, m.log_output)
            self.pm.register_core_proc(p)
            success = p.start()
            if not success:
                raise RLException("ERROR: unable to auto-start master process")
            timeout_t = time.time() + _TIMEOUT_MASTER_START
            while not m.is_running() and time.time() < timeout_t:
                time.sleep(0.1)

        if not m.is_running():
            raise RLException("ERROR: could not contact master [%s]" % m.uri)

        printlog_bold("ROS_MASTER_URI=%s" % m.uri)
        # TODO: although this dependency doesn't cause anything bad,
        # it's still odd for launch to know about console stuff. This
        # really should be an event.
        update_terminal_name(m.uri)

        # Param Server config params
        param_server = m.get()

        # #773: unique run ID
        self._check_and_set_run_id(param_server, self.run_id)

        if self.server_uri:
            # store parent XML-RPC URI on param server
            # - param name is the /roslaunch/hostname:port so that multiple roslaunches can store at once
            hostname, port = roslib.network.parse_http_host_and_port(
                self.server_uri)
            hostname = _hostname_to_rosname(hostname)
            self.logger.info("setting /roslaunch/uris/%s__%s' to %s" %
                             (hostname, port, self.server_uri))
            param_server.setParam(_ID,
                                  '/roslaunch/uris/%s__%s' % (hostname, port),
                                  self.server_uri)