camera_setup_lib.py
Go to the documentation of this file.
00001 import _camera_setup_lib
00002 
00003 def _swig_repr(self):
00004     try: strthis = "proxy of " + self.this.__repr__()
00005     except: strthis = ""
00006     return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
00007 
00008 import types
00009 try:
00010     _object = types.ObjectType
00011     _newclass = 1
00012 except AttributeError:
00013     class _object : pass
00014     _newclass = 0
00015 del types
00016 
00017 
00018 init_bus1394   = _camera_setup_lib.init_bus1394
00019 getCameraUID   = _camera_setup_lib.getCameraUID
00020 endCameraSetup = _camera_setup_lib.endCameraSetup
00021 setFrameRate   = _camera_setup_lib.setFrameRate
00022 getRegister    = _camera_setup_lib.getRegister
00023 setRegister    = _camera_setup_lib.setRegister
00024 
00025 #All hex setting to the cameras confined to this code
00026 brightness_register_dict = { 'brightness':   0x800,  'exposure': 0x804, 
00027                              'shutter_time': 0x81c,  'gain':     0x820,
00028                              'white_balance': 0x80c, 'gamma': 0x818}
00029 
00030 register_dict            = { 'frame_rate':    0x600, 'trigger_mode':  0x830, 
00031                              'trigger_delay': 0x834, 'pio_direction': 0x11f8, 
00032                              'strobe_0_cnt':  0x1500 }
00033 
00034 fps_dict                 = { 60:0xa0000000,
00035                              30:0x80000000,
00036 #                             20:0x70000000, 20 does not seem to be an
00037 #                             option
00038                              15:0x60000000,
00039                              7.5:0x40000000,
00040                              3.75:0x20000000,
00041                              1.875:0x10000000 }
00042 
00043 # Dictionary from registers to fps.  It's named sps because sps is fps backawards ;)
00044 spf_dict                 = { '0xa':60,
00045                              '0x8':30,
00046                              '0x6':15,
00047                              '0x4':7.5 }
00048 
00049 
00050 register_dict.update( brightness_register_dict )
00051 
00052 def get_registers( index ):
00053     """
00054     index would be the .device property of a Camera object
00055     
00056     [register function, register value]"""
00057     return [(key,getRegister( index, register_dict[key])) for key in register_dict.keys()]
00058 
00059 def get_frame_rate( index ):
00060     """
00061     Get the frame rate
00062     """
00063     val = (0xe0000000 & getRegister( index, register_dict['frame_rate'])) >> 7*4
00064     return spf_dict[hex(int(val))]    
00065 
00066 
00067 def set_frame_rate( index, rate ):
00068     frame_rate = fps_dict[rate]
00069     setRegister( index, register_dict['frame_rate'], frame_rate)
00070 
00071 
00072 def set_stereo_slaving( master, slave ):
00073     '''
00074     master and slave would be the .device property of Camera objects
00075     
00076     This function assumes that the right camera is slave off of the left'''
00077     setRegister( master, register_dict['pio_direction'], 0x80000000)
00078     setRegister( slave, register_dict['strobe_0_cnt'], 0x82000000)
00079 
00080     setRegister( slave, register_dict['trigger_mode'], 0x83110000 )
00081     setRegister( master, register_dict['trigger_mode'], 0x80100000 )
00082 
00083     for key in brightness_register_dict.keys():
00084         rdval = getRegister( master, register_dict[key])
00085         setRegister( slave, register_dict[key] ,rdval)
00086 
00087 
00088 def get_brightness_settings( index ):
00089     """
00090     index would be the .device property of a Camera object
00091     
00092     [register function, register value]"""
00093     return [(key, 0xfff & getRegister( index, brightness_register_dict[key])) for key in brightness_register_dict.keys()]
00094 
00095 
00096 def set_auto( index ):
00097     """Set a particular camera to automatically ajdust brightness and exposure"""
00098     setRegister( index, register_dict['brightness'], 0x83000000)
00099     setRegister( index, register_dict['exposure'], 0x83000000)
00100     setRegister( index, register_dict['shutter_time'], 0x8300000e)
00101     setRegister( index, register_dict['gain'], 0x8300000f)
00102     print 'set auto being called'
00103 
00104 
00105 def get_gamma(index):
00106     return getRegister(index, brightness_register_dict['gamma'])
00107 
00108 def set_gamma(index,gamma):
00109     ''' gamma: 0 or 1
00110     '''
00111     setRegister(index, brightness_register_dict['gamma'], 0x82000000+gamma)
00112 
00113 def get_whitebalance(index):
00114     return getRegister(index, brightness_register_dict['white_balance'])
00115 
00116 def set_whitebalance(index,r_val,b_val):
00117     setRegister(index, brightness_register_dict['white_balance'], 0x82000000+r_val+b_val*4096)
00118 
00119 def set_brightness( index, brightness=None, exposure=None, shutter_time=None, gain=None ):
00120     """If brightness is not specified auto mode is used for all settings. If shutter_time
00121     and gain are specified, exposure does nothing. All values should be set between 0-4095"""
00122 
00123     def limit_fff( parameter ):
00124         if parameter > 0xfff:
00125             parameter = 0xfff
00126         elif parameter < 0:
00127             parameter = 0
00128 
00129         return parameter
00130 
00131     if brightness == None and exposure != None:
00132         setRegister( index, register_dict['brightness'], 0x83000000 )
00133         setRegister( index, register_dict['exposure'], 0x82000000+limit_fff(exposure))
00134         setRegister( index, register_dict['shutter_time'], 0x83000000)
00135         setRegister( index, register_dict['gain'], 0x83000000)
00136     
00137     elif brightness == None:
00138         set_auto( index )
00139     
00140     else:
00141             if shutter_time != None or gain != None:
00142                 setRegister( index, register_dict['brightness'], 0x82000000+limit_fff(brightness))
00143                 setRegister( index, register_dict['exposure'], 0x80000000)
00144                 setRegister( index, register_dict['shutter_time'], 0x82000000+limit_fff(shutter_time))
00145                 setRegister( index, register_dict['gain'], 0x82000000+limit_fff(gain))
00146             else:
00147                 if exposure == None:
00148                     setRegister( index, register_dict['brightness'], 0x82000000+limit_fff(brightness))
00149                     setRegister( index, register_dict['exposure'], 0x83000000)
00150                     setRegister( index, register_dict['shutter_time'], 0x83000000)
00151                     setRegister( index, register_dict['gain'], 0x83000000)
00152                 else:
00153                     setRegister( index, register_dict['brightness'], 0x82000000+limit_fff(brightness))
00154                     setRegister( index, register_dict['exposure'], 0x82000000+limit_fff(exposure))
00155                     setRegister( index, register_dict['shutter_time'], 0x83000000)
00156                     setRegister( index, register_dict['gain'], 0x83000000)
00157 
00158 
00159 
00160 


hrl_camera
Author(s): Hai Nguyen, Advait Jain, Cressel Anderson, Marc Killpack
autogenerated on Wed Nov 27 2013 11:37:01