Exemplo n.º 1
0
    def getRobot(robotName=None, spawn=True):
        """ Retrieves the named robot type from the database and constructs the appropriate class """
        """ if robotName is None or Empty, acts like getCurrentRobot() """
        if robotName == None or robotName == '':
            return Factory.getCurrentRobot()
        
        print "Building class for robot named: %s" % robotName
        # care-o-bot shortened to make 'in' easier to handle (only check first 9 characters)
        rosRobots = ['care-o-bo', 'sunflower']
        if robotName.lower()[:9] in rosRobots:
            if robotName.lower().startswith('care-o-bot'):
                if robot_config.has_key(robotName) and robot_config[robotName].has_key('hostname'):
                    rosMaster = 'http://%s:11311'
                else:
                    cobVersion = robotName[11:].replace('.', '-')
                    rosMaster = "http://cob%s-pc1:11311" % cobVersion
                imports = ['from careobot import CareOBot']
                args = (robotName, rosMaster, )
                kwargs = {}
                className = 'CareOBot'
            elif robotName.lower().startswith('sunflower'):
                if robot_config.has_key(robotName) and robot_config[robotName].has_key('hostname'):
                    rosMaster = 'http://%s:11311'
                else:
                    cobVersion = robotName[10:].replace('.', '-')
                    rosMaster = "http://sunflower%s-pc1:11311" % cobVersion
                imports = ['from sunflower import Sunflower']
                args = (robotName, rosMaster, )
                kwargs = {}
                className = 'Sunflower'

            # Set the LD_LIBRARY_PATH before forking
            from rosHelper import ROS
            rosENV = ROS._parseBashEnviron()
            rosLD = rosENV.get('LD_LIBRARY_PATH', '')
            curLD = os.environ.get('LD_LIBRARY_PATH')
            os.environ['LD_LIBRARY_PATH'] = curLD + ',' + rosLD
            
            if spawn:
                # Create the wrapper (runs the named class in a sub-process)
                from subProcessWrapper import SubProcessWrapper
                robot = SubProcessWrapper(imports, className, *args, **kwargs)
            
                # Now revert LD_LIBRARY_PATH for this process
                os.environ['LD_LIBRARY_PATH'] = curLD
            else:
                for import_ in imports:
                    exec(import_, globals())
                robot = globals()[className](*args, **kwargs)
        elif robotName.lower().startswith('dummy'):
            import dummy
            robot = dummy.DummyRobot(robotName)
        else:
            print >> sys.stderr, "Unknown robot %s" % robotName
            return None

        print "Finished building class %s" % className
        return robot
Exemplo n.º 2
0
 def __init__(self, name, rosMaster):
     from rosHelper import ROS
     ROS.configureROS(rosMaster=rosMaster)
     print rosMaster
     super(Sunflower, self).__init__(name, ActionLib, 'sf_controller', '')
Exemplo n.º 3
0
 def __init__(self, name='Sunflower'):
     from rosHelper import ROS
     ROS.configureROS(version='electric', rosMaster='http://sf1-1-pc1:11311', overlayPath='/home/nathan/git/sunflower/')
     super(Sunflower, self).__init__(name, ActionLib(), 'sf_controller', '')
Exemplo n.º 4
0
    def __init__(self, name, rosMaster):
        from rosHelper import ROS

        ROS.configureROS(rosMaster=rosMaster)
        print rosMaster
        super(Sunflower, self).__init__(name, ActionLib, "sf_controller", "")