-
Notifications
You must be signed in to change notification settings - Fork 42
Vortran laser support #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Alpaca233
wants to merge
10
commits into
Cephla-Lab:master
Choose a base branch
from
Alpaca233:vortran
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
10bb248
update config file
Alpaca233 302bf70
change naming to better organize light source files
Alpaca233 3ee5035
initial commit
Alpaca233 f24e1be
product id
Alpaca233 15829a5
temp
Alpaca233 21db131
Vortran laser integration
Alpaca233 11b71d9
VersaLase instructions
Alpaca233 5b6c681
add laser SDK GitHub link
Alpaca233 752460c
naming
Alpaca233 6f4eac3
update config file
Alpaca233 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
from laser_sdk import LaserSDK | ||
|
||
from squid.abc import LightSource | ||
from control.lighting import ShutterControlMode, IntensityControlMode | ||
|
||
import squid.logging | ||
|
||
|
||
class VersaLase(LightSource): | ||
def __init__(self, **kwds): | ||
self._log = squid.logging.get_logger(__name__) | ||
|
||
self.sdk = LaserSDK() | ||
self.sdk.discover() | ||
|
||
self.channel_mappings = { | ||
405: None, | ||
470: None, | ||
488: None, | ||
545: None, | ||
550: None, | ||
555: None, | ||
561: None, | ||
638: None, | ||
640: None, | ||
730: None, | ||
735: None, | ||
750: None, | ||
} | ||
|
||
try: | ||
self.initialize() | ||
except Exception as e: | ||
self._log.error(f"Failed to initialize Vortran laser: {e}") | ||
|
||
def initialize(self) -> bool: | ||
""" | ||
Initialize the connection and settings for the Vortran laser. | ||
Returns True if successful, False otherwise. | ||
""" | ||
try: | ||
# Query information about installed lasers | ||
for laser in self.sdk.get_lasers(): | ||
self._log.info(f"Found laser {laser.wavelength}: {laser.max_power}") | ||
laser.disable() | ||
if laser.wavelength == 405: | ||
self.channel_mappings[405] = laser.id | ||
elif laser.wavelength == 488: | ||
self.channel_mappings[470] = laser.id | ||
self.channel_mappings[488] = laser.id | ||
elif laser.wavelength == 545: | ||
self.channel_mappings[545] = laser.id | ||
self.channel_mappings[550] = laser.id | ||
self.channel_mappings[555] = laser.id | ||
self.channel_mappings[561] = laser.id | ||
elif laser.wavelength == 638: | ||
self.channel_mappings[638] = laser.id | ||
self.channel_mappings[640] = laser.id | ||
return True | ||
|
||
except Exception as e: | ||
self._log.error(f"Initialization failed: {e}") | ||
return False | ||
|
||
def set_intensity_control_mode(self, mode: IntensityControlMode): | ||
""" | ||
Set intensity control mode. Only software intensity control is supported for Vortran laser. | ||
|
||
Args: | ||
mode: IntensityControlMode.Software or IntensityControlMode.External | ||
""" | ||
self._log.debug("Only software intensity control is supported for Vortran laser") | ||
pass | ||
|
||
def get_intensity_control_mode(self) -> IntensityControlMode: | ||
""" | ||
Get current intensity control mode. Only software intensity control is supported for Vortran laser. | ||
|
||
Returns: | ||
IntensityControlMode enum value | ||
""" | ||
return IntensityControlMode.Software | ||
|
||
def set_shutter_control_mode(self, mode: ShutterControlMode): | ||
""" | ||
Set shutter control mode for all lasers. | ||
|
||
Args: | ||
mode: ShutterControlMode enum | ||
""" | ||
for laser in self.sdk.get_lasers(): | ||
laser.set_digital_mode(mode == ShutterControlMode.TTL) | ||
|
||
self.shutter_mode = mode | ||
|
||
def get_shutter_control_mode(self) -> ShutterControlMode: | ||
""" | ||
Get current shutter control mode. | ||
|
||
Returns: | ||
ShutterControlMode enum value | ||
""" | ||
# The lasers in the VersaLase may have different shutter control states. | ||
# We call set_shutter_control_mode() on initialize so they should all be the same. | ||
# Raise an error here if they are not. | ||
digital_mode = None | ||
for laser in self.sdk.get_lasers(): | ||
if digital_mode is None: | ||
digital_mode = laser.digital_mode | ||
elif digital_mode != laser.digital_mode: | ||
raise ValueError("Laser shutter control modes are not consistent") | ||
if digital_mode is None: | ||
raise ValueError("No lasers found") | ||
|
||
return ShutterControlMode.TTL if digital_mode else ShutterControlMode.Software | ||
|
||
def set_shutter_state(self, channel: int, state: bool): | ||
""" | ||
Turn a specific channel on or off. | ||
|
||
Args: | ||
channel: Channel ID (letter or wavelength) | ||
state: True to turn on, False to turn off | ||
""" | ||
laser = self.sdk.get_laser_by_id(self.channel_mappings[channel]) | ||
laser.enable(state) | ||
|
||
def get_shutter_state(self, channel: int) -> bool: | ||
""" | ||
Get the current shutter state of a specific channel. | ||
|
||
Args: | ||
channel: Channel ID (letter or wavelength) | ||
|
||
Returns: | ||
bool: True if channel is on, False if off | ||
""" | ||
laser = self.sdk.get_laser_by_id(self.channel_mappings[channel]) | ||
return laser.get_emission_status() | ||
|
||
def set_intensity(self, channel: int, intensity: float): | ||
""" | ||
Set the intensity for a specific channel. | ||
|
||
Args: | ||
channel: Channel ID (letter or wavelength) | ||
intensity: Intensity value (0-100 percent) | ||
""" | ||
laser = self.sdk.get_laser_by_id(self.channel_mappings[channel]) | ||
laser.set_power(laser.max_power * intensity / 100.0) | ||
|
||
def get_intensity(self, channel: int) -> float: | ||
""" | ||
Get the current intensity of a specific channel. | ||
|
||
Args: | ||
channel: Channel ID (letter or wavelength) | ||
|
||
Returns: | ||
float: Current intensity value (0-100 percent) | ||
""" | ||
# For Vortran laser, we are able to get the actual intensity of the lasers. | ||
# To keep consistency with other light sources, we return the set power/intensity here. | ||
laser = self.sdk.get_laser_by_id(self.channel_mappings[channel]) | ||
laser_info = laser.get_op2() | ||
return laser_info["LaserSetPower"] / laser.max_power * 100.0 | ||
|
||
def shut_down(self): | ||
"""Safely shut down the Vortran laser.""" | ||
for laser in self.sdk.get_lasers(): | ||
laser.disable() | ||
laser.disconnect() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The set_intensity_control_mode method is not implemented and only contains a debug log and pass. Consider implementing the functionality or raising a NotImplementedError to clearly indicate that this mode is unsupported.
Copilot uses AI. Check for mistakes.