qpit / thorlabs_apt Goto Github PK
View Code? Open in Web Editor NEWpython module for Thorlabs' APT library
License: GNU General Public License v2.0
python module for Thorlabs' APT library
License: GNU General Public License v2.0
Upon connection the controller reports, that is at rev limit and can only be moved clockwise.
When using the Thorlabs K10CR1 motor, it appears the default velocity settings are incorrect. When move_to()
is used, the device becomes unresponsive. The device is in the 'moving' state but does not actually move. When the velocity settings are explicitly set, the device works:
import thorlabs_apt as apt
at = apt.Motor(55000488)
at.set_velocity_parameters(0,20,10)
at.set_move_home_parameters(2,1,10,4)
at.move_home()
Hello,
Why when we turn the position with move_to() , we hear some noise after ?
(i fixed the problem by using desable() )
Thanks
Hello,
can you improve the installation of the package? Step 3 of the instruction to copy manually the apt.dll is not the way to do that!
One possible option would be to add the folder to envirnmental variables.
Hello,
I am trying to implement python code for a NR360 with a BSC201.
I can move the motor. Although I am a bit confused where it actually moves to with certain commands. Which function returns the absolute position (if it was homed first)? I found in the APT Communications Protocol MGMSG_MOT_GET_POSCOUNTER. Is it possible this is not implemented in the code or are you using a different function for returning the position?
And I need to read out the Control IO. I can't seem to identify the appropriate functions for that either.
Any help would be greatly appreciated.
Thanks
Hello, I am trying to interface Thorlabs apt motion controller using a python script.
I am looking at the instruction on your github page GitHub - qpit/thorlabs_apt: python module for Thorlabs' APT library
In step #3 of the installation instruction, you mention that I should copy APT.dll from APT installation path\APT Server directory to Windows\System32 location.
I tried this option but when I try:
Import thorlabs_apt as apt
My program will crash without giving me any errors.
If I remove the APT.dll from Windows\System32 location, it generates the following errors:
File "C:\Users\aidenlee1\AppData\Roaming\Python\Python37\site-packages\shiboken2\files.dir\shibokensupport_feature_.py", line 142, in import
return original_import(name, *args, *kwargs)
File "C:\Users\aidenlee1*hidden", line 5, in
import thorlabs_apt as apt
File "C:\Users\aidenlee1\AppData\Roaming\Python\Python37\site-packages\shiboken2\files.dir\shibokensupport_feature.py", line 142, in import
return original_import(name, *args, *kwargs)
File "C:\Users\aidenlee1\Anaconda3\envs*hidden\lib\site-packages\thorlabs_apt_init.py", line 1, in
from .core import *
File "C:\Users\aidenlee1\AppData\Roaming\Python\Python37\site-packages\shiboken2\files.dir\shibokensupport_feature_.py", line 142, in import
return original_import(name, args, kwargs)
File "C:\Users\aidenlee1\Anaconda3\envs*hidden\lib\site-packages\thorlabs_apt\core.py", line 1376, in
_lib = _load_library()
File "C:\Users\aidenlee1\Anaconda3\envs*hidden\lib\site-packages\thorlabs_apt\core.py", line 1360, in _load_library
lib = ctypes.windll.LoadLibrary(filename)
File "C:\Users\aidenlee1\Anaconda3\envs*hidden\lib\ctypes_init.py", line 442, in LoadLibrary
return self.dlltype(name)
File "C:\Users\aidenlee1\Anaconda3\envs*hidden*\lib\ctypes_init.py", line 364, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
Based on my testing, the error is generated from import thorlabs_apt as apt.
Some other setting I am using are:
Some other observations:
If possible, could you help me solve this issue?
Kind regards,
-Aiden
Where can I find a documentation of the APT.DLL on which this code is based?
I encounter issues with the raw to engineering conversion for some stages, I'd like to check why this happens.
I do not have the issue using the APT software.
I run these commands via the kernal on Spyder...
>>import thorlabs_apt as apt
>>devices = apt.list_available_devices()
I have 3 KDC101 controllers mounted on the KCH301 USB hub, but when I run the above code, apt.list_available_devices() only comes up with one device. I know that KDC101 has been tested, but I'm curious if there is something I need to do to read three devices from a single usb port on my computer.? Any thoughts on the fix?
@tobiasgehring
Hello,
Unsure why this is the case, but my motors will only allow me to set their max velocity to 10 rather than the 50 they allow in Kinesis - is this an inherent limitation of APT or is there some setting somewhere I can adjust this?
in combination with controller BSC101
Hi,
I downloaded the most recent version of thorlabs APT from the website for 64bit windows, using the 64bit version. This is version 3.7.0. However, when doing so, the APT.dll was not present in the directory. However, in the archive section, I could download 3.6.0 and this 64bit version, for windows 64bit did have the APT.dll in the stated directory.
I am using Python 2.7.9 64bit on Windows 7.
However, now I am getting an error:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import thorlabs_apt as apt
File "C:\Users\LocalAdmin\Downloads\thorlabs_apt-master\thorlabs_apt-master\thorlabs_apt\__init__.py", line 1, in <module>
from .core import *
File "C:\Users\LocalAdmin\Downloads\thorlabs_apt-master\thorlabs_apt-master\thorlabs_apt\core.py", line 1, in <module>
from . import _APTAPI
ImportError: cannot import name _APTAPI
Any suggestions?
Hi,
I tried to control BSC201.
it can connect to BSC201, but when I try your example, move_by(45), it continued moving more than 90 degree, and I have to turn off the power to stop it. so is there any initialization needed?
Thanks
Hi, just wanted to let you know this package works well to control the Thorlabs NT100 series stepper motor translation stages. Maybe consider adding that to the list. Sorry if this isn't the place to post such info. I am not a regular github user.
This is the stage that I am working with: https://www.thorlabs.com/newgrouppage9.cfm?objectgroup_id=2131
Hi,
I've successfully used this program to control the Thorlabs TDC001 motor, controlling a PRM1Z8. Thanks for writing it!
I can get the serial number from apt.list_available_devices();
But it does not work when I called motor.move_home(True) or any other functions. The error will always be '
Exception: Moving velocity failed: Serial number invalid.'
motor=apt.Motor(serial_number = 37861936); this doesn't have any error by the way. I'm using MFF101/M
apt.list_available_devices() returns an empty list. No devices found
555/5000
I'm trying to drive the K10RC1 rotation stage from Thorlabs with python, I've followed the instructions. instruction apt.list_available_devices () woks but the other functions do not work. Here is the code, I tried in python 2.7 and 3.6.
import thorlabs_apt as apt
apt.list_available_devices ()
print (apt.list_available_devices ())
motor = apt.Motor (55927320)
motor.move_home (True) Here is the error "Exception: Moving velocity failed: Internal error"
motor.move_by (10)
where is the problem ? Thank you in advance
Best regards,
Kévin
Hi,
After homing the stage, I cannot move my NRT150 stage (range 150mm) over 100mm.
Both move_to and move_by fail.
Everything works fine within 100mm.
Hope to hear any suggestion.
Thanks,
Ningxiao
If application exits without calling _cleanup(), next application run, will hang on call to _load_library() or to list_available_devices().
In core:
@atexit.register
def _cleanup():
This will never be called upon pycharm stop or ^C.
When calling _cleanup(), all is working fine.
Pycharm shutdown all open ports and dll properly when hitting stop (debug).
It turns out that the apt.dll does not handle exit properly.
Please advise
Hi, thanks for the package, previously I used the package to control NR360 rotation stage and it works perfectly.
Now, I'm using this package to control KDC101 to move a Z825B. The movement seems to be inaccurate. I input the following command:
Motor.move_to(0.1)
the display on KDC101 only goes to 0.06mm and Motor.position returns 0.1.
It's weird.
By the way, is there a package using Kinesis environment?
Thanks and all the best,
When using the library in a Qt application, it is impossible to create a motor in a separate thread.
Calling apt.Motor() causes the application to crash. without any error.
I am using PyQt5, Python 3.8.5 64bits on Windows 10
It would be desirable to access the StopImmediate function, in addition to StopProfiled. See excerpt from Thorlabs documentation below:
Motor Method StopImmediate
See Also Example Code
Visual Basic Syntax
Function StopImmediate(lChanID As Long) As Long
Parameters
lChanID - the channel identifier
Returns
MG Return Code
Details
This method is called to stop motor moves on the channel specified by the lChanID parameter, which in turn takes values specified by the HWCHANNEL enumeration.
Moves are stopped abruptly in a non-profiled manner, (i.e. the parameter fAccn, set using the SetVelParams method, is ignored) and there is a risk that steps, and therefore positional integrity, could be lost.
This method can be called to stop prematurely, absolute or relative moves and, more importantly, is called to stop MoveAtVelocity moves.
I'm trying to control a KDC101. I am able to control the KDC101 using Thorlabs' Kinesis software, and if I use usb.core.find() I can find the device, and even get the serial number. However, apt.list_available_devices() only gives an empty array, indicating that it does not detect the KDC101.
My code is as follows:
import usb
import thorlabs_apt as apt
PID = 0xFAF0
VID = 0x0403
dev = usb.core.find(idProduct = PID,idVendor = VID)
if not dev:
print("Device not found.")
else:
print("Device found.")
serial_number = usb.util.get_string( dev, dev.iSerialNumber )
print(serial_number)
serial_junk = apt.list_available_devices()
print(serial_junk)
The output is:
Device found.
27258145
[]
I have no idea how to fix this. I have tried installing libusb and pyusb and I've created drivers for libusb using Zadig 2.5.
Hello! I am attempting to control the ThorLabs KBD101 Servo Controller with the Python APT Software. I followed the installation guide and I can interface with the controller so commands like apt.list_available_devices() and apt.get_velocity_parameters() work. However, any move command such as motor.move_home(True) does not work and produces the following error: raise Exception("Moving velocity failed: %s" %
Exception: Moving velocity failed: Invalid error code.
I have tried setting the home parameters and velocity parameters as previous users with this problem have done. Are there other potential reasons why this problem could be persisting?
Tried the example commands but they do not work for the BSC202 controller and HDR50/M setup. The home function does not correct for backlash and the angular movement is incorrect.
Hi,
I am using thorlabs_apt to control a stage of NRT150 via BSC203. I found a problem of homing by using code: "motor.move_home(True)".
1)The stage goes to the forward direction and not reverse direction.
2)The stage does not stop when it reached the end of the range!
Does anyone have the same issue? I am not exactly sure how to set the switch limit for this to protect the stage.
I've been looking through the core.py file for a method that will end comms, but I can't find anything... The official Thor manual lists a StopCtrl method, but it doesn't seem like that method is included in the package.
I've written a small program that allows for user communication with a while loop controlling the whole process, but if the program crashes or is willingly exited it can't relaunch without resetting the motors. I'm guessing its cause the communication channel never closes. It won't even load the packages.
Other than that, it works great on BSC 201 and KDC 101 model stepper motor controllers.
Hi,
I've noticed when using the move_by command the minimum distance the command accepts is between 0.01 - 0.1. However when I use the APT user app I can set the minimum distance to be much smaller (about 3 orders of magnitude smaller). Is there some other command for smaller movements?
I used pip to install thorlabs_apt, and I'm running python 2.7.
Simply trying to run the import statement fails:
import thorlabs_apt as apt
filename = ctypes.util.find_library("APT")
AttributeError: 'module' object has no attribute 'util'
I was able to fix this by adding this line to core.py:
from ctypes.util import find_library
Dear Tobias,
I tried using your software to operate the K10CR1/M but I am getting a timeout error every time I try to run it. The software seems to be recognising the device and the motor can be operated from APT User just fine, for some reason it just doesn't want to move when the python script is run. 'trial2.py' is the file I have been trying to run and I have tried running it for different locations within the directory with no luck. I have copied the file directories and the time out error below, I hope this helps.
Thanks,
Emily
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/Emily/Desktop/SummerProject/Software/thorlabsK10CR1/thorlabs_apt-master/build/lib/thorlabs_apt/trial2.py', wdir='C:/Users/Emily/Desktop/SummerProject/Software/thorlabsK10CR1/thorlabs_apt-master/build/lib/thorlabs_apt')
File "C:\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/Emily/Desktop/SummerProject/Software/thorlabsK10CR1/thorlabs_apt-master/build/lib/thorlabs_apt/trial2.py", line 20, in
motor.move_home(True)
File "C:\Anaconda2\lib\site-packages\thorlabs_apt-0.1-py2.7.egg\thorlabs_apt\core.py", line 830, in move_home
_get_error_text(err_code))
Exception: Moving velocity failed: Internal error.
//
Exception: Moving velocity failed: Time out while waiting for hardware unit to respond.
Hi! The package works well with the KBD101 Brushless Motor Controller connected to a DDR25 Direct Drive Rotation Mount.
Works flawlessly with the Thorlabs LTS150/M linear translation stage. Thanks for writing this software.
Dear Tobias,
I've been trying to use your software with the BSC203 motor but it raises the exception "Could not initialize device: Unknown serial number". However the serial number I use is the one returned by APT USER and I can easily control the motor via Matlab.
Do you have any clue why this might happen ?
Thanks a lot,
Auriane
I'm running the 32bit version of Python 3.5.1 and have installed the current 32bit APT Version. After copying the "APT.dll" file in the "thorlabs_apt" folder I get the following error when trying to run the example code in the Readme-File:
Traceback (most recent call last):
File "C:/Users/ybrun/PycharmProjects/Thorlabs/main.py", line 1, in
import thorlabs_apt as apt
File "C:\Users\ybrun\PycharmProjects\Thorlabs\thorlabs_apt__init__.py", line 1, in
from .core import *
File "C:\Users\ybrun\PycharmProjects\Thorlabs\thorlabs_apt\core.py", line 1373, in
_lib = _load_library()
File "C:\Users\ybrun\PycharmProjects\Thorlabs\thorlabs_apt\core.py", line 1354, in _load_library
filename = ctypes.util.find_library("APT")
AttributeError: module 'ctypes' has no attribute 'util'
I have also put the dll-file in the other suggested directories but always got the same error.
The flipper mount (MFF101 and 102) are APT controlled, and you can certainly recognise them using this. You can even make them rotate... but only in one direction. I figure that the specific commands are missing from _APTAPI?
Any chance of including this?
apt.list_available_devices()\n
[(48, 37849413)]
flipper_mount = apt.Motor(37849413)
Using the move_by
i can get it to move, but never back.
Hi Tobias, thank you for this great software.
I'm trying to control a KDC101 motor controller cube, and I get an error when I try to run "import thorlabs_apt as apt":
Traceback (most recent call last): File "C:\Users\Lefty\Documents\RingFixtureAutomation\ThorlabsControl.py", line 5, in <module> import thorlabs_apt as apt File "C:\Users\Lefty\AppData\Local\Programs\Python\Python35\lib\site-packages\thorlabs_apt\__init__.py", line 1, in <module> from .core import * File "C:\Users\Lefty\AppData\Local\Programs\Python\Python35\lib\site-packages\thorlabs_apt\core.py", line 1373, in <module> _lib = _load_library() File "C:\Users\Lefty\AppData\Local\Programs\Python\Python35\lib\site-packages\thorlabs_apt\core.py", line 1367, in _load_library raise Exception("Thorlabs APT Initialization failed.") Exception: Thorlabs APT Initialization failed.
I have not installed the thorlabs software, rather I have copied APT.dll from another computer. I put APT.dll in the thorlabs_apt python folder. Can you suggest any way to diagnose this error?
Thanks,
Lefty
I couldn't find Stop abruptly command in the thorlabsapt, I am using NRT150 with BCS202. I am looking for ways to send a stop abruptly command to the device.
Hi,
I'd like to add support for the Nanotrack controllers. However, I have not found any documentation of the ATP.dll. Is this available somewhere?
Very best,
Matthias
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.