mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat: motor_example.py created, motor samx and samy can be moved by buttons
This commit is contained in:
160
bec_widgets/examples/motor_movement/motor_controller.ui
Normal file
160
bec_widgets/examples/motor_movement/motor_controller.ui
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Form</class>
|
||||||
|
<widget class="QWidget" name="Form">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>266</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Motor Controller</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3" columnstretch="1,1,1" columnminimumwidth="0,0,0">
|
||||||
|
<item row="4" column="2">
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>Motor Limits</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>+ samy</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QSpinBox" name="spinBox_samxN"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Update</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="2">
|
||||||
|
<widget class="QSpinBox" name="spinBox_samyN"/>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="2">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>- samy</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QSpinBox" name="spinBox_samyP"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="3">
|
||||||
|
<widget class="QSpinBox" name="spinBox_samxP"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="3">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>- samx</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>- samx</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="GraphicsLayoutWidget" name="glw">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QGroupBox" name="motorControl">
|
||||||
|
<property name="title">
|
||||||
|
<string>Motor Controls</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSpinBox" name="spinBox_step">
|
||||||
|
<property name="value">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QToolButton" name="toolButton_left">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="arrowType">
|
||||||
|
<enum>Qt::LeftArrow</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QToolButton" name="toolButton_up">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="arrowType">
|
||||||
|
<enum>Qt::UpArrow</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QToolButton" name="toolButton_down">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="arrowType">
|
||||||
|
<enum>Qt::DownArrow</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QToolButton" name="toolButton_right">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="arrowType">
|
||||||
|
<enum>Qt::RightArrow</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="label_status">
|
||||||
|
<property name="text">
|
||||||
|
<string>Motor Status</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>GraphicsLayoutWidget</class>
|
||||||
|
<extends>QGraphicsView</extends>
|
||||||
|
<header>pyqtgraph.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
68
bec_widgets/examples/motor_movement/motor_example.py
Normal file
68
bec_widgets/examples/motor_movement/motor_example.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from PyQt5.QtCore import pyqtSignal
|
||||||
|
from PyQt5.QtWidgets import QApplication, QWidget
|
||||||
|
from pyqtgraph.Qt import QtCore, QtWidgets, uic
|
||||||
|
import pyqtgraph as pg
|
||||||
|
|
||||||
|
|
||||||
|
class MotorApp(QWidget):
|
||||||
|
motor_position = pyqtSignal(float) # TODO hook to motor position update
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
current_path = os.path.dirname(__file__)
|
||||||
|
uic.loadUi(os.path.join(current_path, "motor_controller.ui"), self)
|
||||||
|
|
||||||
|
# UI
|
||||||
|
|
||||||
|
self.init_ui()
|
||||||
|
|
||||||
|
def init_ui(self):
|
||||||
|
"""Setup all ui elements"""
|
||||||
|
##########################
|
||||||
|
# 2D Plot
|
||||||
|
##########################
|
||||||
|
|
||||||
|
self.label_coorditanes = self.glw.addLabel("Current Motor Coordinates", row=0, col=0)
|
||||||
|
self.plot_map = self.glw.addPlot(row=1, col=0)
|
||||||
|
self.image_map = pg.ImageItem()
|
||||||
|
self.plot_map.addItem(self.image_map)
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# Signals
|
||||||
|
##########################
|
||||||
|
# Buttons - Motor Movement
|
||||||
|
self.toolButton_right.clicked.connect(
|
||||||
|
lambda: self.move_motor(dev.samx, self.spinBox_step.value())
|
||||||
|
)
|
||||||
|
self.toolButton_left.clicked.connect(
|
||||||
|
lambda: self.move_motor(dev.samx, -self.spinBox_step.value())
|
||||||
|
)
|
||||||
|
self.toolButton_up.clicked.connect(
|
||||||
|
lambda: self.move_motor(dev.samy, self.spinBox_step.value())
|
||||||
|
)
|
||||||
|
self.toolButton_down.clicked.connect(
|
||||||
|
lambda: self.move_motor(dev.samy, -self.spinBox_step.value())
|
||||||
|
)
|
||||||
|
|
||||||
|
# self.toolButton_left.clicked.connect(lambda: print(self.client))
|
||||||
|
|
||||||
|
def move_motor(self, motor, value: float) -> None:
|
||||||
|
scans.mv(motor, value, relative=True)
|
||||||
|
self.motor_position.emit(motor.position)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from bec_widgets.bec_dispatcher import bec_dispatcher
|
||||||
|
|
||||||
|
# Client initialization
|
||||||
|
client = bec_dispatcher.client
|
||||||
|
client.start()
|
||||||
|
dev = client.device_manager.devices
|
||||||
|
scans = client.scans
|
||||||
|
|
||||||
|
app = QApplication([])
|
||||||
|
window = MotorApp()
|
||||||
|
window.show()
|
||||||
|
app.exec_()
|
@ -12,7 +12,8 @@ from PyQt5.QtWidgets import (
|
|||||||
)
|
)
|
||||||
from pyqtgraph import mkPen
|
from pyqtgraph import mkPen
|
||||||
from pyqtgraph.Qt import QtCore
|
from pyqtgraph.Qt import QtCore
|
||||||
from crosshair import Crosshair
|
from bec_widgets.qt_utils import Crosshair
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExampleApp(QWidget):
|
class ExampleApp(QWidget):
|
Reference in New Issue
Block a user