mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
refactor: migrate to use just np.array for tracking position, only latest N points are being dimmed.
This commit is contained in:
@ -20,8 +20,9 @@ class MotorApp(QWidget):
|
|||||||
uic.loadUi(os.path.join(current_path, "motor_controller.ui"), self)
|
uic.loadUi(os.path.join(current_path, "motor_controller.ui"), self)
|
||||||
|
|
||||||
self.limit_x, self.limit_y = None, None
|
self.limit_x, self.limit_y = None, None
|
||||||
|
|
||||||
# Coordinates tracking
|
# Coordinates tracking
|
||||||
self.motor_positions = []
|
self.motor_positions = np.array([])
|
||||||
|
|
||||||
# QThread for motor movement + signals
|
# QThread for motor movement + signals
|
||||||
self.motor_thread = MotorControl()
|
self.motor_thread = MotorControl()
|
||||||
@ -184,15 +185,13 @@ class MotorApp(QWidget):
|
|||||||
(map_width, map_height), self.background_value, dtype=np.float32
|
(map_width, map_height), self.background_value, dtype=np.float32
|
||||||
)
|
)
|
||||||
self.limit_map.setImage(self.limit_map_data)
|
self.limit_map.setImage(self.limit_map_data)
|
||||||
# # Set the initial position on the map
|
|
||||||
init_pos = self.motor_thread.retrieve_coordinates()
|
|
||||||
init_brush = pg.mkBrush(255, 255, 255, 255)
|
|
||||||
self.motor_positions.append({"pos": init_pos, "brush": init_brush})
|
|
||||||
|
|
||||||
self.motor_map.setData(
|
# Set the initial position on the map
|
||||||
pos=[point["pos"] for point in self.motor_positions],
|
init_pos = self.motor_thread.retrieve_coordinates()
|
||||||
brush=[point["brush"] for point in self.motor_positions],
|
self.motor_positions = np.array([init_pos])
|
||||||
)
|
self.brushes = [pg.mkBrush(255, 255, 255, 255)]
|
||||||
|
|
||||||
|
self.motor_map.setData(pos=self.motor_positions, brush=self.brushes)
|
||||||
|
|
||||||
# Translate and scale the image item to match the motor coordinates
|
# Translate and scale the image item to match the motor coordinates
|
||||||
self.tr = QtGui.QTransform()
|
self.tr = QtGui.QTransform()
|
||||||
@ -203,19 +202,18 @@ class MotorApp(QWidget):
|
|||||||
# Update label
|
# Update label
|
||||||
self.label_coorditanes.setText(f"Motor position: ({x:.2f}, {y:.2f})")
|
self.label_coorditanes.setText(f"Motor position: ({x:.2f}, {y:.2f})")
|
||||||
|
|
||||||
# Dim previous points
|
# Determine brushes based on position in the array
|
||||||
last_brush = self.motor_positions[-1]["brush"].color().getRgb()
|
self.brushes = [pg.mkBrush(50, 50, 50, 255)] * len(self.motor_positions)
|
||||||
dimmer_brush = tuple(max(int(0.8 * c), 50) for c in last_brush[:3]) + (255,)
|
for i in range(1, min(6, len(self.motor_positions) + 1)):
|
||||||
self.motor_positions[-1]["brush"] = pg.mkBrush(dimmer_brush)
|
brightness = max(50, 255 - 20 * (i - 1))
|
||||||
|
self.brushes[-i] = pg.mkBrush(brightness, brightness, brightness, 255)
|
||||||
|
|
||||||
# Add new point with full brightness
|
# Add new point with full brightness
|
||||||
new_pos = (x, y)
|
new_pos = (x, y)
|
||||||
new_brush = pg.mkBrush(255, 255, 255, 255)
|
self.motor_positions = np.vstack((self.motor_positions, new_pos))
|
||||||
self.motor_positions.append({"pos": new_pos, "brush": new_brush})
|
self.brushes.append(pg.mkBrush(255, 255, 255, 255))
|
||||||
self.motor_map.setData(
|
|
||||||
pos=[point["pos"] for point in self.motor_positions],
|
self.motor_map.setData(pos=self.motor_positions, brush=self.brushes)
|
||||||
brush=[point["brush"] for point in self.motor_positions],
|
|
||||||
)
|
|
||||||
|
|
||||||
def update_all_motor_limits(
|
def update_all_motor_limits(
|
||||||
self, x_limit: list = None, y_limit: list = None
|
self, x_limit: list = None, y_limit: list = None
|
||||||
|
Reference in New Issue
Block a user