mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
feat: speed and frequency is retrieved from devices
This commit is contained in:
@ -6,14 +6,14 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1120</width>
|
||||
<height>547</height>
|
||||
<width>1129</width>
|
||||
<height>542</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Motor Controller</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="7,1,7">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="6,4,6">
|
||||
<item>
|
||||
<widget class="GraphicsLayoutWidget" name="glw">
|
||||
<property name="enabled">
|
||||
@ -120,13 +120,6 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</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">
|
||||
<widget class="QToolButton" name="toolButton_down">
|
||||
<property name="text">
|
||||
@ -196,6 +189,9 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QDoubleSpinBox" name="spinBox_step"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@ -250,10 +246,10 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_absolute_x"/>
|
||||
<widget class="QDoubleSpinBox" name="spinBox_absolute_x"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QSpinBox" name="spinBox_absolute_y"/>
|
||||
<widget class="QDoubleSpinBox" name="spinBox_absolute_y"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@ -276,7 +272,7 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_coordinates">
|
||||
<attribute name="title">
|
||||
@ -326,7 +322,7 @@
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="motorConfig">
|
||||
<widget class="QGroupBox" name="motorLimits">
|
||||
<property name="title">
|
||||
<string>Motor Limits</string>
|
||||
</property>
|
||||
@ -356,6 +352,9 @@
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QSpinBox" name="spinBox_x_max">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-1000</number>
|
||||
</property>
|
||||
@ -395,6 +394,9 @@
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QSpinBox" name="spinBox_x_min">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-1000</number>
|
||||
</property>
|
||||
@ -442,19 +444,16 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Motor config</string>
|
||||
<string>Motor Config</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="4" column="1">
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="spinBox"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Tolerance</string>
|
||||
<item row="2" column="2">
|
||||
<widget class="QSpinBox" name="spinBox_update_frequency_y">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>500</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -465,23 +464,23 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_2"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Decimal Precision</string>
|
||||
<string>Tolerance</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_3"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>X</string>
|
||||
<string>Y</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -492,31 +491,102 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Y</string>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_3">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<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>
|
||||
</widget>
|
||||
</item>
|
||||
<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 row="2" column="2">
|
||||
<widget class="QSpinBox" name="spinBox_5"/>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>X</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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 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>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -49,6 +49,8 @@ class MotorApp(QWidget):
|
||||
self.motor_thread.motors_loaded.connect(self.get_available_motors)
|
||||
self.motor_thread.motors_selected.connect(self.get_selected_motors)
|
||||
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
|
||||
self.init_ui()
|
||||
@ -60,6 +62,8 @@ class MotorApp(QWidget):
|
||||
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.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.motorControl.setEnabled(True)
|
||||
@ -102,6 +106,20 @@ class MotorApp(QWidget):
|
||||
|
||||
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()
|
||||
def enable_motor_control(self):
|
||||
self.motorControl.setEnabled(True)
|
||||
@ -229,6 +247,8 @@ class MotorApp(QWidget):
|
||||
delete_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):
|
||||
# Get motor limits
|
||||
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.insertRow(current_row_count)
|
||||
|
||||
checkBox = QtWidgets.QCheckBox()
|
||||
checkBox.setChecked(True)
|
||||
button = QtWidgets.QPushButton("Go")
|
||||
@ -363,6 +381,8 @@ class MotorActions(Enum):
|
||||
class MotorControl(QThread):
|
||||
coordinates_updated = pyqtSignal(float, float) # Signal to emit current coordinates
|
||||
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
|
||||
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
|
||||
@ -437,6 +457,42 @@ class MotorControl(QThread):
|
||||
"""Get the limits of a motor"""
|
||||
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):
|
||||
limit_x = self.get_motor_limits(motor_x)
|
||||
limit_y = self.get_motor_limits(motor_y)
|
||||
|
Reference in New Issue
Block a user