diff --git a/sashimi/gui/main_gui.py b/sashimi/gui/main_gui.py index 17aa992e..4e3c5b41 100644 --- a/sashimi/gui/main_gui.py +++ b/sashimi/gui/main_gui.py @@ -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): @@ -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) @@ -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"), @@ -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() diff --git a/sashimi/gui/stage_gui.py b/sashimi/gui/stage_gui.py new file mode 100644 index 00000000..982242a9 --- /dev/null +++ b/sashimi/gui/stage_gui.py @@ -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) + diff --git a/sashimi/hardware/stage_motors/KDC101/KCube_py_int.py b/sashimi/hardware/stage_motors/KDC101/KCube_py_int.py new file mode 100644 index 00000000..29de4adf --- /dev/null +++ b/sashimi/hardware/stage_motors/KDC101/KCube_py_int.py @@ -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) \ No newline at end of file diff --git a/sashimi/hardware/stage_motors/KDC101/KCube_utils.py b/sashimi/hardware/stage_motors/KDC101/KCube_utils.py new file mode 100644 index 00000000..98bd142c --- /dev/null +++ b/sashimi/hardware/stage_motors/KDC101/KCube_utils.py @@ -0,0 +1,426 @@ +import KCube_py_int as kdc +from ctypes import ( + c_short, + c_int, + c_char_p, + byref, +) +import time +import numpy as np +import pandas as pd +from time import sleep +# from tqdm import tqdm +from sashimi.hardware.stage_motors.interface import AbstractMotor + + +################################################## + +def check_pos(pos, goal, ths = int(100 - 1e-3)): + acc = accuracy(pos,goal) + #return true if all of the elements are above threshold + return all(acc>ths) + +################################################## + +def check_move(pos, goal, ths= int(100 - 1e-3)): + acc = accuracy(pos,goal) + #return true if all of the elements are above threshold + return all(acc>ths) + +################################################## +def reached_target(pos, goal,ths = int(100 - 1e-3)): + #compute percentage accuracy + acc = 100*(1-abs((pos-goal)/goal)) + #if accuracy is negative set it to zero + if acc < 0: acc = 0 + + #return true if above threshold + return (acc>ths) + +################################################## + +def accuracy(pos,goal): + #compute percentage accuracy for each motor + acc = np.array([ 100*(1-abs((pos[i]-goal[i])/goal[i])) for i in range(len(pos))]) + #if accuracy is negative set it to zero + acc[acc<0] = 0 + return acc + +################################################## +# max = 12mm min -0.3 mm +def check_val(ranges,start_pos): + max_val = to_mm(12, False) + min_val = to_mm(0, False) #-0.3 + + #check if start is inside range starting from top left corner + print("start pos", start_pos) + print("max", max_val) + print("min", min_val) + if all(np.array(start_pos)>min_val) and all(np.array(start_pos)ranges[1]) and (max_val - start_pos[0] - min_val>ranges[0]) and (max_val - start_pos[2] - min_val>ranges[2]): + print("ok2") + return True + else: + return False + else: + return False + + +################################################## + +def to_mm(array, inverse): + x1m = 1.0013 + x1a = 34350 + alpha = x1m/x1a + beta = 1/alpha + + if isinstance(array, int): + if not inverse: + return int(array*beta) + else: + return array*alpha + else: #assume is array + if not inverse: + return (np.array(array)*beta).astype(int) + else: + return np.array(array)*alpha + + +################################################## + +def setVal_Motors(motors, poll=200, pause=0.4, acc=800, vel=2e6, verbose = False, home = False): + #set parameters + for mot in motors: + #polling + mot.set_Polling(poll) + #pause + mot.set_Pause(pause) + #verbose + mot.set_Verbose(verbose) + mot.set_velParams(acc, vel) + + #start the motor + mot.start() + sleep(pause) + + if home: + homing(motors, pause) + + +################################################## + +def homing(motors, pause): + for mot in motors: + mot.homing() + sleep(pause) + + while True: + pos = [mot.get_pos() for mot in motors] + if all(np.subtract(pos,0) == 0): + print("Homing Succeded") + break + + +################################################## +def close_Motors(motors): + for mot in motors: + #start the motor + mot.stop() + sleep(mot.pause) + + +################################################## +def moveTo(motors, end_pos, ths, verbose): + + #get position + pos = [mot.get_pos() for mot in motors] + + #check if end pos elements equal pos + check = abs(np.subtract(pos,end_pos)) > abs(ths -100) + + if len(motors) != len(pos): + print("Error - motors and end_pos should have the same length") + return + else: + #Moning the motors + for i, mot in enumerate(motors): + #if i am not already there, move + if check[i]: +# print("moving mot ", i) + mot.moveTo_abs(end_pos[i]) + + #feedback motor moving + while not check_move(pos, end_pos, ths): + #get position + pos = [mot.get_pos() for mot in motors] + + if verbose: + # clear_output(wait=True) + print("Moving motors..") + for i, p in enumerate(pos): + print(f"Motor - pos = {p} - desired pos = {end_pos[i]}") + + #motor at the desired position + if verbose: + # clear_output(wait=True) + print("Motors position:") + for i, p in enumerate(pos): + print(f"Motor - pos = {p} - desired pos = {end_pos[i]}") + + return {'End_x': end_pos[0], + 'End_y': end_pos[1], + 'End_z': end_pos[2], + 'Pos x': pos[0], + 'Pos y': pos[1], + 'Pos z': pos[2], + 'Accuracy': accuracy(pos, end_pos), + 'Mean Accuracy': np.mean(accuracy(pos, end_pos)), + 'Time Stamp': time.time()} + + + +################################################## +def stage_cycle(motors, start_pos, end_pos, n_steps, delay, ths,f_n,note, verbose): + + #step for each axes + x_steps = n_steps[0] + y_steps = n_steps[1] + z_steps = n_steps[2] + + #ranges for each axis + x_range = np.linspace(start_pos[0],end_pos[0], x_steps).astype(int) + y_range = np.linspace(start_pos[1],end_pos[1], y_steps).astype(int) + z_range = np.linspace(start_pos[2],end_pos[2], z_steps).astype(int) + + x_bool = True + arra = [] + + #get ids + ids = [mot.get_id() for mot in motors] + + meta = {'Ids': ids, + 'steps': n_steps, + 'ranges': [x_range,y_range,z_range], + 'start_pos': start_pos, + 'start_time': time.time(), + 'delay': delay, + 'fish_n': f_n, + 'note': note} + + + #cycle + # pbar2 = tqdm(total=(x_steps*y_steps*(z_steps-1)), desc="Moving..",mininterval=0.5, maxinterval =15, position=0, leave=True) + for z in range(z_steps-1): + if z%2==0: + for y in range(0, y_steps, 1): + if x_bool: + for x in range(0, x_steps, 1): + + #move to position + arra.append(moveTo(motors, [x_range[x], y_range[y], z_range[z]], ths, verbose)) + # pbar2.update(1) + sleep(delay) + + x_bool = False + else: + for x in range(x_steps-1, -1, -1): + + #move to position + arra.append(moveTo(motors, [x_range[x], y_range[y], z_range[z]], ths, verbose)) + # pbar2.update(1) + sleep(delay) + + x_bool = True + + else: + for y in range(y_steps-1, -1, -1): + if x_bool: + for x in range(0, x_steps, 1): + + #move to position + arra.append(moveTo(motors, [x_range[x], y_range[y], z_range[z]], ths, verbose)) + # pbar2.update(1) + sleep(delay) + + x_bool = False + else: + for x in range(x_steps-1, -1, -1): + + #move to position + arra.append(moveTo(motors, [x_range[x], y_range[y], z_range[z]], ths, verbose)) + # pbar2.update(1) + sleep(delay) + + x_bool = True + + # pbar2.close() + return pd.DataFrame(arra),pd.DataFrame(meta) +################################################## +# def saveData(data,meta): +# save_p = save_name + "_data.csv" +# save_m = save_name + "_metadata.csv" +# +# data.to_csv(save_p) +# meta.to_csv(save_m) +################################################## + + +class KC_motor(AbstractMotor): + '''Building our functions on top of the KCube class from Thorlabs''' + # Attention: this is all for one motor. The loop will do the for motor in motors + # Default values set for each motor upon initialization, can be altered + def __init__(self, serial_no, poll=200, pause=0.4, acc=800, vel=2e6, + motor_axis=str, max_range=13.0, verbose=False): + + self.id = c_char_p(bytes(serial_no, "utf-8")) + self.poll = poll + self.pause = pause + self.acc = acc + self.vel = vel + self.msg = [] + self.verbose = verbose + self.motor_axis = motor_axis #x,y,z for logging + self.max_range = max_range + + self.max_vel = kdc.c_int() # to work on it + self.acc = kdc.c_int() # to work on it + + self.isOpen = False + + KC_motor.set_Polling(self, self.poll) #polling + KC_motor.set_Pause(self, self.pause) #pause + KC_motor.set_Verbose(self, self.verbose) #verbose + KC_motor.set_velParams(self) + + def get_id(self): + return self.id + + def set_Polling(self, polling_ms = 200): + + self.poll = c_int(polling_ms) + + #if motor already open reset polling + if self.isOpen: + kdc.CC_StartPolling(self.id, self.poll) + self.msg.append("Start - Polling at " + str(self.poll)) + + def set_Pause(self, sleep_s = 0.4): + self.pause = sleep_s + + def set_Verbose(self, verb = False): + self.ver = verb + + def start(self): + if kdc.TLI_BuildDeviceList() == 0: + self.msg.append("Start - Device list builded correctly.") + + if kdc.CC_Open(self.id) == 0: + self.msg.append(f"Start - Opening motor {self.id}.") + self.isOpen = True + + #start polling + kdc.CC_StartPolling(self.id, self.poll) + self.msg.append("Start - Polling at {self.poll}.") + + #clear message queue + kdc.CC_ClearMessageQueue(self.id) + self.msg.append("Start - Message queue cleared.") + + + else: + self.msg.append(f"Start - Error: Can't Open {self.id}.") + + else: + self.msg.append("Start - Error: Can't build device list.") + + + if self.ver: return self.msg + + + def stop(self): + + kdc.CC_StopPolling(self.id) + self.msg.append("Stop - polling stopped.") + + if kdc.CC_Close(self.id) == 0: + self.msg.append("Stop - motor closed.") + self.isOpen = False + + else: + self.msg.append("Stop - Error: couldn't close the motor.") + + if self.ver: return self.msg + + + def homing(self): + + if kdc.CC_Home(self.id) == 0: + self.msg.append("Homing started.") + sleep(self.pause) + + else: + self.msg.append("Couldn't home.") + + if self.ver: return self.msg + + + def get_pos(self): + return kdc.CC_GetPosition(self.id) + + + def get_velParams(self): + + #request parameters + if kdc.CC_RequestVelParams(self.id) == 0: + self.msg.append("Requested vel Params.") + + #get parameters + if kdc.CC_GetVelParams(self.id, byref(self.acc), byref(self.max_vel)) == 0: + self.msg.append(f"acc = {self.acc} - max_vel = {self.max_vel}.") + + if self.ver: + return [self.acc, self.max_vel, self.msg] + else: + return [self.acc, self.max_vel] + else: + self.msg.append("Error - Couldn't get vel params.") + if self.ver: return self.msg + else: + self.msg.append("Error - Couldn't request vel params.") + if self.ver: return self.msg + + + def set_velParams(self, acc = 800, vel = 2e6): + + #request parameters + if kdc.CC_RequestVelParams(self.id) == 0: + self.msg.append("Requested vel Params.") + + self.acc = kdc.c_int(int(acc)) + self.max_vel = kdc.c_int(int(vel)) + + #set parameters + kdc.CC_SetVelParams(self.id, self.acc, self.max_vel) + self.msg.append(f"Setted - acc = {self.acc} - max_vel = {self.max_vel}.") + + else: + self.msg.append("Error - Couldn't request vel params.") + + if self.ver: return self.msg + + + def moveTo_abs(self, position): + #set move position + kdc.CC_SetMoveAbsolutePosition(self.id, c_int(position)) + + #move to position + kdc.CC_MoveAbsolute(self.id) + self.msg.append(f"Moving to {position}") + sleep(self.pause) + + + + + + \ No newline at end of file diff --git a/sashimi/hardware/stage_motors/KDC101/__init__.py b/sashimi/hardware/stage_motors/KDC101/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sashimi/hardware/stage_motors/KDC101/dlls_servo/ThorLabs.MotionControl.KCube.DCServoCLI.dll b/sashimi/hardware/stage_motors/KDC101/dlls_servo/ThorLabs.MotionControl.KCube.DCServoCLI.dll new file mode 100644 index 00000000..416604f8 Binary files /dev/null and b/sashimi/hardware/stage_motors/KDC101/dlls_servo/ThorLabs.MotionControl.KCube.DCServoCLI.dll differ diff --git a/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.DeviceManager.dll b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.DeviceManager.dll new file mode 100644 index 00000000..b414f3b1 Binary files /dev/null and b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.DeviceManager.dll differ diff --git a/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.GenericMotorUI.dll b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.GenericMotorUI.dll new file mode 100644 index 00000000..b916b4d1 Binary files /dev/null and b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.GenericMotorUI.dll differ diff --git a/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.dll b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.dll new file mode 100644 index 00000000..5429f8c1 Binary files /dev/null and b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.dll differ diff --git a/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.h b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.h new file mode 100644 index 00000000..02f8db2a --- /dev/null +++ b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.h @@ -0,0 +1,2222 @@ +// summary: Declares the cube class +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the KCUBEDCSERVO_EXPORTS +// symbol defined on the command line. This symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// KCUBEDCSERVO_API functions as being imported from a DLL, whereas this DLL sees symbols +// defined with this macro as being exported. + +#pragma once + +#ifdef KCUBEDCSERVODLL_EXPORTS +#define KCUBEDCSERVO_API __declspec(dllexport) +#else +#define KCUBEDCSERVO_API __declspec(dllimport) +#endif + +#include + +extern "C" +{ + + +/** @defgroup KCubeDCServo KCube DCServo + * This section details the Structures and Functions relavent to the @ref KDC101_page "KCube DC Motor Controller"
+ * For an example of how to connect to the device and perform simple operations use the following links: + * + * \ref namespaces_kdc_ex_1 "Example of using the Thorlabs.MotionControl.KCube.DCServo.DLL from a C or C++ project."
+ * This requires the DLL to be dynamical linked.
+ * \ref namespaces_kdc_ex_2 "Example of using the Thorlabs.MotionControl.KCube.DCServo.DLL from a C# project"
+ * This uses Marshalling to load and access the C DLL.
+ *
+ * The Thorlabs.MotionControl.KCube.DCServo.DLL requires the following DLLs + * + * Thorlabs.MotionControl.DeviceManager. + * + * @{ + */ + +/// \cond NOT_MASTER + + /// Values that represent FT_Status. + typedef enum FT_Status : short + { + FT_OK = 0x00, /// Values that represent THORLABSDEVICE_API. + typedef enum MOT_MotorTypes + { + MOT_NotMotor = 0, + MOT_DCMotor = 1, + MOT_StepperMotor = 2, + MOT_BrushlessMotor = 3, + MOT_CustomMotor = 100, + } MOT_MotorTypes; + + /// Values that represent Travel Modes. + typedef enum MOT_TravelModes : int + { + MOT_TravelModeUndefined,/// Values that represent Travel Modes. + typedef enum MOT_TravelDirection : short + { + MOT_TravelDirectionUndefined,/// Values that represent Limit Switch Directions. + typedef enum MOT_HomeLimitSwitchDirection : short + { + MOT_LimitSwitchDirectionUndefined,/// Values that represent Direction Type. + typedef enum MOT_DirectionSense : short + { + MOT_Normal = 0x00,/// Values that represent the motor Jog Modes. + typedef enum MOT_JogModes : short + { + MOT_JogModeUndefined = 0x00,/// Values that represent the motor Jog Modes. + typedef enum MOT_StopModes : short + { + MOT_StopModeUndefined = 0x00,/// Value that represent action to be taken when motor hits a limit switch. + typedef enum MOT_LimitSwitchModes : WORD + { + MOT_LimitSwitchModeUndefined = 0x00,/// Value that represent action to be taken when motor hits a limit switch. + typedef enum MOT_LimitSwitchSWModes : WORD + { + MOT_LimitSwitchSWModeUndefined = 0x00,/// Values that represent MOT_LimitsSoftwareApproachPolicy. + typedef enum MOT_LimitsSoftwareApproachPolicy : __int16 + { + DisallowIllegalMoves = 0,/// Values that represent Wheel Direction Sense. + typedef enum KMOT_WheelDirectionSense : __int16 + { + KMOT_WM_Positive = 0x01,///< Move at constant velocity + KMOT_WM_Negative = 0x02,///< Phase B + } KMOT_WheelDirectionSense; + + /// Values that represent the Wheel Mode. + typedef enum KMOT_WheelMode : __int16 + { + KMOT_WM_Velocity = 0x01,///< Move at constant velocity + KMOT_WM_Jog = 0x02,///< Phase B + KMOT_WM_MoveAbsolute = 0x03,///< Phase A and B + } KMOT_WheelMode; + + /// Values that represent Trigger Port Mode. + typedef enum KMOT_TriggerPortMode : __int16 + { + KMOT_TrigDisabled = 0x00,///< Trigger Disabled + KMOT_TrigIn_GPI = 0x01,///< General purpose logic input ( GetStatusBits) + KMOT_TrigIn_RelativeMove = 0x02,///< Move relative using relative move parameters + KMOT_TrigIn_AbsoluteMove = 0x03,///< Move absolute using absolute move parameters + KMOT_TrigIn_Home = 0x04,///< Perform a Home action + KMOT_TrigIn_Stop = 0x05,///< Perform a Stop Immediate action + KMOT_TrigOut_GPO = 0x0A,///< General purpose output ( SetDigitalOutputs) + KMOT_TrigOut_InMotion = 0x0B,///< Set when device moving + KMOT_TrigOut_AtMaxVelocity = 0x0C,///< Set when at max velocity + KMOT_TrigOut_AtPositionSteps = 0x0D,///< Set when at predefine position steps,
Set using wTrigStartPos, wTrigInterval, wTrigNumPulses,wTrigPulseWidth + KMOT_TrigOut_Synch = 0x0E,///< TBD ? + } KMOT_TriggerPortMode; + + /// Values that represent Trigger Port Polarity. + typedef enum KMOT_TriggerPortPolarity : __int16 + { + KMOT_TrigPolarityHigh = 0x01,///< Trigger Polarity high + KMOT_TrigPolarityLow = 0x02,///< Trigger Polarity Low + } KMOT_TriggerPortPolarity; + + /// Values that represent DeviceMessageClass message types. + typedef enum MOT_MovementModes + { + LinearRange = 0x00,///< Fixed Angular Range defined by MinPosition and MaxPosition + RotationalUnlimited = 0x01,///< Unlimited angle + RotationalWrapping = 0x02,///< Angular Range 0 to 360 with wrap around + } MOT_MovementModes; + + /// Values that represent DeviceMessageClass message types. + typedef enum MOT_MovementDirections + { + Quickest = 0x00,///< Uses the shortest travel between two angles + Forwards = 0x01,///< Only rotate in a forward direction + Reverse = 0x02,///< Only rotate in a backward direction + } MOT_MovementDirections; +/// \endcond + + /// Information about the device generated from serial number. + #pragma pack(1) + typedef struct TLI_DeviceInfo + { + /// The device Type ID, see \ref C_DEVICEID_page "Device serial numbers". + DWORD typeID; + /// The device description. + char description[65]; + /// The device serial number. + char serialNo[16]; + /// The USB PID number. + DWORD PID; + + /// true if this object is a type known to the Motion Control software. + bool isKnownType; + /// The motor type (if a motor). + /// + /// MOT_NotMotor0 + /// MOT_DCMotor1 + /// MOT_StepperMotor2 + /// MOT_BrushlessMotor3 + /// MOT_CustomMotor100 + /// + MOT_MotorTypes motorType; + + /// true if the device is a piezo device. + bool isPiezoDevice; + /// true if the device is a laser. + bool isLaser; + /// true if the device is a custom type. + bool isCustomType; + /// true if the device is a rack. + bool isRack; + /// Defines the number of channels available in this device. + short maxChannels; + } TLI_DeviceInfo; + + /// Structure containing the Hardware Information. + typedef struct TLI_HardwareInformation + { + /// The device serial number. + /// The device serial number is a serial number,
starting with 2 digits representing the device type
and a 6 digit unique value.
+ DWORD serialNumber; + /// The device model number. + /// The model number uniquely identifies the device type as a string. + char modelNumber[8]; + /// The device type. + /// Each device type has a unique Type ID: see \ref C_DEVICEID_page "Device serial numbers" + WORD type; + /// The device firmware version. + DWORD firmwareVersion; + /// The device notes read from the device. + char notes[48]; + /// The device dependant data. + BYTE deviceDependantData[12]; + /// The device hardware version. + WORD hardwareVersion; + /// The device modification state. + WORD modificationState; + /// The number of channels the device provides. + short numChannels; + } TLI_HardwareInformation; + + /// Structure containing the velocity parameters. + /// Moves are performed using a velocity profile.
+ /// The move starts at the Minimum Velocity (always 0 at present) and accelerated to the Maximum Velocity using the defined Acceleration.
+ /// The move is usually completed using a similar deceleration.
+ /// For further information see \ref C_MOTOR_sec11 "Positioning"
+ /// + /// + typedef struct MOT_VelocityParameters + { + /// The minimum velocity in \ref DeviceUnits_page usually 0. + int minVelocity; + /// The acceleration in \ref DeviceUnits_page. + int acceleration; + /// The maximum velocity in \ref DeviceUnits_page. + int maxVelocity; + } MOT_VelocityParameters; + + /// Structure containing the jog parameters. + /// Jogs are performed using a velocity profile over small fixed distances.
+ /// The move starts at the Minimum Velocity (always 0 at present) and accelerated to the Maximum Velocity using the defined Acceleration.
+ /// The move is usually completed using a similar deceleration.
+ /// For further information see \ref C_MOTOR_sec12 "Jogging"
+ /// + /// + typedef struct MOT_JogParameters + { + /// The jogging mode. + /// The mode can be one of the following: + /// + /// 1Continuous Jogging
The device will continue moving until the end stop is reached or the device button is raised
+ /// 2Step Jogbr />The device will move by a fixed amount as defined in this structure. + ///
+ MOT_JogModes mode; + /// The step size in \ref DeviceUnits_page. + unsigned int stepSize; + /// The MOT_VelocityParameters for the jog. + MOT_VelocityParameters velParams; + /// The Stop Mode + /// The Stop Mode determines how the jog should stop. + /// + /// 1Immediate + /// 2Profiled. + /// + MOT_StopModes stopMode; + } MOT_JogParameters; + + /// Structure containing the homing parameters. + /// Homing is performed using a constant velocity.
+ /// The home starts moving the motor in the defined direction until the limit switch is detected.
+ /// The device will then vback off from the limit switch by the defined offset distance.
+ /// For further information see \ref C_MOTOR_sec10 "Homing"
+ /// + /// + typedef struct MOT_HomingParameters + { + /// The Homing direction sense + /// The Homing Operation will always move in a decreasing position sense, but the actuator gearing may change the actual physical sense
+ /// Therefore the homing direction can correct the physical sense. + /// + /// 1Forwards + /// 2Backwards. + ///
+ MOT_TravelDirection direction; + /// The limit switch direction. + /// The limit switch which will be hit when homing completes. + /// + /// 1Forward Limit Switch + /// 2Reverse Limit Switch. + /// + MOT_HomeLimitSwitchDirection limitSwitch; + /// The velocity in small indivisible units. + /// As the homing operation is performed at a much lower velocity, to achieve accuracy, a profile is not required. + unsigned int velocity; + /// Distance of home from limit in small indivisible units. + unsigned int offsetDistance; + } MOT_HomingParameters; + + /// Structure containing the limit switch parameters. + typedef struct MOT_LimitSwitchParameters + { + /// Defines the clockwise hardware limit. + /// The clockwise hardware limit + /// + /// 0x01Ignore limit switch + /// 0x02Make on contact. + /// 0x03Break on contact. + /// 0x04Makes on contact when homing + /// 0x05Break on contact when homing. + /// 0x06Reserved for PMD brushless servo controllers. + /// 0x80Switch mode when using a rotational stage. + /// + MOT_LimitSwitchModes clockwiseHardwareLimit; + /// Defines the anticlockwise hardware limit. + /// The anticlockwise hardware limit + /// + /// 0x01Ignore limit switch + /// 0x02Make on contact. + /// 0x03Break on contact. + /// 0x04Makes on contact when homing + /// 0x05Break on contact when homing. + /// 0x06Reserved for PMD brushless servo controllers. + /// 0x80Switch mode when using a rotational stage. + /// + MOT_LimitSwitchModes anticlockwiseHardwareLimit; + /// poition of clockwise software limit in \ref DeviceUnits_page. + DWORD clockwisePosition; + /// poition of anticlockwise software limit in \ref DeviceUnits_page. + DWORD anticlockwisePosition; + /// Actions to take when software limit is detected. + /// The anticlockwise hardware limit + /// + /// 0x01Ignore limit switche. + /// 0x02Stop Immediate. + /// 0x03Profiled stop. + /// 0x82Stop Immediate (rotational stage). + /// 0x83Profiled stop (rotational stage). + /// + MOT_LimitSwitchSWModes softLimitMode; + } MOT_LimitSwitchParameters; + + /// structure containing the PID Loop Parameters. + typedef struct MOT_DC_PIDParameters + { + /// The PID Proportional Gain. + int proportionalGain; + /// The PID Integral Gain. + int integralGain; + /// The PID Derivative Gain. + /// Kept as differentialGain rather than derivativeGain for backward compatibility + int differentialGain; + /// The PID Integral Limit. + int integralLimit; + /// Bit Mask To enable / disable the PID components. + /// Bit Mask To enable / disable the PID components. + /// + /// Bit 1 (0x01)When set, enable Proportional Gain component. + /// Bit 2 (0x02)When set, enable Integral Gain component. + /// Bit 3 (0x04)When set, enable Derivative Gain component. + /// Bit 4 (0x08)When set, enable Integral Limit component. + /// + WORD parameterFilter; + } MOT_DC_PIDParameters; + + /// Structure containing the MMI Parameters. + /// Device GUI parameters. + typedef struct KMOT_MMIParams + { + /// The wheel mode. + /// The wheel mode is one of the following: + /// + /// 1Constant Velocity
The device will continue moving until the end stop is reached or the duration of the wheel action
+ /// 2Jog
The device will jog forward or backward according to the wheel action.
+ /// The device will jog according to the Jog parameters
+ /// 3Move Absolute
The device will move to either Preset Po 1 or 2 according to the wheel action.
+ ///
+ ///
+ KMOT_WheelMode WheelMode; + /// The wheel maximum velocity. + __int32 WheelMaxVelocity; + /// The wheel acceleration. + __int32 WheelAcceleration; + /// The wheel direction sense. + MOT_DirectionSense WheelDirectionSense; + /// The first preset position in encoder counts. + __int32 PresetPos1; + /// The second preset position in encoder counts. + __int32 PresetPos2; + /// The display intensity, range 0 to 100%. + __int16 DisplayIntensity; + /// The display timeout in miniutes. + __int16 DisplayTimeout; + /// The display dim intensity, range 0 to (Display Timeout). + __int16 DisplayDimIntensity; + /// Reserved fields. + __int16 reserved[4]; + } KMOT_MMIParams; + + /// KCube motor trigger configuration. + typedef struct KMOT_TriggerConfig + { + /// The trigger 1 mode. + /// The trigger 1 operating mode: + /// + /// 0Trigger disabled + /// 1Trigger Input - General purpose logic input ( GetStatusBits) + /// 2Trigger Input - Move relative using relative move parameters + /// 3Trigger Input - Move absolute using absolute move parameters + /// 4Trigger Input - Perform a Home action + /// 5Trigger Input - Perform a Stop action + /// 10Trigger Output - General purpose output ( SetDigitalOutputs) + /// 11Trigger Output - Set when device moving + /// 12Trigger Output - Set when at max velocity + /// 13Trigger Output - Set when at predefine position steps + /// 14Trigger Output - TBD mode + /// + /// + KMOT_TriggerPortMode Trigger1Mode; + /// The trigger 1 polarity. + /// The trigger 1 output polaritye: + /// + /// 1Output high when set + /// 2Output low when set + /// + /// + KMOT_TriggerPortPolarity Trigger1Polarity; + /// The trigger 2 mode. + /// The trigger 2 operating mode: + /// + /// 0Trigger disabled + /// 1Trigger Input - General purpose logic input ( GetStatusBits) + /// 2Trigger Input - Move relative using relative move parameters + /// 3Trigger Input - Move absolute using absolute move parameters + /// 4Trigger Input - Perform a Home action + /// 5Trigger Input - Perform a Stop action + /// 10Trigger Output - General purpose output ( SetDigitalOutputs) + /// 11Trigger Output - Set when device moving + /// 12Trigger Output - Set when at max velocity + /// 13Trigger Output - Set when at predefine position steps + /// 14Trigger Output - TBD mode + /// + /// + KMOT_TriggerPortMode Trigger2Mode; + /// The trigger 2 polarity. + /// The trigger 2 output polarity: + /// + /// 1Output high when set + /// 2Output low when set + /// + /// + KMOT_TriggerPortPolarity Trigger2Polarity; + } KMOT_TriggerConfig; + + /// KCube motor trigger output configuration. + typedef struct KMOT_TriggerParams + { + /// The trigger output start position in encoder units. + __int32 TriggerStartPositionFwd; + /// The trigger interval in encoder units. + __int32 TriggerIntervalFwd; + /// Number of trigger pulses. + __int32 TriggerPulseCountFwd; + /// The trigger output start position in encoder units. + __int32 TriggerStartPositionRev; + /// The trigger interval in encoder units. + __int32 TriggerIntervalRev; + /// Number of trigger pulses. + __int32 TriggerPulseCountRev; + /// Width of the trigger pulse in encoder units. + __int32 TriggerPulseWidth; + /// Number of cycles. + __int32 CycleCount; + /// reserved fields. + __int32 reserved[6]; + } KMOT_TriggerParams; + + #pragma pack() + + /// Build the DeviceList. + /// This function builds an internal collection of all devices found on the USB that are not currently open.
+ /// NOTE, if a device is open, it will not appear in the list until the device has been closed.
+ /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identification.cpp + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_BuildDeviceList(void); + + /// Gets the device list size. + /// \include CodeSnippet_identification.cpp + /// Number of devices in device list. + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_GetDeviceListSize(); + + /// Get the entire contents of the device list. + /// Outputs a SAFEARRAY of strings holding device serial numbers. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identification.cpp + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_GetDeviceList(SAFEARRAY** stringsReceiver); + + /// Get the contents of the device list which match the supplied typeID. + /// Outputs a SAFEARRAY of strings holding device serial numbers. + /// The typeID of devices to match, see \ref C_DEVICEID_page "Device serial numbers". + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identification.cpp + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_GetDeviceListByType(SAFEARRAY** stringsReceiver, int typeID); + + /// Get the contents of the device list which match the supplied typeIDs. + /// Outputs a SAFEARRAY of strings holding device serial numbers. + /// list of typeIDs of devices to be matched, see \ref C_DEVICEID_page "Device serial numbers" + /// length of type list + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identification.cpp + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_GetDeviceListByTypes(SAFEARRAY** stringsReceiver, int * typeIDs, int length); + + /// Get the entire contents of the device list. + /// a buffer in which to receive the list as a comma separated string. + /// The size of the output string buffer. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identification.cpp + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_GetDeviceListExt(char *receiveBuffer, DWORD sizeOfBuffer); + + /// Get the contents of the device list which match the supplied typeID. + /// a buffer in which to receive the list as a comma separated string. + /// The size of the output string buffer. + /// The typeID of devices to be matched, see \ref C_DEVICEID_page "Device serial numbers" + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identification.cpp + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_GetDeviceListByTypeExt(char *receiveBuffer, DWORD sizeOfBuffer, int typeID); + + /// Get the contents of the device list which match the supplied typeIDs. + /// a buffer in which to receive the list as a comma separated string. + /// The size of the output string buffer. + /// list of typeIDs of devices to be matched, see \ref C_DEVICEID_page "Device serial numbers" + /// length of type list + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identification.cpp + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_GetDeviceListByTypesExt(char *receiveBuffer, DWORD sizeOfBuffer, int * typeIDs, int length); + + /// Get the device information from the USB port. + /// The Device Info is read from the USB port not from the device itself. + /// The serial number of the device. + /// The device information. + /// 1 if successful, 0 if not. + /// \include CodeSnippet_identification.cpp + /// + /// + /// + /// + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl TLI_GetDeviceInfo(char const * serialNo, TLI_DeviceInfo *info); + + /// Initialize a connection to the Simulation Manager, which must already be running. + /// Call TLI_InitializeSimulations before TLI_BuildDeviceList at the start of the program to make a connection to the simulation manager.
+ /// Any devices configured in the simulation manager will become visible TLI_BuildDeviceList is called and can be accessed using TLI_GetDeviceList.
+ /// Call TLI_InitializeSimulations at the end of the program to release the simulator.
+ /// + /// + /// + KCUBEDCSERVO_API void __cdecl TLI_InitializeSimulations(); + + /// Uninitialize a connection to the Simulation Manager, which must already be running. + /// + KCUBEDCSERVO_API void __cdecl TLI_UninitializeSimulations(); + + /// Open the device for communications. + /// The serial no of the device to be connected. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_connection1.cpp + /// + KCUBEDCSERVO_API short __cdecl CC_Open(char const * serialNo); + + /// Disconnect and close the device. + /// The serial no of the device to be disconnected. + /// \include CodeSnippet_connection1.cpp + /// + KCUBEDCSERVO_API void __cdecl CC_Close(char const * serialNo); + + /// Check connection. + /// The device serial no. + /// true if the USB is listed by the ftdi controller + /// \include CodeSnippet_CheckConnection.cpp + KCUBEDCSERVO_API bool __cdecl CC_CheckConnection(char const * serialNo); + + /// Sends a command to the device to make it identify iteself. + /// The device serial no. + KCUBEDCSERVO_API void __cdecl CC_Identify(char const * serialNo); + + /// Request the LED indicator bits on cube. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestLEDswitches(char const * serialNo); + + /// Get the LED indicator bits on cube. + /// The device serial no. + /// Sum of: 8 to indicate moving 2 to indicate end of track and 1 to flash on identify command. + /// + /// + KCUBEDCSERVO_API WORD __cdecl CC_GetLEDswitches(char const * serialNo); + + /// Set the LED indicator bits on cube. + /// The device serial no. + /// Sum of: 8 to indicate moving 2 to indicate end of track and 1 to flash on identify command. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetLEDswitches(char const * serialNo, WORD LEDswitches); + + /// Gets the hardware information from the device. + /// The device serial no. + /// Address of a buffer to receive the model number string. Minimum 8 characters + /// The size of the model number buffer, minimum of 8 characters. + /// Address of a WORD to receive the hardware type number. + /// Address of a short to receive the number of channels. + /// Address of a buffer to receive the notes describing the device. + /// The size of the notes buffer, minimum of 48 characters. + /// Address of a DWORD to receive the firmware version number made up of 4 byte parts. + /// Address of a WORD to receive the hardware version number. + /// Address of a WORD to receive the hardware modification state number. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identify.cpp + KCUBEDCSERVO_API short __cdecl CC_GetHardwareInfo(char const * serialNo, char * modelNo, DWORD sizeOfModelNo, WORD * type, WORD * numChannels, + char * notes, DWORD sizeOfNotes, DWORD * firmwareVersion, WORD * hardwareVersion, WORD * modificationState); + + /// Gets the hardware information in a block. + /// The device serial no. + /// Address of a TLI_HardwareInformation structure to receive the hardware information. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// \include CodeSnippet_identify.cpp + KCUBEDCSERVO_API short __cdecl CC_GetHardwareInfoBlock(char const * serialNo, TLI_HardwareInformation *hardwareInfo); + + /// Gets the hub bay number this device is fitted to. + /// The device serial no. + /// The number, 0x00 if unknown or 0xff if not on a hub. + KCUBEDCSERVO_API char __cdecl CC_GetHubBay(char const * serialNo); + + /// Gets version number of the device software. + /// The device serial no. + /// The device software version number made up of 4 byte parts. + /// \include CodeSnippet_identify.cpp + KCUBEDCSERVO_API DWORD __cdecl CC_GetSoftwareVersion(char const * serialNo); + + /// Update device with stored settings. + /// The device serial no. + /// true if successful, false if not. + /// \include CodeSnippet_connection1.cpp + KCUBEDCSERVO_API bool __cdecl CC_LoadSettings(char const * serialNo); + + /// Update device with named settings. + /// The device serial no. + /// Name of settings stored away from device. + /// true if successful, false if not. + /// \include CodeSnippet_connection1.cpp + KCUBEDCSERVO_API bool __cdecl CC_LoadNamedSettings(char const * serialNo, char const *settingsName); + + /// Update device with stored settings. + /// The device serial no. + /// true if successful, false if not. + KCUBEDCSERVO_API bool __cdecl CC_PersistSettings(char const * serialNo); + + /// Reset the stage settings to defaults. + /// The device serial no. + /// true if successful, false if not. + KCUBEDCSERVO_API short __cdecl CC_ResetStageToDefaults(char const * serialNo); + + /// Disable the channel so that motor can be moved by hand. + /// When disabled power is removed from the motor and it can be freely moved. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_DisableChannel(char const * serialNo); + + /// Enable channel for computer control. + /// When enabled power is applied to the motor so it is fixed in position. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_EnableChannel(char const * serialNo); + + /// Determine if the device front panel can be locked. + /// The device serial no. + /// True if we can lock the device front panel, false if not. + /// + /// + /// + KCUBEDCSERVO_API bool __cdecl CC_CanDeviceLockFrontPanel(char const * serialNo); + + /// Query if the device front panel locked. + /// The device serial no. + /// True if the device front panel is locked, false if not. + /// + /// + /// + KCUBEDCSERVO_API bool __cdecl CC_GetFrontPanelLocked(char const * serialNo); + + /// Ask the device if its front panel is locked. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestFrontPanelLocked(char const * serialNo); + + /// Sets the device front panel lock state. + /// The device serial no. + /// True to lock the device, false to unlock. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetFrontPanelLock(char const * serialNo, bool locked); + + /// Get number of positions. + /// The GetNumberPositions function will get the maximum position reachable by the device.
+ /// The motor may need to be \ref C_MOTOR_sec10 "Homed" before this parameter can be used.
+ /// The device serial no. + /// The number of positions. + /// + /// + /// + /// \include CodeSnippet_move.cpp + KCUBEDCSERVO_API int __cdecl CC_GetNumberPositions(char const * serialNo); + + /// Move the device to the specified position (index). + /// The motor may need to be \ref C_MOTOR_sec10 "Homed" before a position can be set
+ /// see \ref C_MOTOR_sec11 "Positioning" for more detail.
+ /// The device serial no. + /// The position in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if move successfully started. + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_move.cpp + KCUBEDCSERVO_API short __cdecl CC_MoveToPosition(char const * serialNo, int index); + + /// Get the current position. + /// The current position is the last recorded position.
+ /// The current position is updated either by the polling mechanism or
+ /// by calling or .
+ /// The device serial no. + /// The current position in \ref DeviceUnits_page. + /// + /// + /// + /// \include CodeSnippet_move.cpp + KCUBEDCSERVO_API int __cdecl CC_GetPosition(char const * serialNo); + + /// Can the device perform a Home. + /// The serial no. + /// true if the device can home. + KCUBEDCSERVO_API bool __cdecl CC_CanHome(char const * serialNo); + + /// \deprecated + /// Does the device need to be Homed before a move can be performed. + /// superceded by + /// The serial no. + /// true if the device needs homing. + KCUBEDCSERVO_API bool __cdecl CC_NeedsHoming(char const * serialNo); + + /// Can this device be moved without Homing. + /// The serial no. + /// true if the device does not need to be homed before a move can be commanded. + KCUBEDCSERVO_API bool __cdecl CC_CanMoveWithoutHomingFirst(char const * serialNo); + + /// Home the device. + /// Homing the device will set the device to a known state and determine the home position,
+ /// see \ref C_MOTOR_sec10 "Homing" for more detail.
+ /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if move successfully started. + /// + /// + /// + /// \include CodeSnippet_move.cpp + KCUBEDCSERVO_API short __cdecl CC_Home(char const * serialNo); + + /// Clears the device message queue. + /// see \ref C_MESSAGES_page "Device Messages" for details on how to use messages. + /// The device serial no. + KCUBEDCSERVO_API void __cdecl CC_ClearMessageQueue(char const * serialNo); + + /// Registers a callback on the message queue. + /// see \ref C_MESSAGES_page "Device Messages" for details on how to use messages. + /// The device serial no. + /// A function pointer to be called whenever messages are received. + /// + /// + /// + KCUBEDCSERVO_API void __cdecl CC_RegisterMessageCallback(char const * serialNo, void(*functionPointer)()); + + /// Gets the MessageQueue size. + /// see \ref C_MESSAGES_page "Device Messages" for details on how to use messages. + /// The device serial no. + /// number of messages in the queue. + /// + /// + /// + KCUBEDCSERVO_API int __cdecl CC_MessageQueueSize(char const * serialNo); + + /// Get the next MessageQueue item. + /// see \ref C_MESSAGES_page "Device Messages" for details on how to use messages. + /// The device serial no. + /// The address of the parameter to receive the message Type. + /// The address of the parameter to receive the message id. + /// The address of the parameter to receive the message data. + /// true if successful, false if not. + /// + /// + /// + KCUBEDCSERVO_API bool __cdecl CC_GetNextMessage(char const * serialNo, WORD * messageType, WORD * messageID, DWORD *messageData); + + /// Wait for next MessageQueue item. + /// see \ref C_MESSAGES_page "Device Messages" for details on how to use messages. + /// The device serial no. + /// The address of the parameter to receive the message Type. + /// The address of the parameter to receive the message id. + /// The address of the parameter to receive the message data. + /// true if successful, false if not. + /// + /// + /// + KCUBEDCSERVO_API bool __cdecl CC_WaitForMessage(char const * serialNo, WORD * messageType, WORD * messageID, DWORD *messageData); + + /// Requests the homing parameters. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestHomingParams(char const * serialNo); + + /// Gets the homing velocity. + /// see \ref C_MOTOR_sec10 "Homing" for more detail. + /// The device serial no. + /// The homing velocity in \ref DeviceUnits_page. + /// + /// + /// + /// + KCUBEDCSERVO_API unsigned int __cdecl CC_GetHomingVelocity(char const * serialNo); + + /// Sets the homing velocity. + /// see \ref C_MOTOR_sec10 "Homing" for more detail. + /// The device serial no. + /// The homing velocity in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetHomingVelocity(char const * serialNo, unsigned int velocity); + + /// Move the motor by a relative amount. + /// The device serial no. + /// Signed displacement in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_move.cpp + KCUBEDCSERVO_API short __cdecl CC_MoveRelative(char const * serialNo, int displacement); + + /// Requests the jog parameters. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API short __cdecl CC_RequestJogParams(const char * serialNo); + + /// Gets the jog mode. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The address of the short mode to recieve the Mode. + /// + /// Jog step1 + /// Continuous2 + /// + /// The address of the short stopMode to recieve the StopMode. + /// + /// Immediate Stop1 + /// Profiled Stop2 + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API short __cdecl CC_GetJogMode(char const * serialNo, MOT_JogModes * mode, MOT_StopModes * stopMode); + + /// Sets the jog mode. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The jog mode. + /// + /// Jog step1 + /// Continuous2 + /// + /// The StopMode. + /// + /// Immediate Stop1 + /// Profiled Stop2 + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API short __cdecl CC_SetJogMode(char const * serialNo, MOT_JogModes mode, MOT_StopModes stopMode); + + /// Gets the distance to move when jogging. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The step in \ref DeviceUnits_page. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API unsigned int __cdecl CC_GetJogStepSize(char const * serialNo); + + /// Sets the distance to move on jogging. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The step in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API short __cdecl CC_SetJogStepSize(char const * serialNo, unsigned int stepSize); + + /// Gets the jog velocity parameters. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// Address of the parameter to receive the acceleration in \ref DeviceUnits_page. + /// Address of the parameter to receive the velocity in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API short __cdecl CC_GetJogVelParams(char const * serialNo, int * acceleration, int * maxVelocity); + + /// Sets jog velocity parameters. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The acceleration in \ref DeviceUnits_page. + /// The maximum velocity in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API short __cdecl CC_SetJogVelParams(char const * serialNo, int acceleration, int maxVelocity); + + /// Perform a jog. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The jog direction + /// + /// Forwards1 + /// Backwards2 + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jog.cpp + KCUBEDCSERVO_API short __cdecl CC_MoveJog(char const * serialNo, MOT_TravelDirection jogDirection); + + /// Requests the velocity parameters. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestVelParams(char const * serialNo); + + /// Gets the move velocity parameters. + /// see \ref C_MOTOR_sec11 "Positioning" for more detail. + /// The device serial no. + /// Address of the parameter to receive the acceleration value in \ref DeviceUnits_page. + /// Address of the parameter to receive the maximum velocity value in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_movepars.cpp + KCUBEDCSERVO_API short __cdecl CC_GetVelParams(char const * serialNo, int * acceleration, int * maxVelocity); + + /// Sets the move velocity parameters. + /// see \ref C_MOTOR_sec11 "Positioning" for more detail. + /// The device serial no. + /// The new acceleration value in \ref DeviceUnits_page. + /// The new maximum velocity value in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_movepars.cpp + KCUBEDCSERVO_API short __cdecl CC_SetVelParams(char const * serialNo, int acceleration, int maxVelocity); + + /// Start moving at the current velocity in the specified direction. + /// see \ref C_MOTOR_sec11 "Positioning" for more detail. + /// The device serial no. + /// The required direction of travel. + /// + /// Forwards1 + /// Backwards2 + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_move.cpp + KCUBEDCSERVO_API short __cdecl CC_MoveAtVelocity(char const * serialNo, MOT_TravelDirection direction); + + /// Sets the motor direction sense. + /// This function is used because some actuators use have directions of motion reversed.
+ /// This parameter will tell the system to reverse the direction sense whnd moving, jogging etc.
+ /// The device serial no. + /// if true then directions will be swapped on these moves. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + KCUBEDCSERVO_API void __cdecl CC_SetDirection(char const * serialNo, bool reverse); + + + /// Stop the current move immediately (with risk of losing track of position). + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_StopImmediate(char const * serialNo); + + /// Stop the current move using the current velocity profile. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_StopProfiled(char const * serialNo); + + /// Requests the backlash. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestBacklash(char const * serialNo); + + /// Get the backlash distance setting (used to control hysteresis). + /// The device serial no. + /// The backlash distance in \ref DeviceUnits_page. + /// + /// + KCUBEDCSERVO_API long __cdecl CC_GetBacklash(char const * serialNo); + + /// Sets the backlash distance (used to control hysteresis). + /// The serial no. + /// The distance in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_SetBacklash(char const * serialNo, long distance); + + /// Get the Position Counter. + /// The position counter is identical to the position parameter.
+ /// The position counter is set to zero when homing is complete.
+ /// The position counter can also be set using
+ /// if homing is not to be perforned
+ /// The device serial no. + /// Position count in \ref DeviceUnits_page. + /// + /// + KCUBEDCSERVO_API long __cdecl CC_GetPositionCounter(char const * serialNo); + + /// Set the Position Counter. + /// Setting the position counter will locate the current position.
+ /// Setting the position counter will effectively define the home position of a motor.
+ /// The device serial no. + /// Position count in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetPositionCounter(char const * serialNo, long count); + + /// Requests the encoder counter. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestEncoderCounter(char const * serialNo); + + /// Get the Encoder Counter. + /// For devices that have an encoder, the current encoder position can be read. + /// The device serial no. + /// Encoder Count of encoder units. + /// + /// + KCUBEDCSERVO_API long __cdecl CC_GetEncoderCounter(char const * serialNo); + + /// Set the Encoder Counter values. + /// setting the encoder counter to zero, effectively defines a home position on the encoder strip.
+ /// NOTE, setting this value does not move the device.
+ /// The device serial no. + /// The encoder count in encoder units. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetEncoderCounter(char const * serialNo, long count); + + + /// Requests the limit switch parameters. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestLimitSwitchParams(char const * serialNo); + + /// Gets the limit switch parameters. + /// The device serial no. + /// The clockwise hardware limit mode. + /// + /// Ignore switch or switch not present. 1 + /// Switch makes on contact. 2 + /// Switch breaks on contact. 3 + /// If these are bitwise-ORed with 0x0080 then the limits are swapped. + /// The anticlockwise hardware limit mode + /// + /// Ignore switch or switch not present. 1 + /// Switch makes on contact. 2 + /// Switch breaks on contact. 3 + /// If these are bitwise-ORed with 0x0080 then the limits are swapped. + /// + /// The poition of the clockwise software limit in \ref DeviceUnits_page. + /// The position of the anticlockwise software limit in \ref DeviceUnits_page. + /// The soft limit mode + /// + /// Ignore limit. 1 + /// Immediate Stop. 2 + /// SProfiled stop. 3 + /// If these are bitwise-ORed with 0x0080 then the limits are swapped. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetLimitSwitchParams(char const * serialNo, MOT_LimitSwitchModes * clockwiseHardwareLimit, MOT_LimitSwitchModes * anticlockwiseHardwareLimit, unsigned int * clockwisePosition, unsigned int * anticlockwisePosition, MOT_LimitSwitchSWModes * softLimitMode); + + /// Sets the limit switch parameters. + /// The device serial no. + /// The clockwise hardware limit mode. + /// + /// Ignore switch or switch not present. 1 + /// Switch makes on contact. 2 + /// Switch breaks on contact. 3 + /// If these are bitwise-ORed with 0x0080 then the limits are swapped. + /// The anticlockwise hardware limit mode + /// + /// Ignore switch or switch not present. 1 + /// Switch makes on contact. 2 + /// Switch breaks on contact. 3 + /// If these are bitwise-ORed with 0x0080 then the limits are swapped. + /// + /// The poition of the clockwise software limit in \ref DeviceUnits_page. + /// The position of the anticlockwise software limit in \ref DeviceUnits_page. + /// The soft limit mode + /// + /// Ignore limit. 1 + /// Immediate Stop. 2 + /// SProfiled stop. 3 + /// If these are bitwise-ORed with 0x0080 then the limits are swapped. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetLimitSwitchParams(char const * serialNo, MOT_LimitSwitchModes clockwiseHardwareLimit, MOT_LimitSwitchModes anticlockwiseHardwareLimit, unsigned int clockwisePosition, unsigned int anticlockwisePosition, MOT_LimitSwitchSWModes softLimitMode); + + /// Gets the software limits mode. + /// The device serial no. + /// The software limits mode + /// Disable any move outside of the current travel range of the stage. 0 + /// Truncate moves to within the current travel range of the stage. 1 + /// Allow all moves, regardless of whether they are within the current travel range of the stage. 2 + /// . + /// The software limits mode. + /// + KCUBEDCSERVO_API MOT_LimitsSoftwareApproachPolicy __cdecl CC_GetSoftLimitMode(char const * serialNo); + + /// Sets the software limits mode. + /// The device serial no. + /// The soft limit mode + /// + /// Disable any move outside of the current travel range of the stage. 0 + /// Truncate moves to within the current travel range of the stage. 1 + /// Allow all moves, regardless of whether they are within the current travel range of the stage. 2 + /// + /// + KCUBEDCSERVO_API void __cdecl CC_SetLimitsSoftwareApproachPolicy(char const * serialNo, MOT_LimitsSoftwareApproachPolicy limitsSoftwareApproachPolicy); + + /// Requests the MMI Parameters for the KCube Display Interface. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestMMIparams(char const * serialNo); + + /// Get the MMI Parameters for the KCube Display Interface. + /// The device serial no. + /// The device wheel mode. + /// + /// 1Constant Velocity
The device will continue moving until the end stop is reached or the duration of the wheel action
+ /// 2Jog
The device will jog forward or backward according to the wheel action.
+ /// The device will jog according to the Jog parameters
+ /// 3Move Absolute
The device will move to either Preset Po 1 or 2 according to the wheel action.
+ ///
+ /// The wheel maximum velocity in \ref DeviceUnits_page. + /// The wheel acceleration in \ref DeviceUnits_page. + /// The wheel direction sense. + /// The first preset position in \ref DeviceUnits_page. + /// The second preset position in \ref DeviceUnits_page. + /// The display intensity, range 0 to 100%. + /// The display timeout, range 0 to 480 in minutes (0 is off, otherwise the inactivity period before dimming the display). + /// The display dimmed intensity, range 0 to 10 (after the timeout period the device display will dim). + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetMMIParamsExt(char const * serialNo, KMOT_WheelMode *wheelMode, __int32 *wheelMaxVelocity, __int32 *wheelAcceleration, KMOT_WheelDirectionSense *directionSense, + __int32 *presetPosition1, __int32 *presetPosition2, __int16 *displayIntensity, __int16 *displayTimeout, __int16 *displayDimIntensity); + + /// \deprecated + /// Get the MMI Parameters for the KCube Display Interface. + /// superceded by + /// The device serial no. + /// The device wheel mode. + /// + /// 1Constant Velocity
The device will continue moving until the end stop is reached or the duration of the wheel action
+ /// 2Jog
The device will jog forward or backward according to the wheel action.
+ /// The device will jog according to the Jog parameters
+ /// 3Move Absolute
The device will move to either Preset Po 1 or 2 according to the wheel action.
+ ///
+ /// The wheel maximum velocity in \ref DeviceUnits_page. + /// The wheel acceleration in \ref DeviceUnits_page. + /// The wheel direction sense. + /// The first preset position in \ref DeviceUnits_page. + /// The second preset position in \ref DeviceUnits_page. + /// The display intensity, range 0 to 100%. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetMMIParams(char const * serialNo, KMOT_WheelMode *wheelMode, __int32 *wheelMaxVelocity, __int32 *wheelAcceleration, KMOT_WheelDirectionSense *directionSense, + __int32 *presetPosition1, __int32 *presetPosition2, __int16 *displayIntensity); + + /// Set the MMI Parameters for the KCube Display Interface. + /// The device serial no. + /// The device wheel mode. + /// + /// 1Constant Velocity
The device will continue moving until the end stop is reached or the duration of the wheel action
+ /// 2Jog
The device will jog forward or backward according to the wheel action.
+ /// The device will jog according to the Jog parameters
+ /// 3Move Absolute
The device will move to either Preset Po 1 or 2 according to the wheel action.
+ ///
+ /// The wheel maximum velocity in \ref DeviceUnits_page. + /// The wheel acceleration in \ref DeviceUnits_page. + /// The direction sense. + /// The first preset position in \ref DeviceUnits_page. + /// The second preset position in \ref DeviceUnits_page. + /// The display intensity, range 0 to 100%. + /// The display timeout, range 0 to 480 in minutes (0 is off, otherwise the inactivity period before dimming the display). + /// The display dimmed intensity, range 0 to 10 (after the timeout period the device display will dim). + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetMMIParamsExt(char const * serialNo, KMOT_WheelMode wheelMode, __int32 wheelMaxVelocity, __int32 wheelAcceleration, KMOT_WheelDirectionSense directionSense, + __int32 presetPosition1, __int32 presetPosition2, __int16 displayIntensity, __int16 displayTimeout, __int16 displayDimIntensity); + + /// \deprecated + /// Set the MMI Parameters for the KCube Display Interface. + /// superceded by + /// The device serial no. + /// The device wheel mode. + /// + /// 1Constant Velocity
The device will continue moving until the end stop is reached or the duration of the wheel action
+ /// 2Jog
The device will jog forward or backward according to the wheel action.
+ /// The device will jog according to the Jog parameters
+ /// 3Move Absolute
The device will move to either Preset Po 1 or 2 according to the wheel action.
+ ///
+ /// The wheel maximum velocity in \ref DeviceUnits_page. + /// The wheel acceleration in \ref DeviceUnits_page. + /// The direction sense. + /// The first preset position in \ref DeviceUnits_page. + /// The second preset position in \ref DeviceUnits_page. + /// The display intensity, range 0 to 100%. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetMMIParams(char const * serialNo, KMOT_WheelMode wheelMode, __int32 wheelMaxVelocity, __int32 wheelAcceleration, KMOT_WheelDirectionSense directionSense, + __int32 presetPosition1, __int32 presetPosition2, __int16 displayIntensity); + + /// Requests the Trigger Configuration Parameters. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestTriggerConfigParams(char const * serialNo); + + /// Get the Trigger Configuration Parameters. + /// The device serial no. + /// The trigger 1 mode. + /// 0Trigger disabled + /// 1Trigger Input - General purpose logic input ( GetStatusBits) + /// 2Trigger Input - Move relative using relative move parameters + /// 3Trigger Input - Move absolute using absolute move parameters + /// 4Trigger Input - Perform a Home action + /// 10Trigger Output - General purpose output ( SetDigitalOutputs) + /// 11Trigger Output - Set when device moving + /// 12Trigger Output - Set when at max velocity + /// 13Trigger Output - Set when at predefine position steps + /// 14Trigger Output - TBD mode + /// + /// The trigger 1 polarity. + /// 1Output high when set + /// 2Output low when set + /// + /// The trigger 2 mode. + /// 0Trigger disabled + /// 1Trigger Input - General purpose logic input ( GetStatusBits) + /// 2Trigger Input - Move relative using relative move parameters + /// 3Trigger Input - Move absolute using absolute move parameters + /// 4Trigger Input - Perform a Home action + /// 10Trigger Output - General purpose output ( SetDigitalOutputs) + /// 11Trigger Output - Set when device moving + /// 12Trigger Output - Set when at max velocity + /// 13Trigger Output - Set when at predefine position steps + /// 14Trigger Output - TBD mode + /// + /// The trigger 2 polarity. + /// 1Output high when set + /// 2Output low when set + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetTriggerConfigParams(char const * serialNo, KMOT_TriggerPortMode *trigger1Mode, KMOT_TriggerPortPolarity *trigger1Polarity, KMOT_TriggerPortMode *trigger2Mode, KMOT_TriggerPortPolarity *trigger2Polarity); + + /// Set the Trigger Configuration Parameters. + /// The device serial no. + /// The trigger 1 mode. + /// 0Trigger disabled + /// 1Trigger Input - General purpose logic input ( GetStatusBits) + /// 2Trigger Input - Move relative using relative move parameters + /// 3Trigger Input - Move absolute using absolute move parameters + /// 4Trigger Input - Perform a Home action + /// 5Trigger Input - Perform a Stop action + /// 10Trigger Output - General purpose output ( SetDigitalOutputs) + /// 11Trigger Output - Set when device moving + /// 12Trigger Output - Set when at max velocity + /// 13Trigger Output - Set when at predefine position steps + /// 14Trigger Output - TBD mode + /// + /// The trigger 1 polarity. + /// 1Output high when set + /// 2Output low when set + /// + /// The trigger 2 mode. + /// 0Trigger disabled + /// 1Trigger Input - General purpose logic input ( GetStatusBits) + /// 2Trigger Input - Move relative using relative move parameters + /// 3Trigger Input - Move absolute using absolute move parameters + /// 4Trigger Input - Perform a Home action + /// 5Trigger Input - Perform a Stop action + /// 10Trigger Output - General purpose output ( SetDigitalOutputs) + /// 11Trigger Output - Set when device moving + /// 12Trigger Output - Set when at max velocity + /// 13Trigger Output - Set when at predefine position steps + /// 14Trigger Output - TBD mode + /// + /// The trigger 2 polarity. + /// 1Output high when set + /// 2Output low when set + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetTriggerConfigParams(char const * serialNo, KMOT_TriggerPortMode trigger1Mode, KMOT_TriggerPortPolarity trigger1Polarity, KMOT_TriggerPortMode trigger2Mode, KMOT_TriggerPortPolarity trigger2Polarity); + + /// Requests the position trigger parameters. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestPosTriggerParams(char const * serialNo); + + /// Get the Trigger Parameters Parameters. + /// The device serial no. + /// The trigger start position in \ref DeviceUnits_page. + /// The trigger interval in \ref DeviceUnits_page. + /// Number of trigger pulses. + /// The trigger start position in \ref DeviceUnits_page. + /// The trigger interval in \ref DeviceUnits_page. + /// Number of trigger pulses. + /// Width of the trigger pulse in milliseconds, range 1000 (1ms) to 32767000 (32767ms). + /// Number of cycles to perform triggering. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetTriggerParamsParams(char const * serialNo, __int32 *triggerStartPositionFwd, __int32 *triggerIntervalFwd, __int32 *triggerPulseCountFwd, + __int32 *triggerStartPositionRev, __int32 *triggerIntervalRev, __int32 *triggerPulseCountRev, + __int32 *triggerPulseWidth, __int32 *cycleCount); + + /// Set the Trigger Parameters Parameters. + /// The device serial no. + /// The trigger start position in \ref DeviceUnits_page. + /// The trigger interval in \ref DeviceUnits_page. + /// Number of trigger pulses. + /// The trigger start position in \ref DeviceUnits_page. + /// The trigger interval in \ref DeviceUnits_page. + /// Number of trigger pulses. + /// Width of the trigger pulse in milliseconds, range 1000 (1ms) to 32767000 (32767ms). + /// Number of cycles to perform triggering. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetTriggerParamsParams(char const * serialNo, __int32 triggerStartPositionFwd, __int32 triggerIntervalFwd, __int32 triggerPulseCountFwd, + __int32 triggerStartPositionRev, __int32 triggerIntervalRev, __int32 triggerPulseCountRev, + __int32 triggerPulseWidth, __int32 cycleCount); + + /// Gets the MMI parameters for the device. + /// The device serial no. + /// Options for controlling the mmi. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetMMIParamsBlock(char const * serialNo, KMOT_MMIParams *mmiParams); + + /// Sets the MMI parameters for the device. + /// The device serial no. + /// Options for controlling the mmi. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetMMIParamsBlock(char const * serialNo, KMOT_MMIParams *mmiParams); + + /// Gets the trigger configuration parameters block. + /// The device serial no. + /// Options for controlling the trigger configuration. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetTriggerConfigParamsBlock(char const * serialNo, KMOT_TriggerConfig *triggerConfigParams); + + /// Sets the trigger configuration parameters block. + /// The device serial no. + /// Options for controlling the trigger configuration. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetTriggerConfigParamsBlock(char const * serialNo, KMOT_TriggerConfig *triggerConfigParams); + + /// Gets the trigger parameters block. + /// The device serial no. + /// Options for controlling the trigger. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetTriggerParamsParamsBlock(char const * serialNo, KMOT_TriggerParams *triggerParamsParams); + + /// Sets the trigger parameters block. + /// The device serial no. + /// Options for controlling the trigger. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetTriggerParamsParamsBlock(char const * serialNo, KMOT_TriggerParams *triggerParamsParams); + + /// Get the move velocity parameters. + /// see \ref C_MOTOR_sec11 "Positioning" for more detail. + /// The device serial no. + /// Address of the MOT_VelocityParameters to recieve the velocity parameters. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_movepars.cpp + KCUBEDCSERVO_API short __cdecl CC_GetVelParamsBlock(const char * serialNo, MOT_VelocityParameters *velocityParams); + + /// Set the move velocity parameters. + /// see \ref C_MOTOR_sec11 "Positioning" for more detail. + /// The device serial no. + /// The address of the MOT_VelocityParameters holding the new velocity parameters. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_movepars.cpp + KCUBEDCSERVO_API short __cdecl CC_SetVelParamsBlock(const char * serialNo, MOT_VelocityParameters *velocityParams); + + /// Sets the move absolute position. + /// The device serial no. + /// The absolute position in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetMoveAbsolutePosition(const char * serialNo, int position); + + /// Requests the position of next absolute move. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestMoveAbsolutePosition(char const * serialNo); + + /// Gets the move absolute position. + /// The device serial no. + /// The move absolute position in \ref DeviceUnits_page. + /// + /// + /// + KCUBEDCSERVO_API int __cdecl CC_GetMoveAbsolutePosition(const char * serialNo); + + /// Moves the device to the position defined in the SetMoveAbsolute command. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_MoveAbsolute(const char * serialNo); + + /// Sets the move relative distance. + /// The device serial no. + /// The relative distance in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetMoveRelativeDistance(const char * serialNo, int distance); + + /// Requests the relative move distance. + /// The serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestMoveRelativeDistance(char const * serialNo); + + /// Gets the move relative distance. + /// The device serial no. + /// The move relative distance in \ref DeviceUnits_page. + /// + /// + /// + KCUBEDCSERVO_API int __cdecl CC_GetMoveRelativeDistance(const char * serialNo); + + /// Moves the device by a relative distancce defined by SetMoveRelativeDistance. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_MoveRelativeDistance(const char * serialNo); + + /// Get the homing parameters. + /// see \ref C_MOTOR_sec10 "Homing" for more detail. + /// The device serial no. + /// Address of the MOT_HomingParameters to recieve the homing parameters. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetHomingParamsBlock(const char * serialNo, MOT_HomingParameters *homingParams); + + /// Set the homing parameters. + /// see \ref C_MOTOR_sec10 "Homing" for more detail. + /// The device serial no. + /// Address of the new homing parameters. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetHomingParamsBlock(const char * serialNo, MOT_HomingParameters *homingParams); + + /// Get the jog parameters. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The address of the MOT_JogParameters block to recieve the jog parameters + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API short __cdecl CC_GetJogParamsBlock(const char * serialNo, MOT_JogParameters *jogParams); + + /// Set the jog parameters. + /// see \ref C_MOTOR_sec12 "Jogging" for more detail. + /// The device serial no. + /// The address of the new MOT_JogParameters block. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + /// + /// + /// + /// + /// \include CodeSnippet_jogpars.cpp + KCUBEDCSERVO_API short __cdecl CC_SetJogParamsBlock(const char * serialNo, MOT_JogParameters *jogParams); + + /// Get the limit switch parameters. + /// The device serial no. + /// Address of the MOT_LimitSwitchParameters parameter to recieve the limit switch parameters. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetLimitSwitchParamsBlock(const char * serialNo, MOT_LimitSwitchParameters *limitSwitchParams); + + /// Set the limit switch parameters. + /// The device serial no. + /// Address of the MOT_LimitSwitchParameters parameter containing the new limit switch parameters. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetLimitSwitchParamsBlock(const char * serialNo, MOT_LimitSwitchParameters *limitSwitchParams); + + /// Request the PID parameters for DC motors used in an algorithm involving calculus. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestDCPIDParams(const char * serialNo); + + /// Get the DC PID parameters for DC motors used in an algorithm involving calculus. + /// The device serial no. + /// [in,out] If non-null, a variable-length parameters list containing DC PID parameters. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_GetDCPIDParams(const char * serialNo, MOT_DC_PIDParameters *DCproportionalIntegralDerivativeParams); + + /// Set the PID parameters for DC motors used in an algorithm involving calculus. + /// The device serial no. + /// [in,out] If non-null, a variable-length parameters list containing DC PID parameters. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetDCPIDParams(const char * serialNo, MOT_DC_PIDParameters *DCproportionalIntegralDerivativeParams); + + + /// Suspend automatic messages at ends of moves. + /// Useful to speed up part of real-time system with lots of short moves. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_SuspendMoveMessages(char const * serialNo); + + /// Resume suspended move messages. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_ResumeMoveMessages(char const * serialNo); + + /// Requests the current position. + /// This needs to be called to get the device to send it's current position.
+ /// NOTE this is called automatically if Polling is enabled for the device using .
+ /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successfully requested. + /// \include CodeSnippet_move.cpp + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestPosition(char const * serialNo); + + /// Request the status bits which identify the current motor state. + /// This needs to be called to get the device to send it's current status bits.
+ /// NOTE this is called automatically if Polling is enabled for the device using .
+ /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successfully requested. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestStatusBits(char const * serialNo); + + /// Get the current status bits. + /// This returns the latest status bits received from the device.
+ /// To get new status bits, use + /// or use the polling functions, .
+ /// The device serial no. + /// The status bits from the device + /// 0x00000001CW hardware limit switch (0=No contact, 1=Contact). + /// 0x00000002CCW hardware limit switch (0=No contact, 1=Contact). + /// 0x00000004Not applicable. + /// 0x00000008Not applicable. + /// 0x00000010Motor shaft moving clockwise (1=Moving, 0=Stationary). + /// 0x00000020Motor shaft moving counterclockwise (1=Moving, 0=Stationary). + /// 0x00000040Shaft jogging clockwise (1=Moving, 0=Stationary). + /// 0x00000080Shaft jogging counterclockwise (1=Moving, 0=Stationary). + /// 0x00000100Not applicable. + /// 0x00000200Motor homing (1=Homing, 0=Not homing). + /// 0x00000400Motor homed (1=Homed, 0=Not homed). + /// 0x00000800For Future Use. + /// 0x00001000Not applicable. + /// 0x00002000 + /// ... + /// 0x00080000 + /// 0x00100000General Digital Input 1. + /// 0x00200000General Digital Input 2. + /// 0x00400000General Digital Input 3. + /// 0x00800000General Digital Input 4. + /// 0x01000000General Digital Input 5. + /// 0x02000000General Digital Input 6. + /// 0x04000000For Future Use. + /// 0x08000000For Future Use. + /// 0x10000000For Future Use. + /// 0x20000000Active (1=Active, 0=Not active). + /// 0x40000000For Future Use. + /// 0x80000000Channel enabled (1=Enabled, 0=Disabled). + /// . + /// + /// + KCUBEDCSERVO_API DWORD __cdecl CC_GetStatusBits(char const * serialNo); + + /// Starts the internal polling loop which continuously requests position and status. + /// The device serial no. + /// The milliseconds polling rate. + /// true if successful, false if not. + /// + /// + /// + /// + /// \include CodeSnippet_connection1.cpp + KCUBEDCSERVO_API bool __cdecl CC_StartPolling(char const * serialNo, int milliseconds); + + /// Gets the polling loop duration. + /// The device serial no. + /// The time between polls in milliseconds or 0 if polling is not active. + /// + /// + /// \include CodeSnippet_connection1.cpp + KCUBEDCSERVO_API long __cdecl CC_PollingDuration(char const * serialNo); + + /// Stops the internal polling loop. + /// The device serial no. + /// + /// + /// \include CodeSnippet_connection1.cpp + KCUBEDCSERVO_API void __cdecl CC_StopPolling(char const * serialNo); + + /// Gets the time in milliseconds since tha last message was received from the device. + /// This can be used to determine whether communications with the device is still good + /// The device serial no. + /// The time since the last message was received in milliseconds. + /// True if monitoring is enabled otherwize False. + /// + /// + /// \include CodeSnippet_connectionMonitoring.cpp + KCUBEDCSERVO_API bool __cdecl CC_TimeSinceLastMsgReceived(char const * serialNo, __int64 &lastUpdateTimeMS); + + /// Enables the last message monitoring timer. + /// This can be used to determine whether communications with the device is still good + /// The device serial no. + /// True to enable monitoring otherwise False to disable. + /// The last message error timeout in ms. 0 to disable. + /// + /// + /// \include CodeSnippet_connectionMonitoring.cpp + KCUBEDCSERVO_API void __cdecl CC_EnableLastMsgTimer(char const * serialNo, bool enable, __int32 lastMsgTimeout); + + /// Queries if the time since the last message has exceeded the lastMsgTimeout set by . + /// This can be used to determine whether communications with the device is still good + /// The device serial no. + /// True if last message timer has elapsed, False if monitoring is not enabled or if time of last message received is less than lastMsgTimeout. + /// + /// + /// \include CodeSnippet_connectionMonitoring.cpp + KCUBEDCSERVO_API bool __cdecl CC_HasLastMsgTimerOverrun(char const * serialNo); + + /// Requests that all settings are download from device. + /// This function requests that the device upload all it's settings to the DLL. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successfully requested. + KCUBEDCSERVO_API short __cdecl CC_RequestSettings(char const * serialNo); + + /// Gets the DC Motor minimum stage position. + /// The device serial no. + /// The Minimum position in \ref DeviceUnits_page. + /// + /// + KCUBEDCSERVO_API int __cdecl CC_GetStageAxisMinPos(char const * serialNo); + + /// Gets the DC Motor maximum stage position. + /// The device serial no. + /// The Maximum position in \ref DeviceUnits_page. + /// + /// + KCUBEDCSERVO_API int __cdecl CC_GetStageAxisMaxPos(char const * serialNo); + + /// Sets the stage axis position limits. + /// This function sets the limits of travel for the stage.
+ /// The implementation will depend upon the nature of the travel being requested and the Soft Limits mode which can be obtained using .
+ /// MoveAbsolute, MoveRelative and Jog (Single Step) will obey the Soft Limit Mode. + /// If the target position is outside the limits then either a full move, a partial move or no move will occur.
+ /// Jog (Continuous) and Move Continuous will attempt to obey the limits, but as these moves rely on position information feedback from the device to detect if the travel is exceeding the limits, the device will stop, but it is likely to overshoot the limit, especially at high velocity.
+ /// Home will always ignore the software limits.
+ /// The device serial no. + /// The minimum position in \ref DeviceUnits_page. + /// The maximum position in \ref DeviceUnits_page. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetStageAxisLimits(char const * serialNo, int minPosition, int maxPosition); + + /// Set the motor travel mode. + /// The device serial no. + /// The travel mode. + /// + /// Linear motion1 + /// Rotational motion2 + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_SetMotorTravelMode(char const * serialNo, MOT_TravelModes travelMode); + + /// Get the motor travel mode. + /// The device serial no. + /// The travel mode. + /// + /// Linear motion1 + /// Rotational motion2 + /// + /// + KCUBEDCSERVO_API MOT_TravelModes __cdecl CC_GetMotorTravelMode(char const * serialNo); + + /// \deprecated + /// Sets the motor stage parameters. + /// superceded by + /// These parameters, when combined define the stage motion in terms of \ref RealWorldUnits_page. (mm or degrees)
+ /// The real world unit is defined from stepsPerRev * gearBoxRatio / pitch.
+ /// The device serial no. + /// The steps per revolution. + /// The gear box ratio. + /// The pitch. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_SetMotorParams(char const * serialNo, long stepsPerRev, long gearBoxRatio, float pitch); + + /// \deprecated + /// Gets the motor stage parameters. + /// superceded by + /// These parameters, when combined define the stage motion in terms of \ref RealWorldUnits_page. (mm or degrees)
+ /// The real world unit is defined from stepsPerRev * gearBoxRatio / pitch.
+ /// The device serial no. + /// Address of the parameter to receive the steps per revolution. + /// Address of the parameter to receive the gear box ratio. + /// Address of the parameter to receive the pitch. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_GetMotorParams(char const * serialNo, long *stepsPerRev, long *gearBoxRatio, float *pitch); + + /// Sets the motor stage parameters. + /// These parameters, when combined define the stage motion in terms of \ref RealWorldUnits_page. (mm or degrees)
+ /// The real world unit is defined from stepsPerRev * gearBoxRatio / pitch.
+ /// The device serial no. + /// The steps per revolution. + /// The gear box ratio. + /// The pitch. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_SetMotorParamsExt(char const * serialNo, double stepsPerRev, double gearBoxRatio, double pitch); + + /// Gets the motor stage parameters. + /// These parameters, when combined define the stage motion in terms of \ref RealWorldUnits_page. (mm or degrees)
+ /// The real world unit is defined from stepsPerRev * gearBoxRatio / pitch.
+ /// The device serial no. + /// Address of the parameter to receive the steps per revolution. + /// Address of the parameter to receive the gear box ratio. + /// Address of the parameter to receive the pitch. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_GetMotorParamsExt(char const * serialNo, double *stepsPerRev, double *gearBoxRatio, double *pitch); + + /// \deprecated + /// Sets the absolute maximum velocity and acceleration constants for the current stage. + /// These parameters are maintained for user info only and do not reflect the current stage parameters.
+ /// The absolute maximum velocity and acceleration constants are initialized from the stage settings..
+ /// The device serial no. + /// The absolute maximum velocity in real world units. + /// The absolute maximum acceleration in real world units. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_SetMotorVelocityLimits(char const * serialNo, double maxVelocity, double maxAcceleration); + + /// Gets the absolute maximum velocity and acceleration constants for the current stage. + /// These parameters are maintained for user info only and do not reflect the current stage parameters.
+ /// The absolute maximum velocity and acceleration constants are initialized from the stage settings..
+ /// The device serial no. + /// Address of the parameter to receive the absolute maximum velocity in real world units. + /// Address of the parameter to receive the absolute maximum acceleration in real world units. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_GetMotorVelocityLimits(char const * serialNo, double *maxVelocity, double *maxAcceleration); + + /// Reset the rotation modes for a rotational device. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_ResetRotationModes(char const * serialNo); + + /// Set the rotation modes for a rotational device. + /// The device serial no. + /// The rotation mode. + /// Linear Range (Fixed Limit, cannot rotate)0 + /// RotationalUnlimited (Ranges between +/- Infinity)1 + /// Rotational Wrapping (Ranges between 0 to 360 with wrapping)2 + /// + /// The rotation direction when moving between two angles. + /// Quickets (Always takes the shortedt path)0 + /// Forwards (Always moves forwards)1 + /// Backwards (Always moves backwards)2 + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_SetRotationModes(char const * serialNo, MOT_MovementModes mode, MOT_MovementDirections direction); + + /// \deprecated + /// Sets the absolute minimum and maximum travel range constants for the current stage. + /// These parameters are maintained for user info only and do not reflect the current travel range of the stage.
+ /// The absolute minimum and maximum travel range constants are initialized from the stage settings. These values can be adjusted to relative positions based upon the Home Offset.
+ ///
+ /// To set the working travel range of the stage use the function
+ /// Use the following to convert between real worl and device units.
+ ///
+ ///
+ /// The device serial no. + /// The absolute minimum position in real world units. + /// The absolute maximum position in real world units. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_SetMotorTravelLimits(char const * serialNo, double minPosition, double maxPosition); + + /// Gets the absolute minimum and maximum travel range constants for the current stage. + /// These parameters are maintained for user info only and do not reflect the current travel range of the stage.
+ /// The absolute minimum and maximum travel range constants are initialized from the stage settings. These values can be adjusted to relative positions based upon the Home Offset.
+ /// The device serial no. + /// Address of the parameter to receive the absolute minimum position in real world units. + /// Address of the parameter to receive the absolute maximum position in real world units. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_GetMotorTravelLimits(char const * serialNo, double *minPosition, double *maxPosition); + + /// Converts a device unit to a real world unit. + /// The serial no. + /// The device unit. + /// The real unit. + /// Type of the unit. + /// Distance0 + /// Velocity1 + /// Acceleration2 + /// + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + KCUBEDCSERVO_API short __cdecl CC_GetRealValueFromDeviceUnit(char const * serialNo, int device_unit, double *real_unit, int unitType); + + /// Converts a device unit to a real world unit. + /// The serial no. + /// The device unit. + /// The real unit. + /// Type of the unit. + /// Distance0 + /// Velocity1 + /// Acceleration2 + /// + /// Success. + /// + KCUBEDCSERVO_API short __cdecl CC_GetDeviceUnitFromRealValue(char const * serialNo, double real_unit, int *device_unit, int unitType); + + /// Requests the digital output bits. + /// The device serial no. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_RequestDigitalOutputs(char const * serialNo); + + /// Gets the digital output bits. + /// The device serial no. + /// Bit mask of states of the 4 digital output pins. + /// + /// + KCUBEDCSERVO_API byte __cdecl CC_GetDigitalOutputs(char const * serialNo); + + /// Sets the digital output bits. + /// The device serial no. + /// Bit mask to set states of the 4 digital output pins. + /// The error code (see \ref C_DLL_ERRORCODES_page "Error Codes") or zero if successful. + /// + /// + KCUBEDCSERVO_API short __cdecl CC_SetDigitalOutputs(char const * serialNo, byte outputsBits); +/** @} */ // KCubeDCServo +} diff --git a/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.lib b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.lib new file mode 100644 index 00000000..cc302686 Binary files /dev/null and b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServo.lib differ diff --git a/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServoUI.dll b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServoUI.dll new file mode 100644 index 00000000..0f8f5980 Binary files /dev/null and b/sashimi/hardware/stage_motors/KDC101/dlls_servo/Thorlabs.MotionControl.KCube.DCServoUI.dll differ diff --git a/sashimi/hardware/stage_motors/KDC101/interface.py b/sashimi/hardware/stage_motors/KDC101/interface.py new file mode 100644 index 00000000..4d1ca7ec --- /dev/null +++ b/sashimi/hardware/stage_motors/KDC101/interface.py @@ -0,0 +1,282 @@ +import KDC101.KCube_py_int as kdc +from ctypes import ( + c_short, + c_int, + c_char_p, + byref, +) +import time +import numpy as np +import pandas as pd +from time import sleep +from interface import AbstractMotor +from KDC101.utils import * + +#Building our functions on top of the KCube class from Thorlabs +class KC_motor(AbstractMotor): + """ + Class to initialize and controll the stage motors (KDC101 thorlabs) + + Methods + + """ + + # Default values set for each motor upon initialization, can be altered + def __init__(self, serial_no, poll=200, pause=0.4, acc=800, vel=2e6, + motor_axis=str, max_range=13.0, verbose=False): + super().__init__(serial_no, max_range) + """ + + Parameters + ---------- + serial_no = id of the motor + poll = polling every n ms + pause = wait time for initializazion and command sending + acc = acceleration + vel = velocity + motor_axis = axis of the motor + max_range = maximum range of the motor + verbose = if True prints out each step + + isOpen = is the motor active + msg = array of messages to keep track of errors + """ + + self.id = c_char_p(bytes(serial_no, "utf-8")) + self.poll = c_int(poll) + self._pause = pause + self.acc = kdc.c_int(acc) + self.vel = kdc.c_int(int(vel)) + self.msg = [] + self.verbose = verbose + self.motor_axis = motor_axis #x,y,z for logging + self.max_range = max_range + + self.max_vel = kdc.c_int(int(2e7)) # to work on it +# self.acc = kdc.c_int(2000) # to work on it + + self.isOpen = False + + + def clear_msg(self): + self.msg = [] + + @property + def axis(self): + return self.motor_axis + + @property + def get_id(self): + return self.id + + @property + def polling(self): + return self.poll + + @polling.setter + def polling(self, polling_ms=200): + self.poll = c_int(polling_ms) + + # if motor already open reset polling + if self.isOpen: + kdc.CC_StartPolling(self.id, self.poll) + self.msg.append("Start - Polling at " + str(self.poll)) + + @property + def pause(self): + return self._pause + + @pause.setter + def pause(self, sleep_s = 0.4): + self._pause = sleep_s + + @property + def verbose(self): + return self.ver + + @verbose.setter + def verbose(self, verb=False): + self.ver = verb + + @property + def maximum_range(self): + return self.max_range + + @maximum_range.setter + def maximum_range(self, max_range=13.0): + self.max_range = float(max_range) + + @property + def position_abs(self): + return kdc.CC_GetPosition(self.id) + + @property + def position_mm(self): + return abs_to_mm(kdc.CC_GetPosition(self.id), False) + + + def get_vel_params(self): + """ + Gets the velocity parameters: + - acceleration + - velocity + """ + # request parameters + if kdc.CC_RequestVelParams(self.id) == 0: + self.msg.append("Requested vel Params.") + + # get parameters + if kdc.CC_GetVelParams(self.id, byref(self.acc), byref(self.vel)) == 0: + self.msg.append(f"acc = {self.acc} - max_vel = {self.vel}.") + + if self.ver: + return [self.acc, self.max_vel, self.msg] + else: + return [self.acc, self.max_vel] + else: + self.msg.append("Error - Couldn't get vel params.") + if self.ver: + return self.msg + else: + self.msg.append("Error - Couldn't request vel params.") + if self.ver: + return self.msg + + + def set_vel_params(self, acc = 800, vel = 2e6): + """ + + Gets the velocity parameters: + - acceleration + - velocity + + """ + # request parameters + if kdc.CC_RequestVelParams(self.id) == 0: + self.msg.append("Requested vel Params.") + + self.acc = kdc.c_int(int(acc)) + self.max_vel = kdc.c_int(int(vel)) + + # set parameters + kdc.CC_SetVelParams(self.id, self.acc, self.max_vel) + self.msg.append(f"Setted - acc = {self.acc} - max_vel = {self.max_vel}.") + + else: + self.msg.append("Error - Couldn't set vel params.") + + if self.ver: + return self.msg + + def start(self): + """ + Starts the motor + """ + if kdc.TLI_BuildDeviceList() == 0: + self.msg.append("Start - Device list builded correctly.") + + if kdc.CC_Open(self.id) == 0: + self.msg.append(f"Start - Opening motor {self.id}.") + self.isOpen = True + + # start polling + kdc.CC_StartPolling(self.id, self.poll) + self.msg.append("Start - Polling at {self.poll}.") + + # clear message queue + kdc.CC_ClearMessageQueue(self.id) + self.msg.append("Start - Message queue cleared.") + + + else: + self.msg.append(f"Start - Error: Can't Open {self.id}.") + + else: + self.msg.append("Start - Error: Can't build device list.") + + if self.ver: + return self.msg + + def stop(self): + """ + Stops the motor (only use when finished) + """ + kdc.CC_StopPolling(self.id) + self.msg.append("Stop - polling stopped.") + + if kdc.CC_Close(self.id) == 0: + self.msg.append("Stop - motor closed.") + self.isOpen = False + + else: + self.msg.append("Stop - Error: couldn't close the motor.") + + if self.ver: + return self.msg + + def home(self): + """ + Homes the motor: + otherwise the motor will save as zero the last position used + """ + if kdc.CC_Home(self.id) == 0: + self.msg.append("Homing started.") + sleep(self._pause) + + else: + self.msg.append("Couldn't home.") + + if self.ver: + return self.msg + + def move_to_abs(self, position): + """ + Parameters + ---------- + position = absolute value of where to move the motor + + no safeguard: if the position is bigger than + the maximum range the motor + may get stucked + """ + + # set move position + kdc.CC_SetMoveAbsolutePosition(self.id, c_int(position)) + + # move to position + kdc.CC_MoveAbsolute(self.id) + self.msg.append(f"Moving to {position}") + sleep(self._pause) + + if self.ver: + return self.msg + + def move_to(self, position): + """ + Parameters + ---------- + position = value of where to move the motor in mm + + safeguard: if the position is bigger than the max range then it skips + + """ + if self.check_limits(position): + self.move_to_abs(abs_to_mm(position, True)) + else: + self.msg.append("Error - position is greater than max range! {} > {}".format(position,self.max_range)) + + if self.ver: + return self.msg + + def check_limits(self, mm_position): + """ + Checks if a given position is within the maximum range of the motor + + Returns: True or False + + """ +# print(mm_position) + if self.max_range >= mm_position: + return True + else: + return False diff --git a/sashimi/hardware/stage_motors/KDC101/utils.py b/sashimi/hardware/stage_motors/KDC101/utils.py new file mode 100644 index 00000000..9c150026 --- /dev/null +++ b/sashimi/hardware/stage_motors/KDC101/utils.py @@ -0,0 +1,260 @@ +import numpy as np +from time import sleep,time,ctime + + + + +def abs_to_mm(value, inverse): + """ + + Parameters + ---------- + value: a int or array of positions (either in mm or absolute value) + inverse: if False performs abs->mm + if True performs mm->abs + + Returns + ------- + does not return anything, but modifies the input + + """ + + + x1m = 1.0013 + x1a = 34350 + alpha = x1m / x1a + beta = 1 / alpha + + if isinstance(value, int): + if inverse: + return int(value * beta) + else: + return value * alpha + else: # assume is array + if inverse: + return (np.array(value) * beta).astype(int) + else: + return np.array(value) * alpha + + + + + +###################### MULTI-MOTOR UTILS (3 - X,Y,Z) ############################ +def close_motors(motors): + """ + Close every motor in a list + """ + for mot in motors: + #start the motor + mot.stop() + sleep(mot._pause) + + +def init_motors(motors, poll=200, pause=0.3, acc=800, vel=2e6, verbose = False, home = False): + """ + Initialize every motor in a list + """ + + for mot in motors: + #polling + mot.polling = poll + #pause + mot._pause = pause + #verbose + mot.verbose = verbose + mot.set_vel_params(acc, vel) + + #start the motor + mot.start() + sleep(mot._pause) + + if home: + home_motors(motors) + +def home_motors(motors): + """ + Home every motor in a list + """ + + for mot in motors: + mot.home() + sleep(mot._pause) + + + safety_counter = 0 + pos = [round(mot.position_mm, 3) for mot in motors] + + while not all(np.subtract(pos,0) == 0): + + pos = [round(mot.position_mm, 3) for mot in motors] + sleep(motors[0]._pause * 2) + + safety_counter +=1 + + if safety_counter > 70: + print("Homing Failed - Timer runout!") + break + + if all(np.subtract(pos,0) == 0): + print("Homing Succeded") + +################################################## +def reached_target(pos, goal,ths = int(100 - 1e-3)): + """ + check if the motor has reached the target + """ + if isinstance(pos, np.ndarray) or isinstance(pos, list): + + acc = np.array([ 100*(1-abs((pos[i]-goal[i])/goal[i])) for i in range(len(pos))]) + + #if accuracy is negative set it to zero + acc[acc<0] = 0 + + + if pos == goal:#safety check + return True + + #return true if all of the elements are above threshold + return all(acc>ths) + + elif isinstance(pos, float) or isinstance(pos, int): + #compute percentage accuracy + acc = 100*(1-abs((pos-goal)/goal)) + + #if accuracy is negative set it to zero + if acc < 0: + acc = 0 + + #return true if above threshold + return (acc>ths) + + else: + print(pos, goal) + raise ValueError("input type cannot be handled, try using a float, int or array") + + + +def move_to_mm(motors, end_pos, ths = 100-1e-3, verbose = False): + """ + Move multiple motors to each location [mot1,mot2] -> [pos1, pos2] + the positions must me in mm + + Returns: + dictionary with metadata: + -'End_x','End_y','End_z' = target position + -'Pos x','Pos y','Pos z' = actual final position + -'Date' + -'Time Stamp' + """ + + #get position + pos = [mot.position_mm for mot in motors] + + #check if end pos elements equal pos + check = abs(np.subtract(pos,end_pos)) > abs(ths -100) + + if len(motors) != len(pos): + print("Error - motors and end_pos should have the same length") + return + else: + #Moning the motors + for i, mot in enumerate(motors): + #if i am not already there, move + if check[i]: +# print("moving mot ", i) + mot.move_to(end_pos[i]) + + #feedback motor moving + while not reached_target(pos, end_pos, ths): + #get position + pos = [mot.position_mm for mot in motors] + sleep(motors[0]._pause) + + if verbose: + + print("Moving motors..") + for i, p in enumerate(pos): + print(f"Motor - pos = {p} - desired pos = {end_pos[i]}") + + t = time() #target reached + + #motor at the desired position + if verbose: + + print("Motors position:") + for i, p in enumerate(pos): + print(f"Motor - pos = {p} - desired pos = {end_pos[i]}") + + return {'End_x': end_pos[0], + 'End_y': end_pos[1], + 'End_z': end_pos[2], + 'Pos x': pos[0], + 'Pos y': pos[1], + 'Pos z': pos[2], + 'Date': ctime(t), + 'Time Stamp': t} + +def move_to_abs(motors, end_pos, ths = 100-1e-3, verbose = False): + + """ + Move multiple motors to each location [mot1,mot2] -> [pos1, pos2] + the positions must me in abs + + Returns: + dictionary with metadata: + -'End_x','End_y','End_z' = target position + -'Pos x','Pos y','Pos z' = actual final position + -'Date' + -'Time Stamp' + """ + + #get position + pos = [mot.position_abs for mot in motors] + + #check if end pos elements equal pos + check = abs(np.subtract(pos,end_pos)) > abs(ths -100) + + if len(motors) != len(pos): + print("Error - motors and end_pos should have the same length") + return + else: + #Moning the motors + for i, mot in enumerate(motors): + #if i am not already there, move + if check[i]: +# print("moving mot ", i) + mot.move_to_abs(end_pos[i]) + + #feedback motor moving + while not reached_target(pos, end_pos, ths): + #get position + pos = [mot.position_abs for mot in motors] + sleep(motors[0]._pause) + + if verbose: + + print("Moving motors..") + for i, p in enumerate(pos): + print(f"Motor - pos = {p} - desired pos = {end_pos[i]}") + + t = time() #target reached + + #motor at the desired position + if verbose: + + print("Motors position:") + for i, p in enumerate(pos): + print(f"Motor - pos = {p} - desired pos = {end_pos[i]}") + + return {'End_x': end_pos[0], + 'End_y': end_pos[1], + 'End_z': end_pos[2], + 'Pos x': pos[0], + 'Pos y': pos[1], + 'Pos z': pos[2], + 'Date': ctime(t), + 'Time Stamp': t} + + + diff --git a/sashimi/hardware/stage_motors/__init__.py b/sashimi/hardware/stage_motors/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sashimi/hardware/stage_motors/interface.py b/sashimi/hardware/stage_motors/interface.py new file mode 100644 index 00000000..16d71d8e --- /dev/null +++ b/sashimi/hardware/stage_motors/interface.py @@ -0,0 +1,43 @@ + +class AbstractMotor: + def __init__(self, serial_no, max_range=None): + self.serial_no = serial_no + self.max_range = max_range + + @property + def get_id(self): + pass + + def start(self): + """ + Starts the motor + """ + pass + + def stop(self): + """ + Stops the motor + """ + pass + + def home(self): + """ + Homes the motor + """ + pass + + @property + def position(self): + """ + + Returns + -------Motor position + + """ + pass + + def move_to(self, pos): + """ + Moves the motor to desired position + """ + pass \ No newline at end of file diff --git a/sashimi/state.py b/sashimi/state.py index 8b4cd2c6..88d25be4 100644 --- a/sashimi/state.py +++ b/sashimi/state.py @@ -102,6 +102,15 @@ def __init__(self): self.lateral = Param(0.0, (-2.0, 2.0), gui="slider") self.frontal = Param(0.0, (-2.0, 2.0), gui="slider") +# stage motors setting for LFM +class StageMotorSettings(ParametrizedQt): + def __init__(self): + super().__init__() + self.name = "Stage Motors" + self.z_axis = Param(1.0, (0.0, 13.0), unit="mm", gui="slider") + self.x_axis = Param(1.0, (0.0, 13.0), unit="mm", gui="slider") + self.y_axis = Param(1.0, (0.0, 13.0), unit="mm", gui="slider") + class SinglePlaneSettings(ParametrizedQt): def __init__(self): @@ -389,6 +398,7 @@ def __init__(self): self.global_state = GlobalState.PAUSED self.planar_setting = PlanarScanningSettings() + self.stage_setting = StageMotorSettings() self.light_source_settings = LightSourceSettings() self.light_source_settings.params.intensity.unit = ( self.light_source.intensity_units @@ -402,6 +412,7 @@ def __init__(self): for setting in [ self.planar_setting, + self.stage_setting, self.light_source_settings, self.single_plane_settings, self.volume_setting,