Skip to content

Commit

Permalink
resolve @astafan8 ’s suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
julienbarrier committed Aug 31, 2023
1 parent f9faf7a commit 1813364
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 85 deletions.
25 changes: 17 additions & 8 deletions qcodes_contrib_drivers/drivers/Thorlabs/KDC101.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Julien Barrier, <[email protected]>
"""
import logging
from typing import Optional

from .private.CC import _Thorlabs_CC

Expand All @@ -15,19 +16,27 @@ class Thorlabs_KDC101(_Thorlabs_CC):
"""Instrument driver for the Thorlabs KDC101 servo motor controller
Args:
name (str): Instrument name.
serial_number (str): Serial number of the device.
simulation (bool): Enables the simulation manager. Defaults to False.
polling (int): Polling rate in ms. Defaults to 200.
home (bool): Sets the device to home state. Defaults to False.
name: Instrument name.
serial_number: Serial number of the device.
dll_path: Path to the kinesis dll for the instrument to use.
dll_dir: Directory in which the kinesis dll are stored.
simulation: Enables the simulation manager.
polling: Polling rate in ms.
home: Sets the device to home state.
"""
def __init__(self,
name: str,
serial_number: str,
dll_path: Optional[str] = None,
dll_dir: Optional[str] = None,
simulation: bool = False,
polling: int = 200,
home: bool = False,
**kwargs):
self._dll_path = 'Thorlabs.MotionControl.KCube.DCServo.dll'
super().__init__(name, serial_number, self._dll_path,
simulation, polling, home, **kwargs)
if dll_path:
self._dll_path = dll_path
else:
self._dll_path = 'Thorlabs.MotionControl.KCube.DCServo.dll'
self._dll_dir: str | None = dll_dir if dll_dir else None
super().__init__(name, serial_number, self._dll_path, self._dll_dir,
simulation, polling, home, **kwargs)
21 changes: 15 additions & 6 deletions qcodes_contrib_drivers/drivers/Thorlabs/KLS1550.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Julien Barrier <[email protected]>, 2023
"""
import logging
from typing import Optional
from .private.LS import _Thorlabs_LS

log = logging.getLogger(__name__)
Expand All @@ -14,17 +15,25 @@ class Thorlabs_KLS1550(_Thorlabs_LS):
"""Instrument driver for the Thorlabs KLS1550
Args:
name (str): Instrument name.
serial_number (str): Serial number of the device.
simulation (bool): Enables the simulation manager. Defaults to False
polling (int): Polling rate in ms. Defaults to 200.
name: Instrument name.
serial_number: Serial number of the device.
dll_path: Path to the kinesis dll for the instrument to use.
dll_dir: Directory in which the kinesis dll are stored.
simulation: Enables the simulation manager.
polling: Polling rate in ms.
"""
def __init__(self,
name: str,
serial_number: str,
dll_path: Optional[str] = None,
dll_dir: Optional[str] = None,
simulation: bool = False,
polling: int = 200,
**kwargs):
self._dll_path = 'Thorlabs. .dll'
super().__init__(name, serial_number, self._dll_path,
if dll_path:
self._dll_path = dll_path
else:
self._dll_path = 'Thorlabs.MotionControl.KCube.LaserSource.dll'
self._dll_dir: str | None = dll_dir if dll_dir else None
super().__init__(name, serial_number, self._dll_path, self._dll_dir,
simulation, polling, **kwargs)
39 changes: 21 additions & 18 deletions qcodes_contrib_drivers/drivers/Thorlabs/PM100D.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import logging
from time import sleep
from typing import Optional, Any
from typing import Any

from qcodes.instrument import VisaInstrument
from qcodes.parameters import Parameter, create_on_off_val_mapping
Expand All @@ -24,19 +24,19 @@ class Thorlab_PM100D(VisaInstrument):
status: beta-version
Args:
name (str): name for the instrument
address (str): Visa Resource name to connect
terminator (str): Visa terminator
timeout (float, optional). Visa timeout. default to 20s
name: name for the instrument
address: Visa Resource name to connect
terminator: Visa terminator
timeout. Visa timeout.
"""
def __init__(self,
name: str,
address: str,
terminator='\n',
terminator: str = '\n',
timeout: float = 20,
**kwargs: Any):
super().__init__(name, address, terminator=terminator, **kwargs)
self._timeout = timeout
super().__init__(name, address, terminator=terminator,
timeout=timeout, **kwargs)

self.averaging = Parameter(
'averaging',
Expand All @@ -53,8 +53,7 @@ def __init__(self,
unit='m',
get_cmd='SENS:CORR:WAV?',
set_cmd='SENS:CORR:WAV {}',
get_parser=lambda val: float(val)/1e9,
set_parser=lambda val: float(val)*1e9,
scale=1e9,
vals=vals.Numbers(185e-9, 25e-6),
instrument=self
)
Expand Down Expand Up @@ -146,18 +145,12 @@ def __init__(self,
unit='m',
get_cmd='CORR:BEAM?',
set_cmd='CORR:BEAM {}',
get_parser=lambda val: float(val)/1e3,
set_parser=lambda val: float(val)*1e3,
scale=1e3,
vals=vals.Numbers(),
instrument=self
)

self.write('STAT:OPER:PTR 512')
sleep(.2)
self.write('STAT:OPER:NTR 0')
sleep(5)
self.ask('STAT:OPER?')
sleep(.2)
self._set_transition_filter(512, 0)
self.averaging(300)
self._set_conf_power()

Expand All @@ -184,3 +177,13 @@ def _get_power(self) -> float:
sleep(.2)
power = self.ask('FETC?')
return float(power)

def _set_transition_filter(self, positive: int, negative: int) -> None:
"""Apply filters
"""
self.write(f'STAT:OPER:PTR {positive}')
sleep(.2)
self.write(f'STAT:OPER:NTR {negative}')
sleep(5)
self.ask('STAT:OPER?') # clear register
sleep(.2)
25 changes: 17 additions & 8 deletions qcodes_contrib_drivers/drivers/Thorlabs/TDC001.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Julien Barrier, <[email protected]>
"""
import logging
from typing import Optional

from .private.CC import _Thorlabs_CC

Expand All @@ -15,20 +16,28 @@ class Thorlabs_TDC001(_Thorlabs_CC):
"""Instrument driver for the Thorlabs TDC001 servo motor controller
Args:
name (str): Instrument name.
serial_number (str): Serial number of the device.
simulation (bool): Enables the simulation manager. Defaults to False.
polling (int): Polling rate in ms. Defaults to 200.
home (bool): Sets the device to home state. Defaults to False.
name: Instrument name.
serial_number: Serial number of the device.
dll_path: Path to the kinesis dll for the instrument to use.
dll_dir: Directory in which the kinesis dll are stored.
simulation: Enables the simulation manager. Defaults to False.
polling: Polling rate in ms. Defaults to 200.
home: Sets the device to home state. Defaults to False.
"""
_CONDITIONS = ['homed', 'moved', 'stopped', 'limit_updated']
def __init__(self,
name: str,
serial_number: str,
dll_path: Optional[str] = None,
dll_dir: Optional[str] = None,
simulation: bool = False,
polling: int = 200,
home: bool = False,
**kwargs):
self._dll_path = 'Thorlabs.MotionControl.TCube.DCServo.dll'
super().__init__(name, serial_number, self._dll_path,
simulation, polling, home, **kwargs)
if dll_path:
self._dll_path = dll_path
else:
self._dll_path = 'Thorlabs.MotionControl.TCube.DCServo.dll'
self._dll_dir: str | None = dll_dir if dll_dir else None
super().__init__(name, serial_number, self._dll_path, self._dll_dir,
simulation, polling, home, **kwargs)
45 changes: 24 additions & 21 deletions qcodes_contrib_drivers/drivers/Thorlabs/private/CC.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ctypes
import logging
from time import sleep, time
from typing import Optional

from qcodes.parameters import Parameter
from qcodes import validators as vals
Expand All @@ -19,25 +20,27 @@ class _Thorlabs_CC(_Thorlabs_Kinesis):
"""Instrument driver for Thorlabs instruments using the CC commands
Args:
name (str): Instrument name.
serial_number (str): Serial number of the device.
dll_path (str): Path to the kinesis dll for the instrument to use.
simulation (bool): Enables the simulation manager. Defaults to False.
polling (int): Polling rate in ms. Defaults to 200.
home (bool): Sets the device to home state. Defaults to False.
name: Instrument name.
serial_number: Serial number of the device.
dll_path: Path to the kinesis dll for the instrument to use.
dll_dir: Directory in which the kinesis dll are stored.
simulation: Enables the simulation manager. Defaults to False.
polling: Polling rate in ms. Defaults to 200.
home: Sets the device to home state. Defaults to False.
"""
_CONDITIONS = ['homed', 'moved', 'stopped', 'limit_updated']
def __init__(self,
name: str,
serial_number: str,
dll_path: str,
dll_dir: Optional[str],
simulation: bool = False,
polling: int = 200,
home: bool = False,
**kwargs):
self._dll_path = dll_path
super().__init__(name, serial_number,
self._dll_path, simulation,
self._dll_path, dll_dir, simulation,
**kwargs)

if self._dll.TLI_BuildDeviceList() == 0:
Expand Down Expand Up @@ -200,20 +203,20 @@ def go_home(self, block=True):
"""Home the device: set the device to a known state and home position
Args:
block (bool, optional): will wait for completion. Defaults to True.
block: will wait for completion. Defaults to True.
"""
self.log.info('home the device.')
self._check_error(self._dll.CC_Home(self._serial_number))
self.homed = True
if block:
self.wait_for_completion()

def wait_for_completion(self, status: str = 'homed', max_time = 5) -> None:
def wait_for_completion(self, status: str = 'homed', max_time: float = 5) -> None:
"""Wait for the current function to be finished.
Args:
status (str, optional): expected status. Defaults to 'homed'.
max_time (int, optional): maximum waiting time for the internal loop. Defaults to 5.
status: expected status. Defaults to 'homed'.
max_time: maximum waiting time for the internal loop.
"""
self.log.debug('wait for the current function to be completed')
message_type = ctypes.c_ushort()
Expand Down Expand Up @@ -257,8 +260,8 @@ def _device_unit_to_real(self, device_unit: int, unit_type: int) -> float:
"""Converts a device unit to a real world unit
Args:
device_unit (int): the device unit.
unit_type (int): the type of unit. Distance: 0, velocity: 1, acceleration: 2.
device_unit: the device unit.
unit_type: the type of unit. Distance: 0, velocity: 1, acceleration: 2.
Returns:
float: real unit value
Expand All @@ -275,8 +278,8 @@ def _real_to_device_unit(self, real_unit: float, unit_type: int) -> int:
"""Converts a real world unit to a device unit
Args:
real_unit (float): the real unit
unit_type (int): the type of unit. Distance: 0, velocity: 1, acceleration: 2
real_unit: the real unit
unit_type: the type of unit. Distance: 0, velocity: 1, acceleration: 2
Returns:
int: device unit
Expand Down Expand Up @@ -533,7 +536,7 @@ def _set_position(self, position: float, block: bool=True) -> None:
sleep(.2)
diff = abs(self._get_position() - position)
diff -= 360 if diff > 180 else diff

def is_moving(self) -> bool:
"""check if the motor cotnroller is moving."""
self.log.info('check if the motor is moving')
Expand Down Expand Up @@ -583,7 +586,7 @@ def move_continuous(self, direction: str = 'forward') -> None:
"""start moving at the current velocity in the specified direction
Args:
direction (str, optional): the required direction of travel.
direction: the required direction of travel.
Defaults to 'forward'. Accepts 'forward' or 'reverse'
"""
self.log.info(f'move continuously. direction: {direction}')
Expand All @@ -602,9 +605,9 @@ def jog(self, direction: str = 'forward', block: bool = True) -> None:
"""Performs a jog
Args:
direction (str): the jog direction. Defaults to 'forward'.
direction: the jog direction. Defaults to 'forward'.
Accepts 'forward' or 'reverse'
block (bool, optional): will wait until complete. Defaults to True.
block: will wait until complete. Defaults to True.
"""
self.log.info(f'perform a jog; direction: {direction}')
if direction == 'forward' or direction == 'forwards':
Expand All @@ -625,7 +628,7 @@ def stop(self, immediate: bool = False) -> None:
"""Stop the current move
Args:
immediate (bool, optional):
immediate:
True: stops immediately (with risk of losing track of position).
False: stops using the current velocity profile.
Defaults to False.
Expand Down Expand Up @@ -706,7 +709,7 @@ def _start_polling(self, polling: int) -> None:
def _stop_polling(self) -> None:
self.log.info('stop polling')
self._dll.CC_StopPolling(self._serial_number)

def _clear_message_queue(self) -> None:
self.log.info('clear messages queue')
self._dll.CC_ClearMessageQueue(self._serial_number)
Expand Down
Loading

0 comments on commit 1813364

Please sign in to comment.