Skip to content
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

Stage motors widget for LFM #133

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sashimi/gui/main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from sashimi.gui.status_bar import StatusBarWidget
from sashimi.gui.top_bar import TopWidget
from sashimi.state import State
from sashimi.gui.stage_gui import StageMotorWidget


class DockedWidget(QDockWidget):
Expand Down Expand Up @@ -45,6 +46,7 @@ def __init__(self, st: State, style: str):
self.wid_camera = CameraSettingsWidget(st, self.wid_display, self.timer)
self.wid_status_bar = StatusBarWidget(st, self.timer)
self.toolbar = TopWidget(st, self.timer)
self.wid_stage = StageMotorWidget(st)

self.addToolBar(Qt.TopToolBarArea, self.toolbar)

Expand All @@ -60,6 +62,11 @@ def __init__(self, st: State, style: str):
DockedWidget(widget=self.wid_scan, title="Scanning settings"),
)

self.addDockWidget(
Qt.RightDockWidgetArea,
DockedWidget(widget=self.wid_stage, title="Stage Motors"),
)

self.addDockWidget(
Qt.RightDockWidgetArea,
DockedWidget(widget=self.wid_laser, title="Light source"),
Expand Down Expand Up @@ -121,6 +128,7 @@ def refresh_param_values(self, omit_wid_camera=False):
# TODO should be possible with lightparam, when it's implemented there remove here
self.wid_laser.wid_settings.refresh_widgets()
self.wid_scan.wid_planar.refresh_widgets()
self.wid_stage.wid_settings.refresh_widgets()
self.wid_status.wid_volume.wid_volume.refresh_widgets()
self.wid_status.wid_calibration.refresh_widgets()
self.wid_status.wid_single_plane.wid_singleplane.refresh_widgets()
Expand Down
17 changes: 17 additions & 0 deletions sashimi/gui/stage_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from PyQt5.QtWidgets import (
QWidget,
QVBoxLayout,
QCheckBox,
)
from lightparam.gui import ParameterGui


# stage motors setting for LFM
class StageMotorWidget(QWidget):
def __init__(self, state):
super().__init__()
self.state = state
self.setLayout(QVBoxLayout())
self.wid_settings = ParameterGui(state.stage_setting)
self.layout().addWidget(self.wid_settings)

110 changes: 110 additions & 0 deletions sashimi/hardware/stage_motors/KDC101/KCube_py_int.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"Bindings for Thorlabs Benchtop Brushless Motor DLL"
# flake8: noqa
from ctypes import (
Structure,
cdll,
windll,
c_bool,
c_short,
c_int,
c_uint,
c_int16,
c_int32,
c_char,
c_byte,
c_long,
c_float,
c_double,
POINTER,
CFUNCTYPE,
CDLL,
CFUNCTYPE,
c_ushort,
c_ulong,
)

import os

from typing import (
Any,
List,
)

c_word = c_ushort
c_dword = c_ulong


def bind(lib: CDLL, func: str,
argtypes: List[Any]=None, restype: Any=None) -> CFUNCTYPE:
_func = getattr(lib, func, null_function)
_func.argtypes = argtypes
_func.restype = restype

return _func


def null_function():
pass


__all__ = [
bind,
null_function,
c_word,
c_dword,
]



#path for dlls
master_path = os.getcwd()


dll_folder = "dlls_servo"
dll_lib = "dlls_servo\Thorlabs.MotionControl.KCube.DCServo.dll"


dlls_path = os.path.join(master_path,dll_folder)
lib_path = os.path.join(master_path,dll_lib)


#specify folder for dlls
os.chdir(dlls_path)
lib = cdll.LoadLibrary(lib_path)

MOT_TravelDirection = c_short
MOT_TravelModes = c_int

CC_Open = bind(lib, "CC_Open", [POINTER(c_char)], c_short)
CC_Close = bind(lib, "CC_Close", [POINTER(c_char)])
TLI_BuildDeviceList = bind(lib, "TLI_BuildDeviceList", None, c_short)
TLI_GetDeviceListSize = bind(lib, "TLI_GetDeviceListSize", None, c_short)
CC_MoveToPosition = bind(lib, "CC_MoveToPosition", [POINTER(c_char), c_int], c_short)
CC_GetPosition = bind(lib, "CC_GetPosition", [POINTER(c_char)], c_int)
CC_CanHome = bind(lib, "CC_CanHome", [POINTER(c_char)], c_bool)
CC_Home = bind(lib, "CC_Home", [POINTER(c_char)], c_short)
CC_ClearMessageQueue = bind(lib, "CC_ClearMessageQueue", [POINTER(c_char)])
CC_RequestHomingParams = bind(lib, "CC_RequestHomingParams", [POINTER(c_char)], c_short)
CC_GetHomingVelocity = bind(lib, "CC_GetHomingVelocity", [POINTER(c_char)], c_uint)
CC_SetHomingVelocity = bind(lib, "CC_SetHomingVelocity", [POINTER(c_char), c_uint], c_short)
CC_MoveRelative = bind(lib, "CC_MoveRelative", [POINTER(c_char), c_int], c_short)
CC_RequestVelParams = bind(lib, "CC_RequestVelParams", [POINTER(c_char)], c_short)
CC_GetVelParams = bind(lib, "CC_GetVelParams", [POINTER(c_char), POINTER(c_int), POINTER(c_int)], c_short)
CC_SetVelParams = bind(lib, "CC_SetVelParams", [POINTER(c_char), c_int, c_int], c_short)
CC_MoveAtVelocity = bind(lib, "CC_MoveAtVelocity", [POINTER(c_char), MOT_TravelDirection], c_short)
CC_SetMoveAbsolutePosition = bind(lib, "CC_SetMoveAbsolutePosition", [POINTER(c_char), c_int], c_short)
CC_RequestMoveAbsolutePosition = bind(lib, "CC_RequestMoveAbsolutePosition", [POINTER(c_char)], c_short)
CC_GetMoveAbsolutePosition = bind(lib, "CC_GetMoveAbsolutePosition", [POINTER(c_char)], c_int)
CC_MoveAbsolute = bind(lib, "CC_MoveAbsolute", [POINTER(c_char)], c_short)
CC_SetMoveRelativeDistance = bind(lib, "CC_SetMoveRelativeDistance", [POINTER(c_char), c_int], c_short)
CC_RequestMoveRelativeDistance = bind(lib, "CC_RequestMoveRelativeDistance", [POINTER(c_char)], c_short)
CC_GetMoveRelativeDistance = bind(lib, "CC_GetMoveRelativeDistance", [POINTER(c_char)], c_int)
CC_MoveRelativeDistance = bind(lib, "CC_MoveRelativeDistance", [POINTER(c_char)], c_short)
CC_StartPolling = bind(lib, "CC_StartPolling", [POINTER(c_char), c_int], c_bool)
CC_PollingDuration = bind(lib, "CC_PollingDuration", [POINTER(c_char)], c_long)
CC_StopPolling = bind(lib, "CC_StopPolling", [POINTER(c_char)])
CC_GetStageAxisMinPos = bind(lib, "CC_GetStageAxisMinPos", [POINTER(c_char)], c_int)
CC_GetStageAxisMaxPos = bind(lib, "CC_GetStageAxisMaxPos", [POINTER(c_char)], c_int)
CC_SetStageAxisLimits = bind(lib, "CC_SetStageAxisLimits", [POINTER(c_char), c_int, c_int], c_short)
CC_SetMotorTravelMode = bind(lib, "CC_SetMotorTravelMode", [POINTER(c_char), MOT_TravelModes], c_short)
CC_GetMotorTravelMode = bind(lib, "CC_GetMotorTravelMode", [POINTER(c_char)], MOT_TravelModes)
Loading