From f48bcd45fcf30782a059480cba186b9f4924e603 Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:05:35 -0500 Subject: [PATCH 1/9] replacing beam available with three click signal variable --- gui/control_main.py | 56 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index 59dfd5cb..ab31827d 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -139,7 +139,7 @@ class ControlMain(QtWidgets.QMainWindow): fastShutterSignal = QtCore.Signal(float) gripTempSignal = QtCore.Signal(float) ringCurrentSignal = QtCore.Signal(float) - beamAvailableSignal = QtCore.Signal(float) + threeClickSignal = QtCore.Signal(float) sampleExposedSignal = QtCore.Signal(float) sampMoveSignal = QtCore.Signal(int, str) roiChangeSignal = QtCore.Signal(int, str) @@ -1424,6 +1424,15 @@ def createSampleTab(self): ringCurrentMessageLabel = QtWidgets.QLabel("Ring(mA):") self.ringCurrentMessage = QtWidgets.QLabel(str(self.ringCurrent_pv.get())) beamAvailable = self.beamAvailable_pv.get() + + ''' + changing beam available label + + + + ''' + + if beamAvailable: self.beamAvailLabel = QtWidgets.QLabel("Beam Available") self.beamAvailLabel.setStyleSheet("background-color: #99FF66;") @@ -1450,6 +1459,13 @@ def createSampleTab(self): else: self.cryostreamTempLabel = QtWidgets.QLabel("N/A") + + + + ''' + Adding bottom labels to gui + + ''' fileHBoxLayout.addWidget(gripperLabel) fileHBoxLayout.addWidget(self.gripperTempLabel) fileHBoxLayout.addWidget(cryostreamLabel) @@ -2195,6 +2211,12 @@ def processMountedPin(self, mountedPinPos): self.eraseCB() self.treeChanged_pv.put(1) + + ''' + functions to bottom status variables + + ''' + def processFastShutter(self, shutterVal): if round(shutterVal) == round(self.fastShutterOpenPos_pv.get()): self.shutterStateLabel.setText("Shutter State:Open") @@ -2220,13 +2242,18 @@ def processRingCurrent(self, ringCurrentVal): else: self.ringCurrentMessage.setStyleSheet("background-color: #99FF66;") - def processBeamAvailable(self, beamAvailVal): - if int(beamAvailVal) == 1: + ''' + change beam abailable set text depending on input + + function is processThreClickCentering + ''' + def processThreeClickCentering(self, beamAvailVal): + if int(beamAvailVal) == 0: self.beamAvailLabel.setText("Beam Available") self.beamAvailLabel.setStyleSheet("background-color: #99FF66;") else: - self.beamAvailLabel.setText("No Beam") - self.beamAvailLabel.setStyleSheet("background-color: red;") + self.beamAvailLabel.setText(beamAvailVal) + self.beamAvailLabel.setStyleSheet("background-color: yellow") def processSampleExposed(self, sampleExposedVal): if int(sampleExposedVal) == 1: @@ -3058,6 +3085,7 @@ def measurePolyCB(self): def center3LoopCB(self): logger.info("3-click center loop") self.threeClickCount = 1 + self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) self.click3Button.setStyleSheet("background-color: yellow") if(daq_utils.exporter_enabled): self.md2.exporter.cmd("startManualSampleCentring", "") @@ -3737,7 +3765,11 @@ def sceneKey(self, event): self.centeringMarksList[i]["graphicsItem"] ) self.centeringMarksList[i] = None + ''' + When picking pixels + + ''' def pixelSelect(self, event): super(QtWidgets.QGraphicsPixmapItem, self.pixmap_item).mousePressEvent(event) x_click = float(event.pos().x()) @@ -3805,9 +3837,13 @@ def pixelSelect(self, event): current_viewangle = daq_utils.mag3ViewAngle elif self.zoom4Radio.isChecked(): current_viewangle = daq_utils.mag4ViewAngle - + ''' + Three click centering will update self.threeClickSignal.emit(self.threeClickCount) + + ''' if self.threeClickCount > 0: # 3-click centering self.threeClickCount = self.threeClickCount + 1 + self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) if daq_utils.exporter_enabled: correctedC2C_x = x_click + ((daq_utils.screenPixX/2) - (self.centerMarker.x() + self.centerMarkerCharOffsetX)) correctedC2C_y = y_click + ((daq_utils.screenPixY/2) - (self.centerMarker.y() + self.centerMarkerCharOffsetY)) @@ -3822,6 +3858,7 @@ def pixelSelect(self, event): self.md2.centring_click.put(f"{correctedC2C_x} {correctedC2C_y}") if self.threeClickCount == 4: self.threeClickCount = 0 + self.threeClickSignal.emit(0) self.click3Button.setStyleSheet("background-color: None") return else: @@ -3832,6 +3869,7 @@ def pixelSelect(self, event): self.aux_send_to_server(comm_s) if self.threeClickCount == 4: self.threeClickCount = 0 + self.threeClickSignal.emit(0) self.click3Button.setStyleSheet("background-color: None") return @@ -5015,8 +5053,8 @@ def ringCurrentChangedCB(self, value=None, char_value=None, **kw): self.ringCurrentSignal.emit(ringCurrentVal) def beamAvailableChangedCB(self, value=None, char_value=None, **kw): - beamAvailableVal = value - self.beamAvailableSignal.emit(beamAvailableVal) + threeClickVal = value + self.threeClickSignal.emit(threeClickVal) def sampleExposedChangedCB(self, value=None, char_value=None, **kw): sampleExposedVal = value @@ -5341,7 +5379,7 @@ def initCallbacks(self): self.cryostreamTemp_pv.add_callback(self.cryostreamTempChangedCB) self.ringCurrentSignal.connect(self.processRingCurrent) self.ringCurrent_pv.add_callback(self.ringCurrentChangedCB) - self.beamAvailableSignal.connect(self.processBeamAvailable) + self.threeClickSignal.connect(self.processThreeClickCentering) self.beamAvailable_pv.add_callback(self.beamAvailableChangedCB) self.sampleExposedSignal.connect(self.processSampleExposed) self.sampleExposed_pv.add_callback(self.sampleExposedChangedCB) From a442c57feba0e47ddd686ee077b021204ec38265 Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Mon, 20 Nov 2023 22:47:17 -0500 Subject: [PATCH 2/9] Update control_main.py --- gui/control_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/control_main.py b/gui/control_main.py index ab31827d..551dfa45 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -139,7 +139,7 @@ class ControlMain(QtWidgets.QMainWindow): fastShutterSignal = QtCore.Signal(float) gripTempSignal = QtCore.Signal(float) ringCurrentSignal = QtCore.Signal(float) - threeClickSignal = QtCore.Signal(float) + threeClickSignal = QtCore.Signal(str) sampleExposedSignal = QtCore.Signal(float) sampMoveSignal = QtCore.Signal(int, str) roiChangeSignal = QtCore.Signal(int, str) From f2471fcdebaff76782b75adb457b4e200be762af Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Mon, 20 Nov 2023 22:55:04 -0500 Subject: [PATCH 3/9] Update control_main.py --- gui/control_main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index 551dfa45..b75f5f33 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -2248,7 +2248,7 @@ def processRingCurrent(self, ringCurrentVal): function is processThreClickCentering ''' def processThreeClickCentering(self, beamAvailVal): - if int(beamAvailVal) == 0: + if beamAvailVal == '0': self.beamAvailLabel.setText("Beam Available") self.beamAvailLabel.setStyleSheet("background-color: #99FF66;") else: @@ -3858,7 +3858,7 @@ def pixelSelect(self, event): self.md2.centring_click.put(f"{correctedC2C_x} {correctedC2C_y}") if self.threeClickCount == 4: self.threeClickCount = 0 - self.threeClickSignal.emit(0) + self.threeClickSignal.emit('0') self.click3Button.setStyleSheet("background-color: None") return else: @@ -3869,7 +3869,7 @@ def pixelSelect(self, event): self.aux_send_to_server(comm_s) if self.threeClickCount == 4: self.threeClickCount = 0 - self.threeClickSignal.emit(0) + self.threeClickSignal.emit('0') self.click3Button.setStyleSheet("background-color: None") return From a74ba493bd75247d3d1c4153d9955a5b646c8a44 Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Mon, 20 Nov 2023 23:26:35 -0500 Subject: [PATCH 4/9] adding sleep time --- gui/control_main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gui/control_main.py b/gui/control_main.py index b75f5f33..2b617361 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -3086,6 +3086,7 @@ def center3LoopCB(self): logger.info("3-click center loop") self.threeClickCount = 1 self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) + time.sleep(0.02) self.click3Button.setStyleSheet("background-color: yellow") if(daq_utils.exporter_enabled): self.md2.exporter.cmd("startManualSampleCentring", "") @@ -3844,6 +3845,7 @@ def pixelSelect(self, event): if self.threeClickCount > 0: # 3-click centering self.threeClickCount = self.threeClickCount + 1 self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) + time.sleep(0.02) if daq_utils.exporter_enabled: correctedC2C_x = x_click + ((daq_utils.screenPixX/2) - (self.centerMarker.x() + self.centerMarkerCharOffsetX)) correctedC2C_y = y_click + ((daq_utils.screenPixY/2) - (self.centerMarker.y() + self.centerMarkerCharOffsetY)) From 77169f67ed7ae78383ba7279febe62bc96381ebc Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Mon, 20 Nov 2023 23:32:18 -0500 Subject: [PATCH 5/9] longer sleep time and adding print statement --- gui/control_main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index 2b617361..059ef675 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -3086,7 +3086,7 @@ def center3LoopCB(self): logger.info("3-click center loop") self.threeClickCount = 1 self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) - time.sleep(0.02) + time.sleep(0.3) self.click3Button.setStyleSheet("background-color: yellow") if(daq_utils.exporter_enabled): self.md2.exporter.cmd("startManualSampleCentring", "") @@ -3845,7 +3845,8 @@ def pixelSelect(self, event): if self.threeClickCount > 0: # 3-click centering self.threeClickCount = self.threeClickCount + 1 self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) - time.sleep(0.02) + time.sleep(0.3) + print('sleeping for 0.3 seconds') if daq_utils.exporter_enabled: correctedC2C_x = x_click + ((daq_utils.screenPixX/2) - (self.centerMarker.x() + self.centerMarkerCharOffsetX)) correctedC2C_y = y_click + ((daq_utils.screenPixY/2) - (self.centerMarker.y() + self.centerMarkerCharOffsetY)) From 15b258400af1e43bb03d8339c8dffeddc4a179c2 Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:39:08 -0500 Subject: [PATCH 6/9] editing Control_main to call exporter command and wait in three click centering --- gui/control_main.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index 059ef675..3f32af2c 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -3845,8 +3845,8 @@ def pixelSelect(self, event): if self.threeClickCount > 0: # 3-click centering self.threeClickCount = self.threeClickCount + 1 self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) - time.sleep(0.3) - print('sleeping for 0.3 seconds') + + if daq_utils.exporter_enabled: correctedC2C_x = x_click + ((daq_utils.screenPixX/2) - (self.centerMarker.x() + self.centerMarkerCharOffsetX)) correctedC2C_y = y_click + ((daq_utils.screenPixY/2) - (self.centerMarker.y() + self.centerMarkerCharOffsetY)) @@ -3859,6 +3859,10 @@ def pixelSelect(self, event): correctedC2C_x = correctedC2C_x * scale_x correctedC2C_y = correctedC2C_y * scale_y self.md2.centring_click.put(f"{correctedC2C_x} {correctedC2C_y}") + logger.info('waiting for motor rotation') + time.sleep(0.2) + self.omegaMoveCheck(0.02,'OmegaState') + if self.threeClickCount == 4: self.threeClickCount = 0 self.threeClickSignal.emit('0') @@ -3874,8 +3878,27 @@ def pixelSelect(self, event): self.threeClickCount = 0 self.threeClickSignal.emit('0') self.click3Button.setStyleSheet("background-color: None") + return + ''' + Function to check if MD motors are rotating or not + ''' + def omegaMoveCheck(self, sleeptime,call='OmegaState'): + state = self.md2.exporter.read(call) + while(state == 'Moving'): + time.sleep(sleeptime) + state = self.md2.exporter.read(call) + logger.info('\nIn Moving\n{}\n'.format(state)) + if state == 'Ready': + logger.info('ready for next click') + return state + else: + logger.info('\ndone moving, current state is: {}'.format(state)) + return state + + + def editScreenParamsCB(self): self.screenDefaultsDialog = ScreenDefaultsDialog(self) self.screenDefaultsDialog.show() From 8203bf3dac7f860730c4087dfec5a73e8c8a7551 Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:43:53 -0500 Subject: [PATCH 7/9] Making click not register until motor is ready --- gui/control_main.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index 3f32af2c..3b02e9a0 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -3777,6 +3777,16 @@ def pixelSelect(self, event): y_click = float(event.pos().y()) penGreen = QtGui.QPen(QtCore.Qt.green) penRed = QtGui.QPen(QtCore.Qt.red) + ''' + For three click centering, this if statement checks the omega state of the motor. + This ideally gives feedback on wether the MD2 is in the rotation portion of the three click centering + + ''' + state = self.md2.exporter.read('OmegaState') + if state != 'Ready': + logger.info('waiting for motor rotation') + logger.info('Click not registered') + return if self.vidActionDefineCenterRadio.isChecked(): self.vidActionC2CRadio.setChecked( True @@ -3859,9 +3869,9 @@ def pixelSelect(self, event): correctedC2C_x = correctedC2C_x * scale_x correctedC2C_y = correctedC2C_y * scale_y self.md2.centring_click.put(f"{correctedC2C_x} {correctedC2C_y}") - logger.info('waiting for motor rotation') - time.sleep(0.2) - self.omegaMoveCheck(0.02,'OmegaState') + #logger.info('waiting for motor rotation') + #time.sleep(0.2) + #self.omegaMoveCheck(0.02,'OmegaState') if self.threeClickCount == 4: self.threeClickCount = 0 @@ -3889,7 +3899,7 @@ def omegaMoveCheck(self, sleeptime,call='OmegaState'): while(state == 'Moving'): time.sleep(sleeptime) state = self.md2.exporter.read(call) - logger.info('\nIn Moving\n{}\n'.format(state)) + #logger.info('\nIn Moving\n{}\n'.format(state)) if state == 'Ready': logger.info('ready for next click') return state From 6678c7b75d830a812ce55748ec2e34819baf8b6a Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:02:21 -0500 Subject: [PATCH 8/9] adding line drawing to three click centering --- gui/control_main.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gui/control_main.py b/gui/control_main.py index 3b02e9a0..1058b3c0 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -1012,6 +1012,7 @@ def createSampleTab(self): self.rasterList = [] self.rasterDefList = [] self.polyPointItems = [] + self.threeClickLines = [] self.rasterPoly = None self.measureLine = None self.scene = QtWidgets.QGraphicsScene(0, 0, 640, 512, self) @@ -3086,7 +3087,7 @@ def center3LoopCB(self): logger.info("3-click center loop") self.threeClickCount = 1 self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) - time.sleep(0.3) + #time.sleep(0.3) self.click3Button.setStyleSheet("background-color: yellow") if(daq_utils.exporter_enabled): self.md2.exporter.cmd("startManualSampleCentring", "") @@ -3855,6 +3856,11 @@ def pixelSelect(self, event): if self.threeClickCount > 0: # 3-click centering self.threeClickCount = self.threeClickCount + 1 self.threeClickSignal.emit('{} more clicks'.format(str(4-self.threeClickCount))) + #adding drawing for three click centering + logger.info('Drawing 3 click line {} at x_value: {} and y_value {}'.format(self.threeClickCount, x_click, y_click)) + self.threeClickLines.append( + self.scene.addLine(x_click, 0, x_click, 512, penGreen) + ) if daq_utils.exporter_enabled: @@ -3877,6 +3883,11 @@ def pixelSelect(self, event): self.threeClickCount = 0 self.threeClickSignal.emit('0') self.click3Button.setStyleSheet("background-color: None") + #removing drawing for three click centering + logger.info('Removing 3 click lines') + for i in range(len(self.threeClickLines)): + self.scene.removeItem(self.threeClickLines[i]) + self.threeClickLines = [] return else: comm_s = f'center_on_click({correctedC2C_x},{correctedC2C_y},{fov["x"]},{fov["y"]},source="screen",jog=90,viewangle={current_viewangle})' @@ -3888,6 +3899,12 @@ def pixelSelect(self, event): self.threeClickCount = 0 self.threeClickSignal.emit('0') self.click3Button.setStyleSheet("background-color: None") + #removing drawing for three cick centering + logger.info('Removing 3 click lines') + for i in range(len(self.threeClickLines)): + self.scene.removeItem(self.threeClickLines[i]) + logger.info('Removed line {}'.format(i)) + self.threeClickLines = [] return From 77d5b6c5ccdfaf43d3b13349ce5dd21ec147c76a Mon Sep 17 00:00:00 2001 From: NYSBC-Rudra <133771854+NYSBC-Rudra@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:07:59 -0400 Subject: [PATCH 9/9] Update control_main.py --- gui/control_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/control_main.py b/gui/control_main.py index 1058b3c0..395d6edf 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -1438,7 +1438,7 @@ def createSampleTab(self): self.beamAvailLabel = QtWidgets.QLabel("Beam Available") self.beamAvailLabel.setStyleSheet("background-color: #99FF66;") else: - self.beamAvailLabel = QtWidgets.QLabel("No Beam") + self.beamAvailLabel = QtWidgets.QLabel("Waiting for Three Click") self.beamAvailLabel.setStyleSheet("background-color: red;") sampleExposed = self.sampleExposed_pv.get() if sampleExposed: