Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 35 additions & 36 deletions examples/903.motion/kcube_jogging.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
# Example of how to use the linear stage (Z825B) with software limits locally

# import the Kinesis Library and make sure the path is correct
import os

os.add_dll_directory("C:\\Program Files\\Thorlabs\\Kinesis")
# Example of how to jog the linear stage (Z825B) locally

# thorlabs_kinesis finds the Kinesis DLLs in C:\Program Files\Thorlabs\Kinesis
# on its own; set THORLABS_DLL_PATHS if they are installed somewhere else.
from pyrolab.drivers.motion.z8xx import Z825B

# Look at the connected KCube for correct serial num
linear = Z825B("27504851", home=True)

# Set and read a few of the parameters pertaining to jogging
print(f"Jog mode: {linear.jog_mode}")
print(f"Stop mode: {linear.stop_mode}")
print(f"Jog step size: {linear.jog_step_size}")
linear.jog_step_size = 1
print(f"Jog step size: {linear.jog_step_size}")
linear.max_pos = 15
print(f"jog velocity: {linear.jog_velocity}")
print(f"jog acceleration: {linear.jog_acceleration}")
print(f"Soft Limit mode: {linear.soft_limits_mode}")

# Jog the position twice and measure position after each step
linear.jog("forward")
print(f"current pos after 1 jog: {linear.get_position()} mm")
linear.jog("forward")
print(f"current pos after 2 jogs: {linear.get_position()} mm")

# change to continuous jog then measure the position after reaching 10 mm
linear.jog_mode = "continuous"
linear.jog_velocity = 1
linear.jog("forward")
while linear.get_position() < 10.0:
pass
linear.stop()
print(f"current pos after continuous jog: {linear.get_position()} mm")
linear.move_to(0)

linear.close()
linear = Z825B()
linear.connect(serialno="27504851", home=True)

try:
# Set and read a few of the parameters pertaining to jogging
print(f"Jog mode: {linear.jog_mode}")
print(f"Stop mode: {linear.stop_mode}")
print(f"Jog step size: {linear.jog_step_size}")
linear.jog_step_size = 1
print(f"Jog step size: {linear.jog_step_size}")
linear.max_pos = 15
print(f"jog velocity: {linear.jog_velocity}")
print(f"jog acceleration: {linear.jog_acceleration}")
print(f"Soft Limit mode: {linear.soft_limits_mode}")

# Jog the position twice and measure position after each step
linear.jog("forward")
print(f"current pos after 1 jog: {linear.get_position()} mm")
linear.jog("forward")
print(f"current pos after 2 jogs: {linear.get_position()} mm")

# change to continuous jog then measure the position after reaching 10 mm
linear.jog_mode = "continuous"
linear.jog_velocity = 1
linear.jog("forward")
while linear.get_position() < 10.0:
pass
linear.stop()
print(f"current pos after continuous jog: {linear.get_position()} mm")
linear.move_to(0)
finally:
linear.close()
96 changes: 49 additions & 47 deletions examples/903.motion/kcube_limits.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
# Example of how to use the linear stage (Z825B) with software limits locally

# import the Kinesis Library and make sure the path is correct
import os

os.add_dll_directory("C:\\Program Files\\Thorlabs\\Kinesis")

# thorlabs_kinesis finds the Kinesis DLLs in C:\Program Files\Thorlabs\Kinesis
# on its own; set THORLABS_DLL_PATHS if they are installed somewhere else.
from pyrolab.drivers.motion.z8xx import Z825B

# Look at the connected KCube for correct serial num
linear = Z825B("27504851", home=True)

# The stage defaults to the "disallow" limit mode
# and defaults to software limits of 0 and 25 mm

# read and set all the different types of software limits modes
print(linear.soft_limits_mode)
linear.soft_limits_mode = "partial"
print(linear.soft_limits_mode)
linear.soft_limits_mode = "all"
print(linear.soft_limits_mode)
linear.soft_limits_mode = "disallow"
print(linear.soft_limits_mode)

# read and set the max position
print(f"max pos: {linear.max_pos} mm")
linear.max_pos = 10
print(f"max pos: {linear.max_pos} mm")

# We will now test the limit mode "disallow"
# it should error if we try to move it outside the limits set
print(f"Before Move: {linear.get_position()} mm")
linear.move_to(5) # Within the limits so no error
print(f"Moved to 5: {linear.get_position()} mm")
linear = Z825B()
linear.connect(serialno="27504851", home=True)

# connect() puts the stage in the "partial" limit mode, and the limits are
# whatever is saved on the device (0 and 25 mm for the Z825B)

try:
linear.move_to(15) # outside the limits so we must catch the error
except RuntimeError:
pass
print(f"Should have dissalowed move: {linear.get_position()} mm")

# We will now test the limit mode "partial"
linear.soft_limits_mode = "partial"
linear.move_to(15) # It will move but only until it has reached it's limit
print(f"Should have truncated move to {linear.max_pos}: {linear.get_position()} mm")

# We will now test the limit mode "all"
linear.soft_limits_mode = "all"
linear.move_to(15) # It will simply ignore any software limit set
print(f"Should have ignored max pos at {linear.max_pos}: {linear.get_position()} mm")
linear.move_to(0)

# min and max pos will reset to 0 and 25 mm and soft_limits_mode resets to "disallow"
linear.close()
# read and set all the different types of software limits modes
print(linear.soft_limits_mode)
linear.soft_limits_mode = "partial"
print(linear.soft_limits_mode)
linear.soft_limits_mode = "all"
print(linear.soft_limits_mode)
linear.soft_limits_mode = "disallow"
print(linear.soft_limits_mode)

# read and set the max position
print(f"max pos: {linear.max_pos} mm")
linear.max_pos = 10
print(f"max pos: {linear.max_pos} mm")

# We will now test the limit mode "disallow"
# it should error if we try to move it outside the limits set
print(f"Before Move: {linear.get_position()} mm")
linear.move_to(5) # Within the limits so no error
print(f"Moved to 5: {linear.get_position()} mm")
try:
linear.move_to(15) # outside the limits so we must catch the error
except RuntimeError:
pass
print(f"Should have dissalowed move: {linear.get_position()} mm")

# We will now test the limit mode "partial"
linear.soft_limits_mode = "partial"
linear.move_to(15) # It will move but only until it has reached it's limit
print(f"Should have truncated move to {linear.max_pos}: {linear.get_position()} mm")

# We will now test the limit mode "all"
linear.soft_limits_mode = "all"
linear.move_to(15) # It will simply ignore any software limit set
print(
f"Should have ignored max pos at {linear.max_pos}: {linear.get_position()} mm"
)
linear.move_to(0)
finally:
# the next connect() reloads the limits saved on the device and goes back
# to the "partial" limit mode
linear.close()
46 changes: 23 additions & 23 deletions examples/903.motion/kcube_rotation.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Example of how to use the rotation stage (PRM1Z8) locally

# import the Kinesis Library and make sure the path is correct
import os

os.add_dll_directory("C:\\Program Files\\Thorlabs\\Kinesis")

# thorlabs_kinesis finds the Kinesis DLLs in C:\Program Files\Thorlabs\Kinesis
# on its own; set THORLABS_DLL_PATHS if they are installed somewhere else.
from pyrolab.drivers.motion.prm1z8 import PRM1Z8

# Look at the connected KCube for correct serial num
rot = PRM1Z8("27003366", home=False)
rot = PRM1Z8()
rot.connect(serialno="27003366", home=False)

# Prints out the starting postition to get an idea of where it currently is
starting_pos = rot.get_position()
print(f"Stating position: {starting_pos} degrees")
try:
# Prints out the starting postition to get an idea of where it currently is
starting_pos = rot.get_position()
print(f"Stating position: {starting_pos} degrees")

# A simple script to test moving the stage
while True:
# Input a position in degrees
move_pos = float(input("Rotation Position (deg):"))
# Input a 0 to go back to the starting position and exit the program
if move_pos == 0:
break
pos = rot.get_position()
print(f"Before Move: {pos} degrees")
rot.move_to(move_pos)
pos = rot.get_position()
print(f"After Move: {pos} degrees")
rot.move_to(starting_pos)
rot.close()
# A simple script to test moving the stage
while True:
# Input a position in degrees
move_pos = float(input("Rotation Position (deg):"))
# Input a 0 to go back to the starting position and exit the program
if move_pos == 0:
break
pos = rot.get_position()
print(f"Before Move: {pos} degrees")
rot.move_to(move_pos)
pos = rot.get_position()
print(f"After Move: {pos} degrees")
rot.move_to(starting_pos)
finally:
rot.close()
34 changes: 15 additions & 19 deletions examples/903.motion/kcubes.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import os

os.add_dll_directory("C:\\Program Files\\Thorlabs\\Kinesis")

import time
from ctypes import byref, c_double, c_int, pointer

from pyrolab.drivers.motion.z8xx import Z825B

linear = Z825B("27003497", home=False)
while True:
move_pos = int(input("Translation Position:"))
if move_pos == 0:
break
pos = linear.get_position()
print(f"Before Move: {pos}")
linear.move_to(move_pos)
pos = linear.get_position()
print(f"After Move: {pos}")
linear.move_to(0)
linear.close()
linear = Z825B()
linear.connect(serialno="27003497", home=False)
try:
while True:
move_pos = int(input("Translation Position:"))
if move_pos == 0:
break
pos = linear.get_position()
print(f"Before Move: {pos}")
linear.move_to(move_pos)
pos = linear.get_position()
print(f"After Move: {pos}")
linear.move_to(0)
finally:
linear.close()
46 changes: 23 additions & 23 deletions examples/903.motion/kcubes_linear.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Example of how to use the linear stage (Z825B) locally

# import the Kinesis Library and make sure the path is correct
import os

os.add_dll_directory("C:\\Program Files\\Thorlabs\\Kinesis")

# thorlabs_kinesis finds the Kinesis DLLs in C:\Program Files\Thorlabs\Kinesis
# on its own; set THORLABS_DLL_PATHS if they are installed somewhere else.
from pyrolab.drivers.motion.z8xx import Z825B

# Look at the connected KCube for correct serial num
linear = Z825B("27504851", home=False)
linear = Z825B()
linear.connect(serialno="27504851", home=False)

# Prints out the starting postition to get an idea of where it currently is
starting_pos = linear.get_position()
print(f"Stating position: {starting_pos} mm")
try:
# Prints out the starting postition to get an idea of where it currently is
starting_pos = linear.get_position()
print(f"Stating position: {starting_pos} mm")

# A simple script to test moving the stage
while True:
# Input a position in degrees
move_pos = float(input("linear Position (mm):"))
# Input a 0 to go back to the starting position and exit the program
if move_pos == 0:
break
pos = linear.get_position()
print(f"Before Move: {pos} mm")
linear.move_to(move_pos)
pos = linear.get_position()
print(f"After Move: {pos} mm")
linear.move_to(starting_pos)
linear.close()
# A simple script to test moving the stage
while True:
# Input a position in mm
move_pos = float(input("linear Position (mm):"))
# Input a 0 to go back to the starting position and exit the program
if move_pos == 0:
break
pos = linear.get_position()
print(f"Before Move: {pos} mm")
linear.move_to(move_pos)
pos = linear.get_position()
print(f"After Move: {pos} mm")
linear.move_to(starting_pos)
finally:
linear.close()
66 changes: 29 additions & 37 deletions examples/903.motion/nanomax300.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
import os

os.add_dll_directory("C:\\Program Files\\Thorlabs\\Kinesis")
import time

from pyrolab.drivers.motion.max31x import MAX31X

SER_NUM = 71874833

print(f"connecting to {SER_NUM}...")
nm = MAX31X(str(SER_NUM), closed_loop=True)
nm = MAX31X()
nm.connect(serialno=str(SER_NUM), closed_loop=True)
print("connected")
print("zeroing all channels...")
nm.zero()
print("zeroed")
(
x,
y,
z,
) = nm.get_position()
print(f"position of x: {x}")
print(f"position of y: {y}")
print(f"position of z: {z}")
print("Input Jogging Parameters:")
while True:
channel = int(input("Input channel:"))
distance = float(input("Input jog distance:"))
print(f"jogging channel {channel} a distance of {distance}...")
nm.jog(channel, distance)
time.sleep(1)
print("jog complete")
(
x,
y,
z,
) = nm.get_position()
print(f"new position of x: {x}")
print(f"new position of y: {y}")
print(f"new position of z: {z}")
cond = input("Break?")
if (cond == "y") | (cond == "yes"):
break
print("closing nanomax...")
nm.close()
print("closed")
try:
print("zeroing all channels...")
nm.zero()
print("zeroed")
x, y, z = nm.get_position()
print(f"position of x: {x}")
print(f"position of y: {y}")
print(f"position of z: {z}")
print("Input Jogging Parameters:")
while True:
channel = int(input("Input channel:"))
distance = float(input("Input jog distance:"))
print(f"jogging channel {channel} a distance of {distance}...")
nm.jog(channel, distance)
time.sleep(1)
print("jog complete")
x, y, z = nm.get_position()
print(f"new position of x: {x}")
print(f"new position of y: {y}")
print(f"new position of z: {z}")
cond = input("Break?")
if cond in ("y", "yes"):
break
finally:
print("closing nanomax...")
nm.close()
print("closed")
Loading
Loading