diff --git a/bec_widgets/examples/motor_movement/motor_controller.ui b/bec_widgets/examples/motor_movement/motor_controller.ui index 325ecbc0..66c42c82 100644 --- a/bec_widgets/examples/motor_movement/motor_controller.ui +++ b/bec_widgets/examples/motor_movement/motor_controller.ui @@ -7,13 +7,13 @@ 0 0 1129 - 542 + 550 Motor Controller - + @@ -190,7 +190,17 @@ - + + + 0.100000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + @@ -246,10 +256,30 @@ - + + + -500.000000000000000 + + + 500.000000000000000 + + + 0.100000000000000 + + - + + + -500.000000000000000 + + + 500.000000000000000 + + + 0.100000000000000 + + @@ -272,7 +302,7 @@ true - 1 + 0 @@ -447,50 +477,6 @@ Motor Config - - - - Qt::AlignCenter - - - 500 - - - - - - - Update Frequency - - - - - - - false - - - Tolerance - - - - - - - Y - - - Qt::AlignCenter - - - - - - - Speed - - - @@ -501,46 +487,6 @@ - - - - false - - - Decimal Precision - - - - - - - false - - - Qt::AlignCenter - - - - - - - Qt::AlignCenter - - - 1000 - - - - - - - X - - - Qt::AlignCenter - - - @@ -551,16 +497,23 @@ - - - - false + + + + X Qt::AlignCenter + + + + Speed + + + @@ -581,6 +534,99 @@ + + + + Qt::AlignCenter + + + 1000 + + + + + + + Y + + + Qt::AlignCenter + + + + + + + Max Points + + + + + + + Qt::AlignCenter + + + 10 + + + 1000 + + + 10 + + + 100 + + + + + + + Update Frequency + + + + + + + false + + + Qt::AlignCenter + + + + + + + false + + + Tolerance + + + + + + + false + + + Qt::AlignCenter + + + + + + + Qt::AlignCenter + + + 500 + + + @@ -588,6 +634,65 @@ + + + + false + + + Decimal Precision + + + + + + + N dim + + + + + + + Qt::AlignCenter + + + 100 + + + 10000 + + + 100 + + + 5000 + + + + + + + Scatter Size + + + + + + + Qt::AlignCenter + + + 1 + + + 15 + + + 5 + + + diff --git a/bec_widgets/examples/motor_movement/motor_example.py b/bec_widgets/examples/motor_movement/motor_example.py index 2f8129bd..fe2a8bb6 100644 --- a/bec_widgets/examples/motor_movement/motor_example.py +++ b/bec_widgets/examples/motor_movement/motor_example.py @@ -44,6 +44,7 @@ class MotorApp(QWidget): self.motor_positions = np.array([]) self.max_points = 5000 # Maximum number of points to keep self.num_dim_points = 15 # Number of points to dim gradually + self.scatter_size = 5 # QThread for motor movement + signals self.motor_thread.motors_loaded.connect(self.get_available_motors) @@ -144,6 +145,18 @@ class MotorApp(QWidget): self.enable_motor_controls(False) self.motor_thread.move_relative(motor, value) + def update_plot_setting(self, max_points, num_dim_points, scatter_size): + self.max_points = max_points + self.num_dim_points = num_dim_points + self.scatter_size = scatter_size + + for spinBox in ( + self.spinBox_max_points, + self.spinBox_num_dim_points, + self.spinBox_scatter_size, + ): + spinBox.setStyleSheet("") + def init_ui(self) -> None: """Setup all ui elements""" # TODO can be separated to multiple functions @@ -157,7 +170,7 @@ class MotorApp(QWidget): self.limit_map = pg.ImageItem() self.plot_map.addItem(self.limit_map) self.motor_map = pg.ScatterPlotItem( - size=2, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 255) + size=self.scatter_size, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 255) ) self.plot_map.addItem(self.motor_map) self.plot_map.showGrid(x=True, y=True) @@ -206,7 +219,7 @@ class MotorApp(QWidget): self.pushButton_stop.clicked.connect(self.motor_thread.stop_movement) ########################## - # Motor limits signals + # Motor Configs ########################## # SpinBoxes - Motor Limits #TODO make spinboxes own limits updated, currently is [-1000, 1000] @@ -229,7 +242,18 @@ class MotorApp(QWidget): lambda: self.param_changed(self.spinBox_update_frequency_y) ) - # Confog updates + # SpinBoxes - Max Points and N Dim Points + self.spinBox_max_points.valueChanged.connect( + lambda: self.param_changed(self.spinBox_max_points) + ) + self.spinBox_num_dim_points.valueChanged.connect( + lambda: self.param_changed(self.spinBox_num_dim_points) + ) + self.spinBox_scatter_size.valueChanged.connect( + lambda: self.param_changed(self.spinBox_scatter_size) + ) + + # Config updates self.pushButton_updateLimits.clicked.connect( lambda: self.update_all_motor_limits( x_limit=[self.spinBox_x_min.value(), self.spinBox_x_max.value()], @@ -237,6 +261,14 @@ class MotorApp(QWidget): ) ) + self.pushButton_update_config.clicked.connect( + lambda: self.update_plot_setting( + max_points=self.spinBox_max_points.value(), + num_dim_points=self.spinBox_num_dim_points.value(), + scatter_size=self.spinBox_scatter_size.value(), + ) + ) + self.pushButton_update_config.clicked.connect( lambda: self.update_all_config( speed=[self.spinBox_speed_x.value(), self.spinBox_speed_y.value()], @@ -316,13 +348,17 @@ class MotorApp(QWidget): # Determine brushes based on position in the array self.brushes = [pg.mkBrush(50, 50, 50, 255)] * len(self.motor_positions) + + # Calculate the decrement step based on self.num_dim_points + decrement_step = (255 - 50) / self.num_dim_points + for i in range(1, min(self.num_dim_points + 1, len(self.motor_positions) + 1)): - brightness = max(50, 255 - 20 * (i - 1)) + brightness = max(50, 255 - decrement_step * (i - 1)) self.brushes[-i] = pg.mkBrush(brightness, brightness, brightness, 255) self.brushes[-1] = pg.mkBrush(255, 255, 255, 255) # Newest point is always full brightness - self.motor_map.setData(pos=self.motor_positions, brush=self.brushes) + self.motor_map.setData(pos=self.motor_positions, brush=self.brushes, size=self.scatter_size) def update_all_motor_limits(self, x_limit: list = None, y_limit: list = None) -> None: self.motor_thread.update_all_motor_limits(x_limit=x_limit, y_limit=y_limit)