Пример #1
0
 def status(self):
     """
     Get led status
     """        
     actual_levels = self.pcomm.call_device('get_fid_status')
     if len(actual_levels) != len(self.controller['devices']):
         raise_error('status: petal controller returns incorrect number of items', level='ERROR')
     state = []
     level = []
     for i in range(len(self.controller['devices'])):
         id = self.controller['devices'][i]
         if str(id) in actual_levels:
             value = actual_levels[str(id)]
         else:
             self.error('get_fid_status does not return can id %r' % id)
             continue
         if(-1==value):
             state.append('unknown')
             level.append(0.0)
         elif(0==value):    
             state.append('off')
             level.append(0.0)
         else:
             state.append('on')
             try:
                 v = float(value)
             except Exception as e:
                 raise_error('status: Exception converting actual level: %s' % str(e))
             level.append(float(int(v/float(self.Relative_Levels[i]))))
         self.controller['level'] = level
         self.controller['state'] = state
     return self.controller
Пример #2
0
 def level(self, value, set_default = False):
     """
     Set the LED value
     """
     on_flag = False
     if isinstance(value,list):
             for value_i in value:
                     if value_i > 0.00001:
                             on_flag = True
     else:
             if value > 0.00001:
                     on_flag = True
     if on_flag is False:
         self.controller['state'] = ['off' for i in range(len(self.CanIDs))]
         self.controller['level'] = [0.0  for i in range(len(self.CanIDs))]
     else:
         self.controller['state'] = ['on'  for i in range(len(self.CanIDs))]
         if isinstance(value, list):
             if len(value) == len(self.CanIDs):
                 self.controller['level'] = value
             else:
                 print(len(value),len(self.CanIDs))
                 raise_error('Incorrect list length', level='ERROR')
         else:
             self.controller['level'] = [value  for i in range(len(self.CanIDs))]
         if set_default == True:
             self.controller['default'] = self.controller['level']
Пример #3
0
 def set_fid_off(self):
     if not self.fiducials:
         raise_error('no fiducials selected',
                     level='ERROR',
                     function='set_fiducials_off')
     self.fiducials.turn_off()
     return 'SUCCESS'
Пример #4
0
 def set_fid_on(self):
     if not self.fiducials:
         raise_error('no fiducials selected',
                     level='ERROR',
                     function='set_fiducials_on')
     print(len(self.device_options['Default_Duty']))
     self.fiducials.turn_on(level=self.device_options['Default_Duty'])
     return 'SUCCESS'
Пример #5
0
 def duty_cycle(self, level, set_default=False):
     if not self.fiducials:
         raise_error('no fiducials selected',
                     level='ERROR',
                     function='duty_cycle')
     if not isinstance(level, list):
         level = [level for i in range(len(self.CanIDs))]
     self.fiducials.level(level, set_default=set_default)
     return 'SUCCESS'
Пример #6
0
 def get_fid_status(self):
     if not self.fiducials:
         raise_error('no fiducials selected',
                     level='ERROR',
                     function='get_fid_status')
     status = self.fiducials.status()
     self.info("fiducials: device %s, state %s, level %s, default_duty %s" %
               (status['devices'], status['state'], status['level'],
                status['default']))
     return 'SUCCESS'
Пример #7
0
 def level(self, percent_duty, set_default = False):
     """
     Set the LED value
     """
     if not isinstance(percent_duty, list):
         percent_duty = [percent_duty for i in range(len(self.CanIDs))]
     if set_default == True:
         self.Default_Duty = percent_duty
         self.controller['default'] = percent_duty
     try:
         return self.pcomm.call_device('set_fiducials', self.CanBus, self.CanIDs, percent_duty)
     except Exception as e:
         raise_error('Exception setting level: %s'% str(e), level='ERROR', function= 'level')
Пример #8
0
    def __init__(self, device, controller_type = 'simulator', service = 'PetalControl', device_options = {}):
        """
        Initialize fiducials class
        device is the DOS device name of the BBB controller
        service is the name of the DOS advertiser service used
        device_options configure the fipos controller (CanBus, CanIDs, Relative_Levels, Default_Duty)
        """
        # Defaults
        CanIDs = [784, 1475]
        CanBus = ['can0' for i in range(len(CanIDs))]
        RelLevel = [1.0 for i in range(len(CanIDs))] 
        Duty = [5.0 for i in range(len(CanIDs))] 

        # Log functions
        for level in ['msg', 'debug', 'info', 'warn', 'error']:
            if hasattr(Log, level):
                setattr(self,level, getattr(Log, level))

        # default settings
        self.hardware = 'fiposled' if str(controller_type).lower() in ['hardware', 'fiposled', 'bbb'] else str(controller_type).lower()
        self.petal_controller = device
        config = {'service' : service,
                  'CanBus' : device_options.get('CanBus', CanBus),
                  'CanIDs' : device_options.get('CanIDs', CanIDs),
                  'Relative_Levels' : device_options.get('Relative_Levels', RelLevel),
                  'Default_Duty' : device_options.get('Default_Duty', Duty),
                  'controller': device_options.get('controller','')}

        self.info('fiducials: device %s, controller %s, Config: %r' % (self.petal_controller, self.hardware, config))
        
        # Connect to the controller
        print('89753 config')
        print(config)
        print('89754 config')
        try:
            if str(self.hardware).lower() == 'simulator':
                self.controller = SimulatorLED(self.petal_controller,config)
            elif str(self.hardware).lower() == 'fiposled':
                self.controller = FiposLED(self.petal_controller, config)
            else:
                raise_error('fiducials: Invalid controller_type', level='ERROR', function='init')
        except Exception as e:
            raise_error('fiducials: Exception connecting to LED controller: %s' % str(e), level='ERROR', function='init')

        # Turn fiducials off
        self.info('fiducials: Turning fiducials off')
        self.controller.turn_off()
        
        # get status
        self.info('fiducials: device status: %r' % self.controller.status())
Пример #9
0
    def __init__(self, device, config):
        # Log functions
        for level in ['msg', 'debug', 'info', 'warn', 'error']:
            if hasattr(Log, level):
                setattr(self,level, getattr(Log, level))

        self.petal_controller = device
        self.pcomm = None
        self.CanBus = config['CanBus']
        self.CanIDs = config['CanIDs']
        self.Relative_Levels = config['Relative_Levels']
        self.Default_Duty = config['Default_Duty']

        try:
            self.pcomm=FiposComm(device,controller = config["controller"])
        except Exception as e:
            raise_error('FiposComm: Cannot connect to device %s' % self.petal_controller)
        self.controller = {'devices' : self.CanIDs, 'state' : ['off' for i in range(len(self.CanIDs))], 
                           'level' : [0.0 for i in range(len(self.CanIDs))], 'default' : self.Default_Duty}
Пример #10
0
 def level(self, level, set_default = False):
     if not self.controller:
         raise_error('No LED controller connected', level='WARN', function='level')
     self.info('level: setting level to %r (set_default = %r)' % (level, set_default))
     self.controller.level(level, set_default = set_default)
Пример #11
0
 def turn_off(self):
     if not self.controller:
         raise_error('No LED controller connected', level='WARN', function='turn_off')
     self.info('turn_off: turning fiducials off')
     self.controller.turn_off()
Пример #12
0
 def turn_on(self, level = None):
     if not self.controller:
         raise_error('No LED controller connected', level='WARN', function='turn_on')
     self.info('turn_on: turning fiducials on')
     self.controller.turn_on(level = level)
Пример #13
0
 def status(self):
     if not self.controller:
         raise_error('No LED controller connected', level='WARN', function = 'status')
     return self.controller.status()
Пример #14
0
    def __init__(self, device, **options):
        """
        Find the petal controller (device) and connect to it
        Options include the fipos settings for LED control
        """
        # Log functions
        for level in ['msg', 'debug', 'info', 'warn', 'error']:
            if hasattr(Log, level):
                setattr(self,level, getattr(Log, level))

        self.petal_controller = device
        # Setup Seeker
        self.seeker_thread = None
        self.repeat = threading.Event()
        self.repeat.clear()
        self.found_controller = threading.Event()
        self.found_controller.clear()
        self.stype = '-dos-'
        self.service = options.get('service', 'PetalControl')
        self.device = {}
        delay = options.get('delay', 15.0)
        # Did we get controller information or should we seek?
        print('89755')
        print(options)
        print('89756')
        print(options['controller'])
        if 'controller' in options and isinstance(options['controller'], dict):
            print('89757')
            self.device = {'connected2instance': 'EXTERN',
                           'device_instance': '',
                           'last_updated': '',
                           'node': options['controller'].get('ip', '140.254.79.198'),
                           'service': self.service,
                           'stype': self.stype,
                           'uid' : '81df0e9a-9409-11e8-b17c-b0d5cc1ef486',
                           }
            print('89757a')
            print('897575'+str(options['controller']))
            if 'port' in options['controller']:
                print('89758')
                self.device['pyro_uri'] = 'PYRO:%s@%s:%s' % (self.petal_controller,
                                                             str(self.device['node']),
                                                             str(options['controller']['port']))
                print(self.device['pyro_uri'])
        else:
            # Setup DOS Seeker
            self.seeker = Seeker(self.stype, self.service, found_callback = self._found_dev)
            # Start Seeker thread
            self.repeat.set()
            self.delay = 0.5
            self.seeker_thread = threading.Thread(target=self._repeat_seeker)
            self.seeker_thread.setDaemon(True)
            self.seeker_thread.start()
            self.info('Seeker thread is now running. Delay %s' % str(self.delay))
            # wait briefly for seeker to find all devices
            self.info('Waiting for device %s' % self.petal_controller)
            self.found_controller.wait(timeout = delay + 1.0)
            self.delay = 10.0

        # Make sure we have a device to connect to
        start = time.time()
        while self.device == {} and delay<(time.time() - start):
            self.device['proxy'] = Pyro4.Proxy(self.device['pyro_uri'])
            self.info('Now connected to device %s' % self.device)
            break
            
        if self.device == {}:
            raise_error('fipos_comm: Timeout connecting to controller %s' % (self.petal_controller), level='ERROR', function='init')