def StartAutoHandleUserInput(self): ''' @brief Handle auto user input in thread ''' if self.__auto: self.__manual_user_input = False if not (self.__no_termination): RunThread(self.AutoHandleUserInput)
def WriteFrameThread(self, frame): ''' @brief Write frame in thread for smoother program flow. ''' RunThread(self.WriteFrame, args=(frame, ), lock=self.__write_lock, wait_lock=True)
def CaptureFrame(self, skip_pin_trig=False, skip_manual_trig=False): ''' @brief Capture image Pin triggering is handled if it is set. @param skip_pin_trig (True/False for skipping trigging a new frame on the Ptgrey) @param skip_manual_trig (True/False for skipping manual trig.) @return frame ''' self.AssertCameraCapturing() if not (skip_manual_trig): self.ManualTriggering() if self.__mc_trigger_pin.GetPin() >= 0 and not (skip_pin_trig): self.__mc_trigger_pin.TogglePin() t = RunThread(self.RetrieveBufferThread) if self.__capture_timeout >= 0: t.join(self.__capture_timeout) else: t.join() if t.isAlive(): raise PtGreyError('timeout_capturing_frame_error_msg') elif self.__error_flag: self.__error_flag = False raise PtGreyError('failed_capturing_frame_error_msg') if self.CheckManualTriggering(): time.sleep( 1.0 ) # Sleep camera if manual trig to make it dump the image buffer. return np.array(self.__frame_object)
def TestMasterSlave(self): ''' @brief Unit test for testing master and slave in a single test. ''' from src.bin.tools import RunThread RunThread(self.test_ObjSlave.TestSlave) self.TestMaster()
def TestDroneMasterSlave(self): ''' @brief Test function for DroneMaster (With slave in thread) ''' print 'Testing DroneMaster with DroneSlave in separate thread' from Test_DroneSlaveSubClass import Test_DroneSlaveSubClass from src.bin.tools import RunThread test_DroneSlave = Test_DroneSlaveSubClass() RunThread(test_DroneSlave.TestDroneSlave) self.TestDroneMaster()
def ReceiveRequest(self, request, content): ''' @brief Handle request from master @param request Request from master @param content Additional content @return stop True/False on stop receiving. ''' stop = False if request == 'setNewFrame': self.SendPayload(request, '') self.__subclass.SetProcessNewFrameFlag() elif request == 'getFrame': frame_content, error = self.__subclass.GetFramePayload() content = self.GetContentRequestFrame(frame_content, error) self.SendPayload(request, content) if content['valid']: self.__subclass.SetStoreDBFlag( ) # Store frames to database after sending them to master. elif request == 'getOriginalFrame': sl_filename = None if 'sl_filename' in content: sl_filename = content['sl_filename'] filename = content['filename'] frame_content, error = self.__subclass.GetOriginalFramePayload( filename, sl_filename) content = self.GetContentRequestOriginalFrame(frame_content, error) self.SendPayload(request, content) elif request == 'tradeFrame': filename = content['filename'] frame_content, error = self.__subclass.GetOriginalFramePayload( filename) content, traded_frame = self.GetRequestTradeFrame( frame_content, content, error) self.__subclass.SetNewTradedFrame(traded_frame) self.SendPayload(request, content) elif request == 'getPointList': frame_content, error = self.__subclass.GetFramePayload() content = self.GetContentRequestPointList(frame_content, error) self.SendPayload(request, content) if content['valid']: self.__subclass.SetStoreDBFlag( ) # Store frames to database after sending them to master. elif request == 'setTimestamp': self.SendPayload(request, '') self.__subclass.SetTimestamp( self.GetContentRequestSetTimestamp(content)) elif request == 'calibrateCV': calibrate_stereopsis_session = content[ 'calibrate_stereopsis_session'] calibrate_blob_scale_detector_session = content[ 'calibrate_blob_scale_detector_session'] self.__subclass.CalibrateCV(calibrate_stereopsis_session, calibrate_blob_scale_detector_session) self.SendPayload(request, '') elif request == 'slaveReady': content = self.GetContentRequestSlaveReady( self.__subclass.GetSlaveReady()) self.SendPayload(request, content) elif request == 'sendFlagToSlave': flag = self.GetContentSendFlagToSlave(content) self.__subclass.SetFlagFromMaster(flag) self.SendPayload(request, '') elif request == 'stop': self.SendPayload(request, '') self.ForceTermination() elif request == 'disconnect': self.SendPayload(request, '') self.Disconnect() stop = True elif request == 'restart': self.SendPayload(request, '') self.Disconnect() stop = True RunThread(self.RestartRequest, daemon=False) elif request == 'restartPtGrey': self.__subclass.RestartCamera() self.SendPayload(request, '') elif request == 'error': self.SendPayload(request, '') return stop
calib_blobs = True if 'master' in sys.argv: RunMaster(calib_stereopsis, calib_blobs) elif 'slave' in sys.argv: RunSlave() elif 'simulate' in sys.argv: preset_settings = Settings() if 'video' in sys.argv: preset_settings.ChangeSetting('BASIC', 'source_type', 'VIDEO') elif 'image' in sys.argv: preset_settings.ChangeSetting('BASIC', 'source_type', 'IMAGE') else: raise Exception("Please append 'video' or 'image' to select a source type for simulation, and be sure to set correct video/image targets in the settings configuration file. Append 'info' to get more details.") preset_settings.ChangeSetting('TCP', 'master_ip', 'localhost') if not(preset_settings.GetSettings('REAL_TIME_PLOT', 'use_matplotlib')): warnings.warn('PyQtImage does not work outside of main thread - switching to matplotlib with interactive mode on.') preset_settings.ChangeSetting('REAL_TIME_PLOT', 'use_matplotlib', True) preset_settings.ChangeSetting('REAL_TIME_PLOT', 'use_interactive_mode', True) RunThread(RunSlave, args=(preset_settings,)) RunMaster(calib_stereopsis, calib_blobs, preset_settings) else: raise Exception("Please append 'master', 'slave' or 'simulate' to start the main program.") elif 'test' in sys.argv: from TestUnits.Test_main import Test_main test_main = Test_main() test_main.ImportTestScipts() test_main.StartTest() else: Settings(skip_checking_for_user_input=True) warnings.warn("No start command given, please append 'info' to get more detailed information on how to use this program.")