<s> import PythonQt <EOL> from PythonQt import QtCore , QtGui , QtUiTools <EOL> from director import lcmUtils <EOL> from director import applogic as app <EOL> from director . utime import getUtime <EOL> from director . timercallback import TimerCallback <EOL> import numpy as np <EOL> import math <EOL> from time import time <EOL> from copy import deepcopy <EOL> def addWidgetsToDict ( widgets , d ) : <EOL> for widget in widgets : <EOL> if widget . objectName : <EOL> d [ str ( widget . objectName ) ] = widget <EOL> addWidgetsToDict ( widget . children ( ) , d ) <EOL> class WidgetDict ( object ) : <EOL> def __init__ ( self , widgets ) : <EOL> addWidgetsToDict ( widgets , self . __dict__ ) <EOL> class SpindleSpinChecker ( object ) : <EOL> def __init__ ( self , spindleMonitor ) : <EOL> self . spindleMonitor = spindleMonitor <EOL> self . timer = TimerCallback ( targetFps = <NUM_LIT:3> ) <EOL> self . timer . callback = self . update <EOL> self . warningButton = None <EOL> self . action = None <EOL> def update ( self ) : <EOL> if abs ( self . spindleMonitor . getAverageSpindleVelocity ( ) ) < <NUM_LIT> : <EOL> self . notifyUserStatusBar ( ) <EOL> else : <EOL> self . clearStatusBarWarning ( ) <EOL> def start ( self ) : <EOL> self . action . checked = True <EOL> self . timer . start ( ) <EOL> def stop ( self ) : <EOL> self . action . checked = False <EOL> self . timer . stop ( ) <EOL> def setupMenuAction ( self ) : <EOL> self . action = app . addMenuAction ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . action . setCheckable ( True ) <EOL> self . action . checked = self . timer . isActive ( ) <EOL> self . action . connect ( '<STR_LIT>' , self . onActionChanged ) <EOL> def onActionChanged ( self ) : <EOL> if self . action . checked : <EOL> self . start ( ) <EOL> else : <EOL> self . stop ( ) <EOL> def clearStatusBarWarning ( self ) : <EOL> if self . warningButton : <EOL> self . warningButton . deleteLater ( ) <EOL> self . warningButton = None <EOL> def notifyUserStatusBar ( self ) : <EOL> if self . warningButton : <EOL> return <EOL> self . warningButton = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> self . warningButton . setStyleSheet ( "<STR_LIT>" ) <EOL> app . getMainWindow ( ) . statusBar ( ) . insertPermanentWidget ( <NUM_LIT:0> , self . warningButton ) <EOL> class MultisensePanel ( object ) : <EOL> def __init__ ( self , multisenseDriver ) : <EOL> self . multisenseDriver = multisenseDriver <EOL> self . multisenseChanged = False <EOL> loader = QtUiTools . QUiLoader ( ) <EOL> uifile = QtCore . QFile ( '<STR_LIT>' ) <EOL> assert uifile . open ( uifile . ReadOnly ) <EOL> self . widget = loader . load ( uifile ) <EOL> self . ui = WidgetDict ( self . widget . children ( ) ) <EOL> self . updateTimer = TimerCallback ( targetFps = <NUM_LIT:2> ) <EOL> self . updateTimer . callback = self . updatePanel <EOL> self . updateTimer . start ( ) <EOL> self . widget . headCamGainSpinner . setEnabled ( False ) <EOL> self . widget . headCamExposureSpinner . setEnabled ( False ) <EOL> self . widget . spinRateSpinner . valueChanged . connect ( self . spinRateChange ) <EOL> self . widget . scanDurationSpinner . valueChanged . connect ( self . scanDurationChange ) <EOL> self . widget . headCamFpsSpinner . valueChanged . connect ( self . headCamFpsChange ) <EOL> self . widget . headCamGainSpinner . valueChanged . connect ( self . headCamGainChange ) <EOL> self . widget . headCamExposureSpinner . valueChanged . connect ( self . headCamExposureChange ) <EOL> self . widget . headAutoGainCheck . clicked . connect ( self . headCamAutoGainChange ) <EOL> self . widget . ledOnCheck . clicked . connect ( self . ledOnCheckChange ) <EOL> self . widget . ledBrightnessSpinner . valueChanged . connect ( self . ledBrightnessChange ) <EOL> self . widget . sendButton . clicked . connect ( self . sendButtonClicked ) <EOL> self . updatePanel ( ) <EOL> def getCameraFps ( self ) : <EOL> return self . widget . headCamFpsSpinner . value <EOL> def getCameraGain ( self ) : <EOL> return self . widget . headCamGainSpinner . value <EOL> def getCameraExposure ( self ) : <EOL> return self . widget . headCamExposureSpinner . value <EOL> def getCameraLedOn ( self ) : <EOL> return self . widget . ledOnCheck . isChecked ( ) <EOL> def getCameraLedBrightness ( self ) : <EOL> return self . widget . ledBrightnessSpinner . value <EOL> def getCameraAutoGain ( self ) : <EOL> return self . widget . headAutoGainCheck . isChecked ( ) <EOL> def getSpinRate ( self ) : <EOL> return self . widget . spinRateSpinner . value <EOL> def getScanDuration ( self ) : <EOL> return self . widget . scanDurationSpinner . value <EOL> def ledBrightnessChange ( self , event ) : <EOL> self . multisenseChanged = True <EOL> def ledOnCheckChange ( self , event ) : <EOL> self . multisenseChanged = True <EOL> def headCamExposureChange ( self , event ) : <EOL> self . multisenseChanged = True <EOL> def headCamAutoGainChange ( self , event ) : <EOL> self . multisenseChanged = True <EOL> self . widget . headCamGainSpinner . setEnabled ( not self . getCameraAutoGain ( ) ) <EOL> self . widget . headCamExposureSpinner . setEnabled ( not self . getCameraAutoGain ( ) ) <EOL> def headCamFpsChange ( self , event ) : <EOL> self . multisenseChanged = True <EOL> def headCamGainChange ( self , event ) : <EOL> self . multisenseChanged = True <EOL> def spinRateChange ( self , event ) : <EOL> self . multisenseChanged = True <EOL> spinRate = self . getSpinRate ( ) <EOL> if spinRate == <NUM_LIT:0.0> : <EOL> scanDuration = <NUM_LIT> <EOL> else : <EOL> scanDuration = abs ( <NUM_LIT> / ( spinRate * <NUM_LIT:2> ) ) <EOL> if scanDuration > <NUM_LIT> : <EOL> scanDuration = <NUM_LIT> <EOL> self . widget . scanDurationSpinner . blockSignals ( True ) <EOL> self . widget . scanDurationSpinner . value = scanDuration <EOL> self . widget . scanDurationSpinner . blockSignals ( False ) <EOL> def scanDurationChange ( self , event ) : <EOL> self . multisenseChanged = True <EOL> scanDuration = self . getScanDuration ( ) <EOL> spinRate = abs ( <NUM_LIT> / ( scanDuration * <NUM_LIT:2> ) ) <EOL> self . widget . spinRateSpinner . blockSignals ( True ) <EOL> self . widget . spinRateSpinner . value = spinRate <EOL> self . widget . spinRateSpinner . blockSignals ( False ) <EOL> def sendButtonClicked ( self , event ) : <EOL> self . publishCommand ( ) <EOL> def updatePanel ( self ) : <EOL> if not self . widget . isVisible ( ) : <EOL> return <EOL> def publishCommand ( self ) : <EOL> fps = self . getCameraFps ( ) <EOL> camGain = self . getCameraGain ( ) <EOL> exposure = <NUM_LIT:1000> * self . getCameraExposure ( ) <EOL> ledFlash = self . getCameraLedOn ( ) <EOL> ledDuty = self . getCameraLedBrightness ( ) <EOL> spinRate = self . getSpinRate ( ) <EOL> autoGain = <NUM_LIT:1> if self . getCameraAutoGain ( ) else <NUM_LIT:0> <EOL> self . multisenseDriver . sendMultisenseCommand ( fps , camGain , exposure , autoGain , spinRate , ledFlash , ledDuty ) <EOL> self . multisenseChanged = False <EOL> self . updateTimer . start ( ) <EOL> def _getAction ( ) : <EOL> return app . getToolBarActions ( ) [ '<STR_LIT>' ] <EOL> def init ( driver ) : <EOL> global panel <EOL> global dock <EOL> panel = MultisensePanel ( driver ) <EOL> dock = app . addWidgetToDock ( panel . widget , action = _getAction ( ) ) <EOL> dock . hide ( ) <EOL> return panel </s>
