def __init__(self, minValue=0.0, maxValue=1.0, resolution=1000): self._value = 0.0 self.spinbox = QtGui.QDoubleSpinBox() self.spinbox.setSuffix('s') self.slider = QtGui.QSlider(QtCore.Qt.Horizontal) self.playButton = QtGui.QPushButton('Play') self.setValueRange(minValue, maxValue) self.setResolution(resolution) self.slider.connect('valueChanged(int)', self._onSliderValueChanged) self.spinbox.connect('valueChanged(double)', self._onSpinboxValueChanged) self.playButton.connect('clicked()', self._onPlayClicked) self.widget = QtGui.QWidget() layout = QtGui.QHBoxLayout(self.widget) layout.addWidget(self.playButton) layout.addWidget(self.spinbox) layout.addWidget(self.slider) self.animationPrevTime = 0.0 self.animationRate = 1.0 self.animationRateTarget = 1.0 self.animationRateAlpha = 1.0 self.animationTimer = TimerCallback(callback=self._tick, targetFps=60) self.useRealTime = True self.callbacks = callbacks.CallbackRegistry(self.events._fields) self.eventFilter = PythonQt.dd.ddPythonEventFilter() self.eventFilter.connect('handleEvent(QObject*, QEvent*)', self._filterEvent) self.eventFilter.addFilteredEventType(QtCore.QEvent.MouseButtonPress) self.eventFilter.addFilteredEventType(QtCore.QEvent.MouseMove) self.slider.installEventFilter(self.eventFilter)
def __init__(self, obj, propertyName, targetValue, animationTime=1.0): self.obj = obj self.propertyName = propertyName self.animationTime = animationTime self.targetValue = targetValue self.timer = TimerCallback()
def initView(self, view): # Must call the createview function with the robot name so that the view can be associated, but cannot pass # keyword arguments to python_qt functions so need to also pass the -1 to add the tab to the end of the list # rather than insert it. self.view = view or app.getViewManager().createView( self.viewName, "VTK View", -1, self.robotName) app.getRobotSelector().associateViewWithRobot(self.view, self.robotName) self.view.installImageInteractor() # self.interactorStyle = self.view.renderWindow().GetInteractor().GetInteractorStyle() # self.interactorStyle.AddObserver('SelectionChangedEvent', self.onRubberBandPick) self.imageActor = vtk.vtkImageActor() self.imageActor.SetInputData(self.getImage()) self.imageActor.SetVisibility(False) self.view.renderer().AddActor(self.imageActor) self.view.orientationMarkerWidget().Off() self.view.backgroundRenderer().SetBackground(0, 0, 0) self.view.backgroundRenderer().SetBackground2(0, 0, 0) self.timerCallback = TimerCallback() self.timerCallback.targetFps = 60 self.timerCallback.callback = self.updateView self.timerCallback.start()
def main(): app = consoleapp.ConsoleApp() meshCollection = lcmobjectcollection.LCMObjectCollection( 'MESH_COLLECTION_COMMAND') affordanceCollection = lcmobjectcollection.LCMObjectCollection( 'AFFORDANCE_COLLECTION_COMMAND') meshCollection.sendEchoRequest() affordanceCollection.sendEchoRequest() def printCollection(): print print '----------------------------------------------------' print datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') print '%d affordances' % len(affordanceCollection.collection) for desc in affordanceCollection.collection.values(): print print 'name:', desc['Name'] print 'type:', desc['classname'] timer = TimerCallback(targetFps=0.2) timer.callback = printCollection timer.start() #app.showPythonConsole() app.start()
def __init__(self, view): self.view = view loader = QtUiTools.QUiLoader() uifile = QtCore.QFile(':/ui/ddFrameVisualization.ui') assert uifile.open(uifile.ReadOnly) self.widget = loader.load(uifile) self.ui = WidgetDict(self.widget.children()) self.botFrameUpdater = BotFrameUpdater(self.ui.botFramesListWidget) robotModel = om.findObjectByName('robot state model') self.linkFrameUpdater = LinkFrameUpdater(robotModel, self.ui.linkFramesListWidget) self.eventFilter = PythonQt.dd.ddPythonEventFilter() self.ui.scrollArea.installEventFilter(self.eventFilter) self.eventFilter.addFilteredEventType(QtCore.QEvent.Resize) self.eventFilter.connect('handleEvent(QObject*, QEvent*)', self.onEvent) PythonQt.dd.ddGroupBoxHider(self.ui.botFramesGroup) PythonQt.dd.ddGroupBoxHider(self.ui.linkFramesGroup) self.updateTimer = TimerCallback(targetFps=60) self.updateTimer.callback = self.updateFrames self.updateTimer.start()
def __init__(self, frameProvider): vis.PolyDataItem.__init__(self, 'spindle axis', vtk.vtkPolyData(), view=None) self.frameProvider = frameProvider self.timer = TimerCallback() self.timer.callback = self.update self.setProperty('Color', QtGui.QColor(0, 255, 0)) self.setProperty('Visible', False)
def __init__(self, imageManager, imageName, view, visible=True): self.view = view self.imageManager = imageManager self.imageName = imageName self.visible = visible self.updateUtime = 0 self.initialized = False self.imageWidget = vtk.vtkLogoWidget() imageRep = self.imageWidget.GetRepresentation() self.imageWidget.ResizableOff() self.imageWidget.SelectableOn() imageRep.GetImageProperty().SetOpacity(1.0) self.imageWidget.SetInteractor( self.view.renderWindow().GetInteractor()) self.flip = vtk.vtkImageFlip() self.flip.SetFilteredAxis(1) self.flip.SetInput(imageManager.getImage(imageName)) imageRep.SetImage(self.flip.GetOutput()) self.eventFilter = PythonQt.dd.ddPythonEventFilter() self.view.installEventFilter(self.eventFilter) self.eventFilter.addFilteredEventType(QtCore.QEvent.Resize) self.eventFilter.connect('handleEvent(QObject*, QEvent*)', self.onResizeEvent) self.timerCallback = TimerCallback() self.timerCallback.targetFps = 60 self.timerCallback.callback = self.updateView self.timerCallback.start()
def __init__(self, view): self.view = view self.depthImage = None self.pointCloudObj = None self.renderObserver = None self.windowToDepthBuffer = vtk.vtkWindowToImageFilter() self.windowToDepthBuffer.SetInput(self.view.renderWindow()) self.windowToDepthBuffer.SetInputBufferTypeToZBuffer() self.windowToDepthBuffer.ShouldRerenderOff() self.windowToColorBuffer = vtk.vtkWindowToImageFilter() self.windowToColorBuffer.SetInput(self.view.renderWindow()) self.windowToColorBuffer.SetInputBufferTypeToRGB() self.windowToColorBuffer.ShouldRerenderOff() useBackBuffer = False if useBackBuffer: self.windowToDepthBuffer.ReadFrontBufferOff() self.windowToColorBuffer.ReadFrontBufferOff() self.initDepthImageView() self.initPointCloudView() self._block = False self.singleShotTimer = TimerCallback() self.singleShotTimer.callback = self.update
def start(enableAutomaticQuit=True): """ In testing mode, the application will quit automatically after starting unless enableAutomaticQuit is set to False. Tests that need to perform work after the QApplication has started can set this flag to False and call quit or exit themselves. In testing mode, this function will register an exception hook so that tests will return on error code if an unhandled exception is raised. """ if enableAutomaticQuit: ConsoleApp.startTestingModeQuitTimer() if (ConsoleApp.getTestingEnabled() and not ConsoleApp.getTestingInteractiveEnabled()): sys.excepthook = _consoleAppExceptionHook def onStartup(): for func in ConsoleApp._startupCallbacks: try: func() except: print traceback.format_exc() startTimer = TimerCallback(callback=onStartup) startTimer.singleShot(0) result = ConsoleApp.applicationInstance().exec_() if (ConsoleApp.getTestingEnabled() and not ConsoleApp.getTestingInteractiveEnabled()): print "TESTING PROGRAM RETURNING EXIT CODE:", result sys.exit(result) return result
def __init__(self, imageManager, view=None, robotName=""): self.imageManager = imageManager self.updateUtimes = {} self.robotModel = None self.sphereObjects = {} self.robotName = robotName try: if self.robotName: self.images = [ camera["name"] for camera in drcargs.getRobotConfig( self.robotName)["sensors"]["camera"]["color"] ] except KeyError as e: raise Exception( "CameraView requires color cameras to be defined at sensors/camera/color." " Check your director config.") for name in self.images: imageManager.addImage(name, self.robotName) self.updateUtimes[name] = 0 self.initView(view) self.initEventFilter() self.rayCallback = rayDebug self.timerCallback = TimerCallback() self.timerCallback.targetFps = 60 self.timerCallback.callback = self.updateView self.timerCallback.start()
def __init__(self, imageManager, imageNames, view, visible=True, robotName=None): self.view = view self.imageManager = imageManager self.robotName = robotName self.imageNames = imageNames self.visible = visible self.widgetWidth = 400 self.showNonMainImages = True # if false, show only imageNames[0] self.updateUtime = 0 self.initialized = False # these two data structures are initialized when data is received self.imageWidgets = [None for i in range(0, len(self.imageNames))] self.flips = [None for i in range(0, len(self.imageNames))] self.eventFilter = PythonQt.dd.ddPythonEventFilter() self.view.installEventFilter(self.eventFilter) self.eventFilter.addFilteredEventType(QtCore.QEvent.Resize) self.eventFilter.connect("handleEvent(QObject*, QEvent*)", self.onResizeEvent) self.timerCallback = TimerCallback() self.timerCallback.targetFps = 60 self.timerCallback.callback = self.updateView self.timerCallback.start()
def __init__(self, image_handler): self._name = 'Image View' self._view = PythonQt.dd.ddQVTKWidgetView() self._image_handler = image_handler self._image = vtk.vtkImageData() self._prev_attrib = None # Initialize the view. self._view.installImageInteractor() # Add actor. self._image_actor = vtk.vtkImageActor() vtk_SetInputData(self._image_actor, self._image) self._image_actor.SetVisibility(False) self._view.renderer().AddActor(self._image_actor) self._view.orientationMarkerWidget().Off() self._view.backgroundRenderer().SetBackground(0, 0, 0) self._view.backgroundRenderer().SetBackground2(0, 0, 0) self._depth_mapper = None # Add timer. self._render_timer = TimerCallback(targetFps=60, callback=self.render) self._render_timer.start()
def _initTaskPanel(self): self.lastStatusMessage = '' self.nextStepTask = None self.completedTasks = [] self.taskQueue = atq.AsyncTaskQueue() self.taskQueue.connectQueueStarted(self.onQueueStarted) self.taskQueue.connectQueueStopped(self.onQueueStopped) self.taskQueue.connectTaskStarted(self.onTaskStarted) self.taskQueue.connectTaskEnded(self.onTaskEnded) self.taskQueue.connectTaskPaused(self.onTaskPaused) self.taskQueue.connectTaskFailed(self.onTaskFailed) self.taskQueue.connectTaskException(self.onTaskException) self.timer = TimerCallback(targetFps=2) self.timer.callback = self.updateTaskStatus self.timer.start() self.taskTree = tmw.TaskTree() self.ui.taskFrame.layout().insertWidget(0, self.taskTree.treeWidget) l = QtGui.QVBoxLayout(self.ui.taskPropertiesGroupBox) l.addWidget(self.taskTree.propertiesPanel) PythonQt.dd.ddGroupBoxHider(self.ui.taskPropertiesGroupBox) self.ui.taskStepButton.connect('clicked()', self.onStep) self.ui.taskContinueButton.connect('clicked()', self.onContinue) self.ui.taskPauseButton.connect('clicked()', self.onPause) self.ui.promptAcceptButton.connect('clicked()', self.onAcceptPrompt) self.ui.promptRejectButton.connect('clicked()', self.onRejectPrompt) self.clearPrompt() self.updateTaskButtons()
def startApplication(enableQuitTimer=False): appInstance = QtGui.QApplication.instance() if enableQuitTimer: quitTimer = TimerCallback() quitTimer.callback = appInstance.quit quitTimer.singleShot(0.1) appInstance.exec_()
def __init__(self, robotStateJointController, view, cameraview, mapServerSource): self.robotStateJointController = robotStateJointController self.view = view self.cameraview = cameraview self.mapServerSource = mapServerSource self.lastCameraMessageTime = 0 self.lastScanBundleMessageTime = 0 self.lastBlackoutLengths = [] self.lastBlackoutLength = 0 self.inBlackout = False self.averageBlackoutLength = 0.0 self.txt = vis.updateText("DATA AGE: 0 sec", "Data Age Text", view=self.view) self.txt.addProperty('Show Avg Duration', False) self.txt.setProperty('Visible', False) self.updateTimer = TimerCallback(self.UPDATE_RATE) self.updateTimer.callback = self.update self.updateTimer.start()
def __init__(self, propertySet, propertiesPanel, propertyNamesToAdd=None): self.propertySet = propertySet self.propertyNamesToAdd = propertyNamesToAdd self.propertiesPanel = propertiesPanel self.connections = [] self.connections.append( self.propertySet.connectPropertyAdded(self._onPropertyAdded) ) self.connections.append( self.propertySet.connectPropertyChanged(self._onPropertyChanged) ) self.connections.append( self.propertySet.connectPropertyAttributeChanged( self._onPropertyAttributeChanged ) ) self.propertiesPanel.connect( "propertyValueChanged(QtVariantProperty*)", self._onPanelPropertyChanged ) self.timer = TimerCallback() self.timer.callback = self._rebuildNow self._blockSignals = True PropertyPanelHelper.addPropertiesToPanel( self.propertySet, self.propertiesPanel, self.propertyNamesToAdd ) self._blockSignals = False
def onRobotPlan(self, msg): playback = planplayback.PlanPlayback() playback.interpolationMethod = 'pchip' poseTimes, poses = playback.getPlanPoses(msg) f = playback.getPoseInterpolator(poseTimes, poses) jointController = self.robotSystem.teleopJointController timer = simpletimer.SimpleTimer() def setPose(pose): jointController.setPose('plan_playback', pose) self.jointTeleopPanel.endPose = pose self.jointTeleopPanel.updateSliders() commandStream.setGoalPose(pose) def updateAnimation(): tNow = timer.elapsed() if tNow > poseTimes[-1]: pose = poses[-1] setPose(pose) return False pose = f(tNow) setPose(pose) self.animationTimer = TimerCallback() self.animationTimer.targetFps = 60 self.animationTimer.callback = updateAnimation self.animationTimer.start()
def __init__(self): self.timer = TimerCallback(targetFps=10) #self.timer.disableScheduledTimer() self.app = ConsoleApp() self.robotModel, self.jointController = roboturdf.loadRobotModel( 'robot model') self.fpsCounter = simpletimer.FPSCounter() self.drakePoseJointNames = robotstate.getDrakePoseJointNames() self.fpsCounter.printToConsole = True self.timer.callback = self._tick self._initialized = False self.publishChannel = 'JOINT_POSITION_GOAL' # self.lastCommandMessage = newAtlasCommandMessageAtZero() self._numPositions = len(robotstate.getDrakePoseJointNames()) self._previousElapsedTime = 100 self._baseFlag = 0 self.jointLimitsMin = np.array([ self.robotModel.model.getJointLimits(jointName)[0] for jointName in robotstate.getDrakePoseJointNames() ]) self.jointLimitsMax = np.array([ self.robotModel.model.getJointLimits(jointName)[1] for jointName in robotstate.getDrakePoseJointNames() ]) self.useControllerFlag = False self.drivingGainsFlag = False self.applyDefaults()
def playPoses(self, poseTimes, poses, jointController): f = self.getPoseInterpolator(poseTimes, poses) timer = SimpleTimer() def updateAnimation(): tNow = timer.elapsed() * self.playbackSpeed if tNow > poseTimes[-1]: pose = poses[-1] jointController.setPose("plan_playback", pose) if self.animationCallback: self.animationCallback() return False pose = f(tNow) jointController.setPose("plan_playback", pose) if self.animationCallback: self.animationCallback() self.animationTimer = TimerCallback() self.animationTimer.targetFps = 60 self.animationTimer.callback = updateAnimation self.animationTimer.start() updateAnimation()
def __init__(self, spindleMonitor): self.spindleMonitor = spindleMonitor self.timer = TimerCallback(targetFps=3) self.timer.callback = self.update self.warningButton = None self.action = None
def setupPlayback(self): self.timer = TimerCallback(targetFps=30) self.timer.callback = self.tick playButtonFps = 1.0 / self.dt print "playButtonFPS", playButtonFps self.playTimer = TimerCallback(targetFps=playButtonFps) self.playTimer.callback = self.playTimerCallback self.sliderMovedByPlayTimer = False panel = QtGui.QWidget() l = QtGui.QHBoxLayout(panel) playButton = QtGui.QPushButton('Play/Pause') playButton.connect('clicked()', self.onPlayButton) slider = QtGui.QSlider(QtCore.Qt.Horizontal) slider.connect('valueChanged(int)', self.onSliderChanged) self.sliderMax = self.numTimesteps slider.setMaximum(self.sliderMax) self.slider = slider l.addWidget(playButton) l.addWidget(slider) w = QtGui.QWidget() l = QtGui.QVBoxLayout(w) l.addWidget(self.view) l.addWidget(panel) w.showMaximized() self.frame.connectFrameModified(self.updateDrawIntersection) self.updateDrawIntersection(self.frame) applogic.resetCamera(viewDirection=[0.2, 0, -1]) self.view.showMaximized() self.view.raise_() panel = screengrabberpanel.ScreenGrabberPanel(self.view) panel.widget.show() elapsed = time.time() - self.startSimTime simRate = self.counter / elapsed print "Total run time", elapsed print "Ticks (Hz)", simRate print "Number of steps taken", self.counter self.app.start()
def __init__(self, atlasDriver, statusBar): self.atlasDriver = atlasDriver self.label = QtGui.QLabel('') statusBar.addPermanentWidget(self.label) self.timer = TimerCallback(targetFps=1) self.timer.callback = self.showRate self.timer.start()
def __init__(self, lDriver, rDriver, robotStateModel, robotStateJointController, view): self.robotStateModel = robotStateModel self.robotStateJointController = robotStateJointController self.drivers = {} self.drivers['left'] = lDriver self.drivers['right'] = rDriver self.storedCommand = {'left': None, 'right': None} loader = QtUiTools.QUiLoader() uifile = QtCore.QFile(':/ui/ddHandControl.ui') assert uifile.open(uifile.ReadOnly) self.widget = loader.load(uifile) self.ui = WidgetDict(self.widget.children()) self._updateBlocked = True self.widget.advanced.sendButton.setEnabled(True) # Store calibration for wrist f/t sensors self.wristftvis = WristForceTorqueVisualizer(robotStateModel, robotStateJointController, view) # connect the callbacks self.widget.basic.openButton.clicked.connect(self.openClicked) self.widget.basic.closeButton.clicked.connect(self.closeClicked) self.widget.basic.waitOpenButton.clicked.connect(self.waitOpenClicked) self.widget.basic.waitCloseButton.clicked.connect(self.waitCloseClicked) self.widget.advanced.sendButton.clicked.connect(self.sendClicked) self.widget.advanced.calibrateButton.clicked.connect(self.calibrateClicked) self.widget.advanced.setModeButton.clicked.connect(self.setModeClicked) self.widget.advanced.regraspButton.clicked.connect(self.regraspClicked) self.widget.advanced.dropButton.clicked.connect(self.dropClicked) self.widget.advanced.repeatRateSpinner.valueChanged.connect(self.rateSpinnerChanged) self.ui.fingerControlButton.clicked.connect(self.fingerControlButton) self.widget.sensors.rightTareButton.clicked.connect(self.wristftvis.tareRightFT) self.widget.sensors.leftTareButton.clicked.connect(self.wristftvis.tareLeftFT) self.widget.sensors.rightCalibButton.clicked.connect(self.wristftvis.calibRightFT) self.widget.sensors.leftCalibButton.clicked.connect(self.wristftvis.calibLeftFT) self.widget.sensors.rightCalibClearButton.clicked.connect(self.wristftvis.calibRightClearFT) self.widget.sensors.leftCalibClearButton.clicked.connect(self.wristftvis.calibLeftClearFT) self.widget.sensors.rightVisCheck.clicked.connect(self.updateWristFTVis) self.widget.sensors.leftVisCheck.clicked.connect(self.updateWristFTVis) self.widget.sensors.torqueVisCheck.clicked.connect(self.updateWristFTVis) PythonQt.dd.ddGroupBoxHider(self.ui.sensors) PythonQt.dd.ddGroupBoxHider(self.ui.fingerControl) # Bug fix... for some reason one slider is set as disabled self.ui.fingerASlider.setEnabled(True) # create a timer to repeat commands self.updateTimer = TimerCallback() self.updateTimer.callback = self.updatePanel self.updateTimer.targetFps = 3 self.updateTimer.start()
def __init__(self): self.interval = 1 / 60.0 sys.setcheckinterval(1000) #sys.setswitchinterval(self.interval) # sys.setswitchinterval is only Python 3 self.taskQueue = asynctaskqueue.AsyncTaskQueue() self.pendingTasks = [] self.threads = [] self.timer = TimerCallback(callback=self._onTimer, targetFps=1 / self.interval)
def __init__(self, lcmHandle=None): if not lcmHandle: lcmHandle = lcmUtils.getGlobalLCM() self.lcmHandle = lcmHandle self.log = None self.filePositions = [] self.playbackFactor = 1.0 self.timer = TimerCallback() self.timestamps = np.array([]) self.timestampOffset = 0.0
def __init__(self, affordanceManager, imageView): self.affordanceManager = affordanceManager self.prependImageName = False self.projectFootsteps = False self.projectAffordances = True self.extraObjects = [] self.imageView = imageView self.imageQueue = imageView.imageManager.queue self.timer = TimerCallback(targetFps=10) self.timer.callback = self.update
def __init__(self): self.target = None self.targetFrame = None self.trackerClass = None self.camera = None self.view = None self.timer = TimerCallback() self.timer.callback = self.updateTimer self.addTrackers() self.initTracker()
def __init__(self, robotSystem, configFilename="contact_particle_filter_config.yaml"): self.robotSystem = robotSystem self.robotStateModel = robotSystem.robotStateModel self.robotStateModel.connectModelChanged(self.onModelChanged) self.options = cfUtils.loadConfig(configFilename) self.loadDrakeModelFromFilename() self.initializeRobotPoseTranslator() self.initializeJointNamesList() # keys = linkNames, wrench = 6 x 1 Torque-Force vector, all in body frame self.externalForces = dict() self.publishChannel = 'EXTERNAL_FORCE_TORQUE' self.captureMode = False self.captureModeCounter = 0 self.showContactRay = True self.showContactFilterEstimate = True self.addSubscribers() self.createPlunger() self.createMeshDataAndLocators() self.createTwoStepEstimator(configFilename) self.visObjectDrawTime = dict() self.timeout = 1.5 # setup timercallback to publish, lets say at 5 hz self.timer = TimerCallback(targetFps=25) self.timer.callback = self.publish self.startPublishing() # self.startPublishing() # this now gets activated when you start linkSelection self.visObjectCleanupTimer = TimerCallback(targetFps=1) self.visObjectCleanupTimer.callback = self.removeStaleVisObjects self.visObjectCleanupTimer.start() self.initializationTime = time.time() self.trueResidual = None self.estimatedResidual = None
def __init__(self, name, cameraName, imageManager, robotStateJointController, provider=None): vis.PolyDataItem.__init__(self, name, vtk.vtkPolyData(), view=None) self.robotStateJointController = robotStateJointController self.addProperty("Camera name", cameraName) self.addProperty( "Decimation", 1, attributes=om.PropertyAttributes( enumNames=["1", "2", "4", "8", "16"]), ) self.addProperty( "Remove Size", 1000, attributes=om.PropertyAttributes(decimals=0, minimum=0, maximum=100000.0, singleStep=1000), ) self.addProperty( "Target FPS", 5.0, attributes=om.PropertyAttributes(decimals=1, minimum=0.1, maximum=30.0, singleStep=0.1), ) self.addProperty( "Max Range", 5.0, attributes=om.PropertyAttributes(decimals=2, minimum=0.0, maximum=30.0, singleStep=0.25), ) self.imageManager = imageManager self.cameraName = cameraName self.firstData = True self.timer = TimerCallback() self.timer.callback = self.update self.lastUtime = 0 self.lastDataReceivedTime = 0 if provider: self.setProvider(provider) else: self.provider = None
def start(self, rate_hz=30): """ Launches a timercallback that just calls update() :param rate_hz: :type rate_hz: :return: :rtype: """ self._timercallback = TimerCallback(targetFps=rate_hz, callback=self.update) self._timercallback.start()