Esempio n. 1
0
 def loadBrain(self, file):
     """Finds and loads the brain file."""
     if self.robot is 0:
         raise 'No robot loaded when loading brain'
     if file[-3:] != '.py':
         file = file + '.py'
     if system.file_exists(file):
         try:
             self.brain.window.destroy()
         except:
             pass
         try:
             self.brain.destroy()
         except:
             pass
         self.brain = system.loadINIT(file, self)
         self.brainfile = file
     elif (os.getenv('PYROBOT') != None and
           system.file_exists(os.getenv('PYROBOT') + \
                              '/plugins/brains/' + file)):
         try:
             self.brain.window.destroy()
         except:
             pass
         try:
             self.brain.destroy()
         except:
             pass
         self.brain = system.loadINIT(os.getenv('PYROBOT') + \
                                      '/plugins/brains/' + file, self)
         self.brainfile = os.getenv('PYROBOT') + '/plugins/brains/' + file
     else:
         raise "File not found: '%s'; is PYROBOT set?" % file
Esempio n. 2
0
 def loadBrain(self,file):
    """Finds and loads the brain file."""
    if self.robot is 0:
       raise 'No robot loaded when loading brain'
    if file[-3:] != '.py':
       file = file + '.py'
    if system.file_exists(file):
       try:
          self.brain.window.destroy()
       except:
          pass
       try:
          self.brain.destroy()
       except:
          pass
       self.brain = system.loadINIT(file, self)
       self.brainfile = file
    elif (os.getenv('PYROBOT') != None and
          system.file_exists(os.getenv('PYROBOT') + \
                             '/plugins/brains/' + file)): 
       try:
          self.brain.window.destroy()
       except:
          pass
       try:
          self.brain.destroy()
       except:
          pass
       self.brain = system.loadINIT(os.getenv('PYROBOT') + \
                                    '/plugins/brains/' + file, self)
       self.brainfile = os.getenv('PYROBOT') + '/plugins/brains/' + file
    else:
       raise "File not found: '%s'; is PYROBOT set?" % file
Esempio n. 3
0
 def loadBrain(self, file):
     """Finds and loads the brain file."""
     if self.robot is 0:
         raise Except('No robot loaded when loading brain')
     if file[-3:] != '.py':
         file = file + '.py'
     if system.file_exists(file):
         try:
             self.brain.window.destroy()
         except:
             pass
         try:
             self.brain.destroy()
         except:
             pass
         self.brain = system.loadINIT(file, self)
         self.brainfile = file
     elif (pyrobotdir() != None and
           system.file_exists(pyrobotdir() + \
                              '/plugins/brains/' + file)):
         try:
             self.brain.window.destroy()
         except:
             pass
         try:
             self.brain.destroy()
         except:
             pass
         self.brain = system.loadINIT(pyrobotdir() + \
                                      '/plugins/brains/' + file, self)
         self.brainfile = pyrobotdir() + '/plugins/brains/' + file
     else:
         raise Exception("Pyrobot File not found: '%s'" % file)
Esempio n. 4
0
 def loadBrain(self,file):
    """Finds and loads the brain file."""
    if self.robot is 0:
       raise Except('No robot loaded when loading brain')
    if file[-3:] != '.py':
       file = file + '.py'
    if system.file_exists(file):
       try:
          self.brain.window.destroy()
       except:
          pass
       try:
          self.brain.destroy()
       except:
          pass
       self.brain = system.loadINIT(file, self)
       self.brainfile = file
    elif (pyrobotdir() != None and
          system.file_exists(pyrobotdir() + \
                             '/plugins/brains/' + file)): 
       try:
          self.brain.window.destroy()
       except:
          pass
       try:
          self.brain.destroy()
       except:
          pass
       self.brain = system.loadINIT(pyrobotdir() + \
                                    '/plugins/brains/' + file, self)
       self.brainfile = pyrobotdir() + '/plugins/brains/' + file
    else:
       raise Exception("Pyrobot File not found: '%s'" % file)
Esempio n. 5
0
    def loadMapFile(self, file):
        import os

        if file[-3:] != ".py":
            file = file + ".py"
        if system.file_exists(file):
            grid = system.loadINIT(file)
        elif system.file_exists(pyrobotdir() + "/plugins/maps/" + file):
            grid = system.loadINIT(pyrobotdir() + "/plugins/plots/" + file)
        else:
            raise "Map file not found: " + file
        self.setGrid(grid)
Esempio n. 6
0
 def startDevices(self, item, override=FALSE, **args):
     print("pyrobot/robot/__init.py__ startDevices")  #error occured
     """Load devices can take a dict, list, builtin name, or filename """
     # Item can be: dict, list, or string. string can be name or filename
     if type(item) == type({}):
         # this is the only one that does anything
         retval = []
         for dev in list(item.keys()):
             deviceNumber = self._getNextDeviceNumber(dev)
             print("Loading device %s[%d]..." % (dev, deviceNumber))
             self.__dict__[dev][deviceNumber] = item[dev]
             item[dev].setTitle(dev + "[" + str(deviceNumber) + "]")
             item[dev].index = deviceNumber
             retval.append(item[dev])  # return object
         return retval
     elif item in self.builtinDevices:  # built-in name
         # deviceBuiltin returns dictionary
         print("pyrobot/robot/__init.py__ items")  #error occured
         print("pyrobot/robot/__init.py__ builtinDevice")  #error occured
         print(self.builtinDevices)  #error occured
         print(type(self.builtinDevices))  #error occured
         print("pyrobot/robot/__init.py__ item %s" % item)  #error occured
         #deviceList = self.startDeviceBuiltin(item) #error occured
         deviceList = self.startDeviceBuiltin(item)  #error occured
         print(type(deviceList))
         if type(deviceList) == type(
                 "device"):  # loaded it here, from the robot
             return [deviceList]
         else:
             return self.startDevices(deviceList, **args)  # dict of objs
     elif isinstance(item, (type((1, )), type([
             1,
     ]))):
         retval = []
         for i in item:
             retval.append(self.startDevice(i, **args))
         return retval
     else:  # from a file
         file = item
         if file == None:
             return []
         if len(file) > 3 and file[-3:] != '.py':
             file = file + '.py'
         if system.file_exists(file):
             return self.startDevices(system.loadINIT(file, self), **args)
         elif system.file_exists(os.getenv('PYROBOT') + \
                                 '/plugins/devices/' + file):
             return self.startDevices( system.loadINIT(os.getenv('PYROBOT') + \
                                                '/plugins/devices/'+ \
                                                file, self), **args)
         else:
             print('Device file not found: ' + file)
             return []
Esempio n. 7
0
 def loadMapFile(self, file):
     import os
     if file[-3:] != '.py':
         file = file + '.py'
     if system.file_exists(file):
         grid = system.loadINIT(file)
     elif system.file_exists(os.getenv('PYROBOT') + \
                             '/plugins/maps/' + file): 
         grid = system.loadINIT(os.getenv('PYROBOT') + \
                                '/plugins/plots/' + file)
     else:
         raise 'Map file not found: ' + file
     self.setGrid(grid)
Esempio n. 8
0
 def loadMapFile(self, file):
     import os
     if file[-3:] != '.py':
         file = file + '.py'
     if system.file_exists(file):
         grid = system.loadINIT(file)
     elif system.file_exists(os.getenv('PYROBOT') + \
                             '/plugins/maps/' + file):
         grid = system.loadINIT(os.getenv('PYROBOT') + \
                                '/plugins/plots/' + file)
     else:
         raise 'Map file not found: ' + file
     self.setGrid(grid)
Esempio n. 9
0
 def loadRobot(self, file):
     """Finds and loads the robot."""
     if file[-3:] != '.py':
         file = file + '.py'
     if system.file_exists(file):
         self.robot = system.loadINIT(file)
         self.robotfile = file
     elif (os.getenv('PYROBOT') != None and
           system.file_exists(os.getenv('PYROBOT') + \
                              '/plugins/robots/' + file)):
         self.robot = system.loadINIT(os.getenv('PYROBOT') + \
                                      '/plugins/robots/' + file)
         self.robotfile = os.getenv('PYROBOT') + '/plugins/robots/' + file
     else:
         raise "Robot file not found: '%s'; is PYROBOT set?" % file
Esempio n. 10
0
 def loadRobot(self, file):
     """Finds and loads the robot."""
     if file[-3:] != '.py':
         file = file + '.py'
     if system.file_exists(file):
         self.robot = system.loadINIT(file)
         self.robotfile = file
     elif (pyrobotdir() != None and
           system.file_exists(pyrobotdir() + \
                              '/plugins/robots/' + file)):
         self.robot = system.loadINIT(pyrobotdir() + \
                                      '/plugins/robots/' + file)
         self.robotfile = pyrobotdir() + '/plugins/robots/' + file
     else:
         raise Exception("Pyrobot Robot file not found: '%s'" % file)
Esempio n. 11
0
 def loadRobot(self,file):
    """Finds and loads the robot."""
    if file[-3:] != '.py':
       file = file + '.py'
    if system.file_exists(file):
       self.robot = system.loadINIT(file)
       self.robotfile = file
    elif (pyrobotdir() != None and
          system.file_exists(pyrobotdir() + \
                             '/plugins/robots/' + file)): 
       self.robot = system.loadINIT(pyrobotdir() + \
                                    '/plugins/robots/' + file)
       self.robotfile = pyrobotdir() + '/plugins/robots/' + file
    else:
       raise Exception("Pyrobot Robot file not found: '%s'" % file)
Esempio n. 12
0
 def loadRobot(self,file):
    """Finds and loads the robot."""
    if file[-3:] != '.py':
       file = file + '.py'
    if system.file_exists(file):
       self.robot = system.loadINIT(file)
       self.robotfile = file
    elif (os.getenv('PYROBOT') != None and
          system.file_exists(os.getenv('PYROBOT') + \
                             '/plugins/robots/' + file)): 
       self.robot = system.loadINIT(os.getenv('PYROBOT') + \
                                    '/plugins/robots/' + file)
       self.robotfile = os.getenv('PYROBOT') + '/plugins/robots/' + file
    else:
       raise "Robot file not found: '%s'; is PYROBOT set?" % file
Esempio n. 13
0
 def startDevices(self, item, override = False, **args):
     """Load devices can take a dict, list, builtin name, or filename """
     # Item can be: dict, list, or string. string can be name or filename
     if type(item) == type({}):
         # this is the only one that does anything
         retval = []
         for dev in item.keys():
             deviceNumber = self._getNextDeviceNumber(dev)
             print "Loading device %s[%d]..." % (dev, deviceNumber)
             self.__dict__[dev][deviceNumber] = item[dev]
             item[dev].setTitle( dev + "[" + str(deviceNumber) + "]" )
             item[dev].index = deviceNumber
             retval.append(item[dev]) # return object
         return retval
     elif item in self.builtinDevices: # built-in name
         # deviceBuiltin returns dictionary
         deviceList = self.startDeviceBuiltin(item)
         if type(deviceList) == type("device"): # loaded it here, from the robot
             return [ deviceList ]
         else:
             return self.startDevices( deviceList, **args ) # dict of objs
     elif isinstance(item, (type((1,)), type([1,]))):
         retval = []
         for i in item:
             retval.append( self.startDevice(i, **args) )
         return retval
     else: # from a file
         file = item
         if file == None:
             return []
         if len(file) > 3 and file[-3:] != '.py':
             file = file + '.py'
         if system.file_exists(file):
             return self.startDevices( system.loadINIT(file, self), **args )
         elif system.file_exists(pyrobotdir() + \
                                 '/plugins/devices/' + file): 
             return self.startDevices( system.loadINIT(pyrobotdir() + \
                                                '/plugins/devices/'+ \
                                                file, self), **args)
         else:
             print 'Device file not found: ' + file
             return []
Esempio n. 14
0
 def reset(self):
     """Shuts down the brain, and reloads it."""
     self.pleaseStop()
     time.sleep(.1)  # give it time to stop
     if self.brain is not 0:
         self.brain.pleaseQuit()
         time.sleep(.1)  # give it time to stop
         #self.robot = system.loadINIT(self.robotfile, redo = 1)
         try:
             self.brain.window.destroy()
         except:
             pass
         try:
             self.brain.destroy()
         except:
             print("I was unable to properly destroy the brain")
         self.brain = system.loadINIT(self.brainfile, self, 1)
Esempio n. 15
0
 def reset(self):
    """Shuts down the brain, and reloads it."""
    self.pleaseStop()
    time.sleep(.1) # give it time to stop
    if self.brain is not 0:
       self.brain.pleaseQuit()
       time.sleep(.1) # give it time to stop
       #self.robot = system.loadINIT(self.robotfile, redo = 1)
       try:
          self.brain.window.destroy()
       except:
          pass
       try:
          self.brain.destroy()
       except:
          print "I was unable to properly destroy the brain"
       self.brain = system.loadINIT(self.brainfile, self, 1)