コード例 #1
0
ファイル: parameter.py プロジェクト: roboearth-neu/rce
    def __init__(self, owner, name, value):
        """ Add the Parameter to the parameter server.

            @param owner:       Environment in which the node will be created.
            @type  owner:       rce.environment.Environment

            @param name:        Name of the parameter which should be added.
            @type  name:        str

            @param value:       Value of the parameter which should be added.
                                Top-level string values can contain the
                                directives $(find PKG) and/or $(env VAR).
            @type  value:       str, int, float, bool, list
        """
        self._registered = False

        ArgumentMixin.__init__(self, owner.loader)

        owner.registerParameter(self)
        self._owner = owner

        if isinstance(value, basestring):
            value = self.processArgument(value)

        self._name = name

        try:
            if rospy.has_param(name):
                log.msg("Warning: Parameter already exists.")

            rospy.set_param(name, value)
            self._registered = True
        except rospy.ROSException as e:
            raise InternalError("ROS Parameter Server reported an error: " "{0}".format(e))
コード例 #2
0
ファイル: node.py プロジェクト: dreamfrog/rce
    def __init__(self, owner, status, pkg, exe, args, name, namespace):
        """ Initialize and start the Node.
            
            @param owner:       Environment in which the node will be created.
            @type  owner:       rce.environment.Environment
            
            @param status:      Status observer which is used to inform the
                                Master of the node's status.
            @type  status:      twisted.spread.pb.RemoteReference

            @param pkg:         Name of ROS package where the node can be
                                found.
            @type  pkg:         str

            @param exe:         Name of executable (node) which should be
                                launched.
            @type  exe:         str
            
            @param args:        Additional arguments which should be used for
                                the launch. Can contain the directives
                                $(find PKG) and/or $(env VAR). Other special
                                characters such as '$' or ';' are not allowed.
            @type  args:        str
            
            @param name:        Name of the node under which the node should be
                                launched.
            @type  name:        str
            
            @param namespace:   Namespace in which the node should be started
                                in the environment.
            @type  namespace:   str
        """
        ArgumentMixin.__init__(self, owner.loader)
        
        owner.registerNode(self)
        self._owner = owner
        
        self._status = status
        self._reactor = owner.reactor
        self._call = None
        
        # Find and validate executable
        try:
            cmd = [self._loader.findNode(pkg, exe)]
        except ResourceNotFound as e:
            raise InvalidRequest('Could not identify which node to launch: '
                                 '{0}'.format(e))
        
        # Add arguments
        args = self.processArgument(args)
        
        # TODO: Is it necessary to limit the possible characters here?
#        for char in '$;':
#            if char in args:
#                raise InvalidRequest('Argument can not contain special '
#                                     "character '{0}'.".format(char))
        
        cmd += shlex.split(args)
        
        # Process name and namespace argument
        if name:
            cmd.append('__name:={0}'.format(name))
        else:
            name = exe
        
        if namespace:
            cmd.append('__ns:={0}'.format(namespace))
        
        # Create protocol instance
        uid = uuid4().hex
        out = os.path.join(self._LOG_DIR,
                           '{0}-{1}-out.log'.format(uid, name or exe))
        err = os.path.join(self._LOG_DIR,
                           '{0}-{1}-err.log'.format(uid, name or exe))
        
        self._protocol = NodeProtocol(self, out, err)
        
        # Start node
        log.msg('Start Node {0}/{1} [pkg: {2}, exe: '
                '{3}].'.format(namespace, name, pkg, exe))
        self._reactor.spawnProcess(self._protocol, cmd[0], cmd, env=os.environ)
        
        self._name = '{0}/{1}'.format(pkg, exe)
コード例 #3
0
ファイル: node.py プロジェクト: zhangaigh/rce
    def __init__(self, owner, pkg, exe, args, name, namespace):
        """ Initialize and start the Node.

            @param owner:       Environment in which the node will be created.
            @type  owner:       rce.environment.Environment

            @param pkg:         Name of ROS package where the node can be
                                found.
            @type  pkg:         str

            @param exe:         Name of executable (node) which should be
                                launched.
            @type  exe:         str

            @param args:        Additional arguments which should be used for
                                the launch. Can contain the directives
                                $(find PKG) and/or $(env VAR). Other special
                                characters such as '$' or ';' are not allowed.
            @type  args:        str

            @param name:        Name of the node under which the node should be
                                launched.
            @type  name:        str

            @param namespace:   Namespace in which the node should be started
                                in the environment.
            @type  namespace:   str

            @raise:             rce.util.loader.ResourceNotFound
        """
        ArgumentMixin.__init__(self, owner.loader)

        owner.registerNode(self)
        self._owner = owner

        self._reactor = owner.reactor
        self._call = None
        self._protocol = None

        # Find and validate executable
        cmd = [self._loader.findNode(pkg, exe)]  # raises ResourceNotFound

        # Add arguments
        args = self.processArgument(args)

        # TODO: Is it necessary to limit the possible characters here?
        #        for char in '$;':
        #            if char in args:
        #                raise ValueError('Argument can not contain special '
        #                                 "character '{0}'.".format(char))

        cmd += shlex.split(args)

        # Process name and namespace argument
        if name:
            cmd.append('__name:={0}'.format(name))

        if namespace:
            cmd.append('__ns:={0}'.format(namespace))

        # Create protocol instance
        uid = uuid4().hex
        out = os.path.join(self._LOG_DIR,
                           '{0}-{1}-out.log'.format(uid, name or exe))
        err = os.path.join(self._LOG_DIR,
                           '{0}-{1}-err.log'.format(uid, name or exe))

        self._protocol = NodeProtocol(self, out, err)

        # Start node
        log.msg('Start Node {0}/{1} [pkg: {2}, exe: '
                '{3}].'.format(namespace, name or exe, pkg, exe))
        self._reactor.spawnProcess(self._protocol, cmd[0], cmd, env=os.environ)

        self._name = '{0}/{1}'.format(pkg, exe)