thorlabs_apt_device.utils module¶
Utility methods for conversion of units to encoder counts.
The interfaces to the controllers have been left in their native “encoder counts”, since there are many different devices with different conversions between encoder counts (or stepper motor microsteps etc) to position or angle. Furthermore, real usage of motion devices will often involve a calibration routine, for example to convert linear translation stage motion to an optical delay path. In this case it’s more straightforward to convert time to encoder pulses directly, instead of converting through a position intermediate (which may itself need to be calibrated properly).
This choice does make code a little more verbose, however with these utilities and some tricks of python, that extra coding effort can be reduced. For a particular combination of controller and motion device, it’s recommended to use the python partial to build device-specific conversions. For example, the documentation for the TDC001 controller lists a time unit of \(2048/6 \times 10^6\) and with a MTS50-Z8 translation stage encoder counts per mm of 34304. Custom conversion methods can be built:
from functools import partial
# Build our custom coversions using mm, mm/s and mm/s/s
from_mm = partial(from_pos, factor=34304)
from_mmps = partial(from_vel, factor=34304, t=2048/6e6)
from_mmpsps = partial(from_acc, factor=34304, t=2048/6e6)
to_mm = partial(from_pos, factor=1/34304)
to_mmps = partial(from_vel, factor=1/34304, t=2048/6e6)
to_mmpsps = partial(from_acc, factor=1/34304, t=2048/6e6)
# ...
# Perform moves in mm instead of encoder counts
stage.move_relative(from_mm(12.34))
# Check position in mm
print(to_mm(stage.status["position"]))
Similar functions can be built for other units, for example where position is angle in degrees.
- thorlabs_apt_device.utils.from_acc(acc, factor, t)[source]¶
Convert from acceleration in real units to encoder counts per unit time squared.
The
factor
parameter is the number of encoder counts per real unit, taken from the documentation for the device and is the same as forfrom_pos()
. The t is the time unit, again taken from the documentation for the controller, and is the same as forfrom_vel()
.- Parameters:
factor – Conversion factor, encoder counts per unit.
t – Time unit for the controller.
- Returns:
Number of encoder counts per unit time squared corresponding to
acc
.
- thorlabs_apt_device.utils.from_pos(pos, factor)[source]¶
Convert from position in real units to encoder counts.
The
factor
is the number of encoder counts per real unit, taken from the documentation for the device. For example, there are 20000 encoder counts per mm on the DDS600 translation stage, so usingfactor=20000
would convert millimetres to encoder counts.- Parameters:
factor – Conversion factor, encoder counts per unit.
- Returns:
Number of encoder counts corresponding to
pos
.
- thorlabs_apt_device.utils.from_vel(vel, factor, t)[source]¶
Convert from velocity in real units to encoder counts per unit time.
The
factor
parameter is the number of encoder counts per real unit, taken from the documentation for the device and is the same as forfrom_pos()
. The t is the time unit, again taken from the documentation for the controller. For example, the BBD201 controller hast=102.4e-6
.- Parameters:
factor – Conversion factor, encoder counts per unit.
t – Time unit for the controller.
- Returns:
Number of encoder counts per unit time corresponding to
vel
.
- thorlabs_apt_device.utils.to_acc(count, factor, t)[source]¶
Convert to acceleration in real units from encoder counts per unit time squared.
The
factor
parameter is the number of encoder counts per real unit, taken from the documentation for the device and is the same as forfrom_pos()
. The t is the time unit, again taken from the documentation for the controller, and is the same as forfrom_vel()
.- Parameters:
factor – Conversion factor, encoder counts per unit.
t – Time unit for the controller.
- Returns:
Acceleration in real units corresponding to
count
.
- thorlabs_apt_device.utils.to_pos(count, factor)[source]¶
Convert to position in real units from encoder counts.
The
factor
is the number of encoder counts per real unit, taken from the documentation for the device. For example, there are 20000 encoder counts per mm on the DDS600 translation stage, so usingfactor=20000
would convert encoder counts to millimetres.- Parameters:
factor – Conversion factor, encoder counts per unit.
- Returns:
Position in real units corresponding to
count
.
- thorlabs_apt_device.utils.to_vel(count, factor, t)[source]¶
Convert to velocity in real units from encoder counts per unit time.
The
factor
parameter is the number of encoder counts per real unit, taken from the documentation for the device and is the same as forfrom_pos()
. The t is the time unit, again taken from the documentation for the controller. For example, the BBD201 controller hast=102.4e-6
.- Parameters:
factor – Conversion factor, encoder counts per unit.
t – Time unit for the controller.
- Returns:
Velocity in real units corresponding to
count
.