Skip to content

Commit

Permalink
adding partial laser controls with gui
Browse files Browse the repository at this point in the history
  • Loading branch information
edyoshikun committed Jan 25, 2024
1 parent 2879bce commit abd9c24
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 31 deletions.
6 changes: 2 additions & 4 deletions copylot/assemblies/photom/demo/photom_VIS_config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
lasers:
- name: laser_1
power: 50
- name: laser_2
power: 30
- name: laser_405
COM_port: COM7

mirrors:
- name: mirror_1_VIS
Expand Down
64 changes: 44 additions & 20 deletions copylot/assemblies/photom/demo/photom_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
# DEMO_MODE = True
DEMO_MODE = False


# TODO fix the right click releaser
# TODO: deal with the logic when clicking calibrate. Mirror dropdown
# TODO: update the mock laser and mirror
# TODO: replace the entry boxes tos et the laser powers


class LaserWidget(QWidget):
Expand All @@ -41,28 +43,36 @@ def __init__(self, laser):
self.laser = laser

self.emission_state = 0 # 0 = off, 1 = on
self.emission_delay = 0.0

self._curr_power = 0.0
self._slider_decimal = 1

self.initializer_laser()
self.initialize_UI()

def initializer_laser(self):
self.laser.toggle_emission = self.emission_state
self.laser.power = self._curr_power
self.laser.emission_delay = self.emission_delay

def initialize_UI(self):
layout = QVBoxLayout()

self.laser_label = QLabel(self.laser.name)
layout.addWidget(self.laser_label)

self.laser_power_slider = QSlider(Qt.Horizontal)
self.laser_power_slider = DoubleSlider(
orientation=Qt.Horizontal, decimals=self._slider_decimal
)
self.laser_power_slider.setMinimum(0)
self.laser_power_slider.setMaximum(100)
self.laser_power_slider.setValue(self.laser.laser_power)
self.laser_power_slider.setValue(self.laser.power)
self.laser_power_slider.valueChanged.connect(self.update_power)
layout.addWidget(self.laser_power_slider)

# Add a QLabel to display the power value
self.power_label = QLabel(f"Power: {self.laser.laser_power}")
self.power_label = QLabel(f"Power: {self._curr_power} %")
layout.addWidget(self.power_label)

self.laser_toggle_button = QPushButton("Toggle")
Expand All @@ -83,9 +93,10 @@ def toggle_laser(self):
self.laser_toggle_button.setStyleSheet("background-color: green")

def update_power(self, value):
self.laser.laser_power = value
self.laser.power = value / (10**self._slider_decimal)
self._curr_power = self.laser.power
# Update the QLabel with the new power value
self.power_label.setText(f"Power: {value}")
self.power_label.setText(f"Power: {self._curr_power} %")


# TODO: connect widget to actual abstract mirror calls
Expand Down Expand Up @@ -654,15 +665,27 @@ def eventFilter(self, source, event):
self._move_marker_and_update_sliders()
elif event.buttons() == Qt.RightButton:
self._right_click_hold = True
self.photom_controls.photom_assembly.laser[0].toggle_emission = True
print('right button pressed')
elif event.type() == QMouseEvent.MouseButtonRelease:
print('mouse button released')
if event.buttons() == Qt.LeftButton:
self._left_click_hold = False
print('left button released')
elif event.buttons() == Qt.RightButton:
self._right_click_hold = False
print('right button released')
if self.calibration_mode:
if event.buttons() == Qt.LeftButton:
self._left_click_hold = False
print('left button released')
elif event.buttons() == Qt.RightButton:
self._right_click_hold = False
print('right button released')
else:
print('mouse button released')
if event.buttons() == Qt.LeftButton:
self._left_click_hold = False
print('left button released')
elif event.buttons() == Qt.RightButton:
print('right button released')
self._right_click_hold = False
self.photom_controls.photom_assembly.laser[
0
].toggle_emission = False

return super(LaserMarkerWindow, self).eventFilter(source, event)

Expand Down Expand Up @@ -714,21 +737,22 @@ def display_marker_center(self, marker, coords=None):
Mirror = MockMirror

else:
# NOTE: These are the actual classes that will be used in the photom assembly
# from copylot.hardware.lasers.vortran import VortranLaser as Laser
# TODO: remove after testing
from copylot.assemblies.photom.photom_mock_devices import MockLaser, MockMirror

Laser = MockLaser
from copylot.hardware.mirrors.optotune.mirror import OptoMirror as Mirror
from copylot.hardware.lasers.vortran.vortran import VortranLaser as Laser

config_path = r"./copylot/assemblies/photom/demo/photom_VIS_config.yml"

# TODO: this should be a function that parses the config_file and returns the photom_assembly
# Load the config file and parse it
with open(config_path, "r") as config_file:
config = yaml.load(config_file, Loader=yaml.FullLoader)
lasers = [Laser(**laser_data) for laser_data in config["lasers"]]
lasers = [
Laser(
name=laser_data["name"],
port=laser_data["COM_port"],
)
for laser_data in config["lasers"]
]
mirrors = [
Mirror(
name=mirror_data["name"],
Expand Down
21 changes: 14 additions & 7 deletions copylot/hardware/lasers/vortran/vortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class VortranLaser(AbstractLaser):
]
VOLTRAN_CMDS = GLOBAL_CMD + GLOBAL_QUERY + LASER_CMD + LASER_QUERY

def __init__(self, serial_number=None, port=None, baudrate=19200, timeout=1):
def __init__(self, name, serial_number=None, port=None, baudrate=19200, timeout=1):
"""
Wrapper for vortran stradus lasers.
establishes a connection through COM port
Expand All @@ -65,6 +65,7 @@ def __init__(self, serial_number=None, port=None, baudrate=19200, timeout=1):
timeout for write/read in seconds
"""
# Serial Communication
self.name = name
self.port: str = port
self.baudrate: int = baudrate
self.address = None
Expand Down Expand Up @@ -308,15 +309,15 @@ def external_power_control(self, control):
self._ext_power_ctrl = self._write_cmd('EPC', str(control))[0]

@property
def current_control(self):
def current_control_mode(self):
"""
Laser Current Control (0-Max)
"""
self._current_ctrl = self._write_cmd('?LC')[0]
return self._current_ctrl

@current_control.setter
def current_control(self, value):
@current_control_mode.setter
def current_control_mode(self, value):
"""
Laser Current Control (0-Max)
"""
Expand All @@ -337,6 +338,12 @@ def toggle_emission(self, value):
Toggles Laser Emission On and Off
(1 = On, 0 = Off)
"""

if isinstance(value, bool):
value = str(int(value))
elif isinstance(value, int):
value = str(value)

self._toggle_emission = self._write_cmd('LE', value)[0]

def turn_on(self):
Expand All @@ -356,16 +363,16 @@ def turn_off(self):
return self._toggle_emission

@property
def laser_power(self):
def power(self):
"""
Sets the laser power
Requires pulse_mode() to be OFF
"""
self._curr_power = float(self._write_cmd('?LP')[0])
return self._curr_power

@laser_power.setter
def laser_power(self, power: float):
@power.setter
def power(self, power: float):
"""
Sets the laser power
Requires pulse_mode() to be OFF
Expand Down

0 comments on commit abd9c24

Please sign in to comment.