mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat: speed and frequency is retrieved from devices
This commit is contained in:
@ -6,14 +6,14 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1120</width>
|
<width>1129</width>
|
||||||
<height>547</height>
|
<height>542</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Motor Controller</string>
|
<string>Motor Controller</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="7,1,7">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="6,4,6">
|
||||||
<item>
|
<item>
|
||||||
<widget class="GraphicsLayoutWidget" name="glw">
|
<widget class="GraphicsLayoutWidget" name="glw">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
@ -120,13 +120,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
|
|
||||||
<widget class="QSpinBox" name="spinBox_step">
|
|
||||||
<property name="value">
|
|
||||||
<number>5</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="2" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
|
<item row="3" column="2" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
|
||||||
<widget class="QToolButton" name="toolButton_down">
|
<widget class="QToolButton" name="toolButton_down">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -196,6 +189,9 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QDoubleSpinBox" name="spinBox_step"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -250,10 +246,10 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QSpinBox" name="spinBox_absolute_x"/>
|
<widget class="QDoubleSpinBox" name="spinBox_absolute_x"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<widget class="QSpinBox" name="spinBox_absolute_y"/>
|
<widget class="QDoubleSpinBox" name="spinBox_absolute_y"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
@ -276,7 +272,7 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_coordinates">
|
<widget class="QWidget" name="tab_coordinates">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
@ -326,7 +322,7 @@
|
|||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="motorConfig">
|
<widget class="QGroupBox" name="motorLimits">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Motor Limits</string>
|
<string>Motor Limits</string>
|
||||||
</property>
|
</property>
|
||||||
@ -356,6 +352,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
<item row="2" column="2">
|
||||||
<widget class="QSpinBox" name="spinBox_x_max">
|
<widget class="QSpinBox" name="spinBox_x_max">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>-1000</number>
|
<number>-1000</number>
|
||||||
</property>
|
</property>
|
||||||
@ -395,6 +394,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QSpinBox" name="spinBox_x_min">
|
<widget class="QSpinBox" name="spinBox_x_min">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>-1000</number>
|
<number>-1000</number>
|
||||||
</property>
|
</property>
|
||||||
@ -442,19 +444,16 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_2">
|
<widget class="QGroupBox" name="groupBox_2">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Motor config</string>
|
<string>Motor Config</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_5">
|
<layout class="QGridLayout" name="gridLayout_5">
|
||||||
<item row="4" column="1">
|
<item row="2" column="2">
|
||||||
<widget class="QDoubleSpinBox" name="doubleSpinBox"/>
|
<widget class="QSpinBox" name="spinBox_update_frequency_y">
|
||||||
</item>
|
<property name="alignment">
|
||||||
<item row="1" column="1">
|
<set>Qt::AlignCenter</set>
|
||||||
<widget class="QSpinBox" name="spinBox"/>
|
</property>
|
||||||
</item>
|
<property name="maximum">
|
||||||
<item row="4" column="0">
|
<number>500</number>
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Tolerance</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -465,23 +464,23 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="4" column="0">
|
||||||
<widget class="QSpinBox" name="spinBox_2"/>
|
<widget class="QLabel" name="label_3">
|
||||||
</item>
|
<property name="enabled">
|
||||||
<item row="3" column="0">
|
<bool>false</bool>
|
||||||
<widget class="QLabel" name="label_4">
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Decimal Precision</string>
|
<string>Tolerance</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="0" column="2">
|
||||||
<widget class="QSpinBox" name="spinBox_3"/>
|
<widget class="QLabel" name="label_10">
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLabel" name="label_9">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>X</string>
|
<string>Y</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -492,31 +491,102 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="2">
|
<item row="3" column="1">
|
||||||
<widget class="QLabel" name="label_10">
|
<widget class="QSpinBox" name="spinBox_3">
|
||||||
<property name="text">
|
<property name="enabled">
|
||||||
<string>Y</string>
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QCheckBox" name="checkBox">
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>X = Y</string>
|
<string>Decimal Precision</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBox">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<widget class="QSpinBox" name="spinBox_4"/>
|
<widget class="QSpinBox" name="spinBox_speed_y">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>1000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
<item row="0" column="1">
|
||||||
<widget class="QSpinBox" name="spinBox_5"/>
|
<widget class="QLabel" name="label_9">
|
||||||
|
<property name="text">
|
||||||
|
<string>X</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="2">
|
<item row="3" column="2">
|
||||||
<widget class="QSpinBox" name="spinBox_6"/>
|
<widget class="QSpinBox" name="spinBox_6">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="2">
|
<item row="4" column="2">
|
||||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_2"/>
|
<widget class="QDoubleSpinBox" name="doubleSpinBox_2">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSpinBox" name="spinBox_speed_x">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>1000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QSpinBox" name="spinBox_update_frequency_x">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>500</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Update</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -49,6 +49,8 @@ class MotorApp(QWidget):
|
|||||||
self.motor_thread.motors_loaded.connect(self.get_available_motors)
|
self.motor_thread.motors_loaded.connect(self.get_available_motors)
|
||||||
self.motor_thread.motors_selected.connect(self.get_selected_motors)
|
self.motor_thread.motors_selected.connect(self.get_selected_motors)
|
||||||
self.motor_thread.limits_retrieved.connect(self.update_limits)
|
self.motor_thread.limits_retrieved.connect(self.update_limits)
|
||||||
|
self.motor_thread.speed_retrieved.connect(self.update_speed)
|
||||||
|
self.motor_thread.update_frequency_retrieved.connect(self.update_update_frequency)
|
||||||
|
|
||||||
# UI
|
# UI
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
@ -60,6 +62,8 @@ class MotorApp(QWidget):
|
|||||||
def connect_motor(self, motor_x_name: str, motor_y_name: str):
|
def connect_motor(self, motor_x_name: str, motor_y_name: str):
|
||||||
self.motor_thread.connect_motors(motor_x_name, motor_y_name)
|
self.motor_thread.connect_motors(motor_x_name, motor_y_name)
|
||||||
self.motor_thread.retrieve_motor_limits(self.motor_x, self.motor_y)
|
self.motor_thread.retrieve_motor_limits(self.motor_x, self.motor_y)
|
||||||
|
self.motor_thread.retrieve_motor_speed(self.motor_x, self.motor_y)
|
||||||
|
self.motor_thread.retrieve_motor_update_frequency(self.motor_x, self.motor_y)
|
||||||
self.init_motor_map()
|
self.init_motor_map()
|
||||||
|
|
||||||
self.motorControl.setEnabled(True)
|
self.motorControl.setEnabled(True)
|
||||||
@ -102,6 +106,20 @@ class MotorApp(QWidget):
|
|||||||
|
|
||||||
self.init_motor_map() # reinitialize the map with the new limits
|
self.init_motor_map() # reinitialize the map with the new limits
|
||||||
|
|
||||||
|
@pyqtSlot(int, int)
|
||||||
|
def update_speed(self, speed_x, speed_y):
|
||||||
|
self.spinBox_speed_x.setValue(speed_x)
|
||||||
|
self.spinBox_speed_y.setValue(speed_y)
|
||||||
|
for spinBox in (self.spinBox_speed_x, self.spinBox_speed_y):
|
||||||
|
spinBox.setStyleSheet("")
|
||||||
|
|
||||||
|
@pyqtSlot(int, int)
|
||||||
|
def update_update_frequency(self, update_frequency_x, update_frequency_y):
|
||||||
|
self.spinBox_update_frequency_x.setValue(update_frequency_x)
|
||||||
|
self.spinBox_update_frequency_y.setValue(update_frequency_y)
|
||||||
|
for spinBox in (self.spinBox_update_frequency_x, self.spinBox_update_frequency_y):
|
||||||
|
spinBox.setStyleSheet("")
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def enable_motor_control(self):
|
def enable_motor_control(self):
|
||||||
self.motorControl.setEnabled(True)
|
self.motorControl.setEnabled(True)
|
||||||
@ -229,6 +247,8 @@ class MotorApp(QWidget):
|
|||||||
delete_shortcut.activated.connect(self.delete_selected_row)
|
delete_shortcut.activated.connect(self.delete_selected_row)
|
||||||
backspace_shortcut.activated.connect(self.delete_selected_row)
|
backspace_shortcut.activated.connect(self.delete_selected_row)
|
||||||
|
|
||||||
|
# Get speed and update frequency
|
||||||
|
|
||||||
def init_motor_map(self):
|
def init_motor_map(self):
|
||||||
# Get motor limits
|
# Get motor limits
|
||||||
limit_x_min, limit_x_max = self.motor_thread.get_motor_limits(self.motor_x)
|
limit_x_min, limit_x_max = self.motor_thread.get_motor_limits(self.motor_x)
|
||||||
@ -306,8 +326,6 @@ class MotorApp(QWidget):
|
|||||||
|
|
||||||
table.setRowCount(current_row_count + 1)
|
table.setRowCount(current_row_count + 1)
|
||||||
|
|
||||||
# table.insertRow(current_row_count)
|
|
||||||
|
|
||||||
checkBox = QtWidgets.QCheckBox()
|
checkBox = QtWidgets.QCheckBox()
|
||||||
checkBox.setChecked(True)
|
checkBox.setChecked(True)
|
||||||
button = QtWidgets.QPushButton("Go")
|
button = QtWidgets.QPushButton("Go")
|
||||||
@ -363,6 +381,8 @@ class MotorActions(Enum):
|
|||||||
class MotorControl(QThread):
|
class MotorControl(QThread):
|
||||||
coordinates_updated = pyqtSignal(float, float) # Signal to emit current coordinates
|
coordinates_updated = pyqtSignal(float, float) # Signal to emit current coordinates
|
||||||
limits_retrieved = pyqtSignal(list, list) # Signal to emit current limits
|
limits_retrieved = pyqtSignal(list, list) # Signal to emit current limits
|
||||||
|
speed_retrieved = pyqtSignal(int, int) # Signal to emit current speed
|
||||||
|
update_frequency_retrieved = pyqtSignal(int, int) # Signal to emit current update frequency
|
||||||
move_finished = pyqtSignal() # Signal to emit when the move is finished
|
move_finished = pyqtSignal() # Signal to emit when the move is finished
|
||||||
motors_loaded = pyqtSignal(list, list) # Signal to emit when the motors are loaded
|
motors_loaded = pyqtSignal(list, list) # Signal to emit when the motors are loaded
|
||||||
motors_selected = pyqtSignal(object, object) # Signal to emit when the motors are selected
|
motors_selected = pyqtSignal(object, object) # Signal to emit when the motors are selected
|
||||||
@ -437,6 +457,42 @@ class MotorControl(QThread):
|
|||||||
"""Get the limits of a motor"""
|
"""Get the limits of a motor"""
|
||||||
return motor.limits
|
return motor.limits
|
||||||
|
|
||||||
|
def get_motor_config(self, motor) -> dict:
|
||||||
|
"""Get the configuration of a motor""" # TODO at this moment just for speed and update_frequency
|
||||||
|
return motor.get_device_config()
|
||||||
|
|
||||||
|
def get_motor_speed(self, motor) -> float:
|
||||||
|
"""Get the speed of a motor"""
|
||||||
|
return motor.speed
|
||||||
|
|
||||||
|
def set_motor_speed(self, motor, speed: float) -> None:
|
||||||
|
"""Set the speed of a motor"""
|
||||||
|
motor.speed = speed
|
||||||
|
|
||||||
|
def get_motor_update_frequency(self, motor) -> float:
|
||||||
|
"""Get the update frequency of a motor"""
|
||||||
|
return motor.update_frequency
|
||||||
|
|
||||||
|
def set_motor_update_frequency(self, motor, update_frequency: float) -> None:
|
||||||
|
"""Set the update frequency of a motor"""
|
||||||
|
motor.update_frequency = update_frequency
|
||||||
|
|
||||||
|
def retrieve_motor_speed(
|
||||||
|
self, motor_x, motor_y
|
||||||
|
) -> None: # TODO can be migrated to some general config function
|
||||||
|
"""Get the speed of a motor"""
|
||||||
|
speed_x = motor_x.get_device_config()["speed"]
|
||||||
|
speed_y = motor_y.get_device_config()["speed"]
|
||||||
|
self.speed_retrieved.emit(int(speed_x), int(speed_y))
|
||||||
|
|
||||||
|
def retrieve_motor_update_frequency(
|
||||||
|
self, motor_x, motor_y
|
||||||
|
) -> None: # TODO can be migrated to some general config function
|
||||||
|
"""Get the speed of a motor"""
|
||||||
|
update_frequency_x = motor_x.get_device_config()["update_frequency"]
|
||||||
|
update_frequency_y = motor_y.get_device_config()["update_frequency"]
|
||||||
|
self.update_frequency_retrieved.emit(int(update_frequency_x), int(update_frequency_y))
|
||||||
|
|
||||||
def retrieve_motor_limits(self, motor_x, motor_y):
|
def retrieve_motor_limits(self, motor_x, motor_y):
|
||||||
limit_x = self.get_motor_limits(motor_x)
|
limit_x = self.get_motor_limits(motor_x)
|
||||||
limit_y = self.get_motor_limits(motor_y)
|
limit_y = self.get_motor_limits(motor_y)
|
||||||
|
Reference in New Issue
Block a user