Exemplo n.º 1
0
    def __init__(self):
        com_ports = list(serial.tools.list_ports.comports())
        xy_com_port = "NULL"
        z_com_port = "NULL"

        #detect com ports
        for port in com_ports:
            print(port)
            if XYDEVPORT in port[2]:
                xy_com_port = port[0]
            if ZDEVPORT in port[1]:
                z_com_port = port[0]

        if "NULL" == xy_com_port:
            self.x_axis_device = "NULL"
            self.y_axis_device = "NULL"
            print("Could not find xy-axis device")
        #connects to devices if found
        else:
            port = BinarySerial(xy_com_port)
            self.x_axis_device = BinaryDevice(port, 1)
            self.y_axis_device = BinaryDevice(port, 2)
        if "NULL" == z_com_port:
            self.z_axis_device = "NULL"
            print("Could not find z-axis device")
        else:
            self.z_axis_device = serial.Serial(z_com_port, 115200)
Exemplo n.º 2
0
def setup_stages():
    global x_linear, y_linear, z_rotary

    serial_conn = BinarySerial(STAGES_PORT, timeout=None)

    x_linear = BinaryDevice(serial_conn, 2)
    y_linear = BinaryDevice(serial_conn, 3)
    z_rotary = BinaryDevice(serial_conn, 1)

    x_linear.set_home_speed(linspeed2lindata(DEFAULT_HOME_SPEED))
    y_linear.set_home_speed(linspeed2lindata(DEFAULT_HOME_SPEED))

    # need to  check that mm2rotdata does the right conversion
    #rotary.set_target_speed(mm2rotdata(DEFAULT_ROT_SPEED))
    x_linear.set_target_speed(linspeed2lindata(DEFAULT_HOME_SPEED))
    y_linear.set_target_speed(linspeed2lindata(DEFAULT_HOME_SPEED))

    x_linear.set_acceleration(LIN_STAGE_ACCELERATION)
    y_linear.set_acceleration(LIN_STAGE_ACCELERATION)
    z_rotary.set_acceleration(ROT_STAGE_ACCELERATION)

    z_rotary.set_min_position(deg2rotdata(ROTARY_MIN_ANGLE))
    z_rotary.set_max_position(deg2rotdata(ROTARY_MAX_ANGLE))

    home_all()
Exemplo n.º 3
0
def setup_stages():
    global serial_conn, x_linear, y_linear, z_rotary

    serial_conn = BinarySerial(STAGES_PORT, timeout=None)

    if CONNECT_ROTARY:
        z_rotary = BinaryDevice(serial_conn, 1)
        z_rotary.set_home_speed(degspeed2rotdata(DEFAULT_ROT_SPEED))
        z_rotary.set_target_speed(degspeed2rotdata(DEFAULT_ROT_SPEED))
        z_rotary.set_acceleration(ROT_STAGE_ACCELERATION)

        z_rotary.set_min_position(deg2rotdata(ROTARY_MIN_ANGLE))
        z_rotary.set_max_position(deg2rotdata(ROTARY_MAX_ANGLE))

    x_linear = BinaryDevice(serial_conn, 2)
    y_linear = BinaryDevice(serial_conn, 3)

    x_linear.set_home_speed(linspeed2lindata(DEFAULT_HOME_SPEED))
    y_linear.set_home_speed(linspeed2lindata(DEFAULT_HOME_SPEED))

    x_linear.set_target_speed(linspeed2lindata(DEFAULT_HOME_SPEED))
    y_linear.set_target_speed(linspeed2lindata(DEFAULT_HOME_SPEED))

    x_linear.set_acceleration(LIN_STAGE_ACCELERATION)
    y_linear.set_acceleration(LIN_STAGE_ACCELERATION)

    x_linear.disable_manual_move_tracking()
    y_linear.disable_manual_move_tracking()

    home_all()
Exemplo n.º 4
0
    def __init__(self, inst, props, *args, **kwargs):
        super(ZaberTMMMotorController, self).__init__(inst, props, *args,
                                                      **kwargs)

        # initialize hardware communication
        self.con = BinarySerial(self.port, timeout=5)

        print('Zaber TMM Controller Initialization ...'),
        print('SUCCESS on port %s' % self.port)
        # do some initialization
        self._motors = {}
Exemplo n.º 5
0
def setup_stages():

    global rotary, xAxis, yAxis

    serial_conn = BinarySerial(STAGES_PORT, timeout=None)

    rotary = BinaryDevice(serial_conn, 1)
    xAxis = BinaryDevice(serial_conn, 2)
    yAxis = BinaryDevice(serial_conn, 3)

    xAxis.set_home_speed(mm2lindata(DEFAULT_HOMING_SPEED))
    xAxis.set_home_speed(mm2lindata(DEFAULT_HOMING_SPEED))

    rotary.set_acceleration(20)
    xAxis.set_acceleration(2000)
    yAxis.set_acceleration(2000)

    # rotary.set_max_position

    home_all()
Exemplo n.º 6
0
def movedist(distance, direction_sign, device):
    # removed speed for now (third variable)
    # where device = device number.
    from src.check_command_succeeded import check_command_succeeded
    from zaber.serial import BinarySerial, BinaryDevice, BinaryCommand  # , BinaryReply #Added
    import time  # Added

    # -------------------------------------------------------------------------
    # TODO: Create device
    # -------------------------------------------------------------------------

    # command = BinaryCommand(device, 21, steps)   # Added. 21 = move rel
    port = BinarySerial(device)  # Added

    # -------------------------------------------------------------------------
    # TODO: Convert distances to steps.  Put in the true conversion.
    # -------------------------------------------------------------------------

    converter = 1  # converts distance to steps.  (steps/distance)
    steps = int(distance) * converter * int(
        direction_sign)  #number of microsteps to move

    # -------------------------------------------------------------------------
    # TODO: Insert motor move command
    # -------------------------------------------------------------------------

    command = BinaryCommand(0, 21, steps)
    port.write(command)  # Added
    # device.move_rel(speed,blocking=True)   # Added Commented Out

    #r eply = device.move_rel(steps)  # move rel 2000 microsteps #A dded Commented out everything below

    # if not check_command_succeeded(reply):
    #print("Device move failed.")
    #exit(1)
    # else:
    # print("Motor moved", distance, "microsteps")
    return
Exemplo n.º 7
0
'''
author: ashish
license: GPL v3.0
brief: Zaber's binary stepper motor control. The code demonstrates a circular motion
       of the combination of two devices in a plane.
       Ref: http://www.zaber.com/wiki/Manuals/Binary_Protocol_Manual
Pre: Do install Zaber's serial package from http://www.zaber.com/wiki/Software
'''


from zaber.serial import BinarySerial, BinaryDevice, BinaryCommand
import sys,os,thread,time,xlsxwriter,xlrd,re,math,serial


print "Port Opening..."
port = BinarySerial("/dev/ttyUSB0")
port.timeout = 30

resolution_mm = 0.124023438*1e-3
spd_mm_s = 10
spd_steps = int((spd_mm_s * 1.6384)/resolution_mm)
print spd_steps 

# Device number 0, command number 1.
radius = 100000
steps = 10
theta = (2*3.14159)/steps

device = BinaryDevice(port, 2)
device1 = BinaryDevice(port, 3)
Exemplo n.º 8
0
    def __init__(self, time_offset, COM_port, dev1_axis, dev2_axis,
                 coordinates_fname):
        self.time_offset = time_offset
        self.COM_port = COM_port

        self.coordinates_fname = coordinates_fname
        with h5py.File('drivers/' + coordinates_fname, 'r') as f:
            self.coordinates_random = f['all_points'][()]
            np.random.shuffle(self.coordinates_random)

        # shape and type of the array of returned data from ReadValue
        self.dtype = ('f4', 'int32', 'int32')
        self.shape = (3, )

        try:
            self.port = BinarySerial(COM_port)
            msg = self.command(0, 50, 0, 2)
            msg = [d.data for d in msg]
            if not all(elem == msg[0] for elem in msg):
                raise ValueError(
                    'ZaberTMM warning in verification : Device IDs not equal')
        except Exception as err:
            logging.warning("ZaberTMM error in initial connection : " +
                            str(err))
            self.verification_string = "False"
            self.__exit__()
            return None

        try:
            self.port.write(BinaryCommand(0, 55, 123))
            msg1 = self.port.read()
            msg2 = self.port.read()
            if msg1.data != 123:
                logging.warning(
                    "ZaberTMM warning in verification : motor {0} connection error"
                    .format(msg1.device_number))
            if msg2.data != 123:
                logging.warning(
                    "ZaberTMM warning in verification : motor {0} connection error"
                    .format(msg2.device_number))
            self.verification_string = "True"
        except Exception as err:
            logging.warning('ZaberTMM warning in verification : ' + str(err))
            self.verification_string = "False"

        self.warnings = []

        self.position = ZaberCoordinates(dev1_axis, dev2_axis)

        if dev1_axis == 'x':
            self.devx = 1
            self.devy = 2
        elif dev1_axis == 'y':
            self.devx = 2
            self.devy = 1

        if not self.ReadDeviceModeX()[7]:
            warning = 'Home Status bit not set in Dev{0}, home device'.format(
                self.devx)
            logging.warning('ZaberTMM warning: ' + warning)
            self.CreateWarning(warning)
        if not self.ReadDeviceModeY()[7]:
            warning = 'Home Status bit not set in Dev{0}, home device'.format(
                self.devx)
            logging.warning('ZaberTMM warning: ' + warning)
            self.CreateWarning(warning)

        self.sweep_thread = None
        self.running_sweep = False
        self.sweep_start_position = 'current'
        self.sweep_square_params = {}
        self.step_rectangle = None

        self.GetPosition()

        # HDF attributes generated when constructor is run
        self.new_attributes = [
            ('dev1_axis', dev1_axis), ('dev2_axis', dev2_axis),
            ('x_speed', str(self.ReadTargetSpeedX())),
            ('y_speed', str(self.ReadTargetSpeedY())),
            ('x_acceleration', str(self.ReadAccelerationX())),
            ('y_acceleration', str(self.ReadAccelerationY()))
        ]
Exemplo n.º 9
0
 def connect(self):
     self.comport = BinarySerial(self.port)
     self.x_axis = BinaryDevice(self.comport,1)
     self.y_axis = BinaryDevice(self.comport,2)
     self.rot_axis = BinaryDevice(self.comport,3)
## Input Data

horizontalDist = 1      #horizontal distance between nodes
verticalDist = 1        #verticle distance between nodes
nrow = 5                #Number of rows
ncol = 5                #Number of columns (maximum) in a row
matrixOffset = 0        #If rows are offset type 0, if rows are inline type 1.
                        # This program assumes it's halfway between each column
## Import functions
from src.moveRow import moveRow
from src.moveCol import moveCol
from zaber.serial import BinarySerial, BinaryDevice
from src.home import home

##hardware and OS setup
with BinarySerial("/dev/ttyUSB0") as port:  # Linux
# with BinarySerial("COM3") as port:         # Windows

# Get a handle for device #1 on the serial chain. This assumes you have a
# device already in Binary 9,600 baud mode at address 1 on your port.
device1 = BinaryDevice(port, 1) # motor on x axis
device2 = BinaryDevice(port, 2) # motor on y axis
device3 = BinaryDevice(port, 3) # motor on z axis


## Home all devices
# Home the device and check the result.
home(device1)
home(device2)
home(device3)
Exemplo n.º 11
0
def test_constructor_fails_when_not_passed_a_string():
    with pytest.raises(TypeError):
        BinarySerial(1)
# Here's an area where you can do code testing with out it impacting the rest of the functions!  Enjoy!

# go here for help: https://www.rose-hulman.edu/class/csse/csse120/201920/
# preparations have videos

# nrow = 5
# ncol = 5

from zaber.serial import BinarySerial, BinaryDevice, BinaryCommand  # , BinaryReply
import time

# Assume that our serial port can be found at COM1

port = BinarySerial(
    "COM13"
)  # be mindful of which COM port to use; check device manager; may need to restart port
# with BinarySerial("COM13") as port:
# Device number 0, command number 1.    1 is Home. 0 is Reset, move absolute is 20, relative is 21, 23 is stop
#max relative move is 20,000, 42 sets speed, can be changed during a move; calculate spd w/ https://www.zaber.com/documents/ZaberSpeedSetting.xls
command = BinaryCommand(0, 1)
#command = BinaryCommand(0, 20, 0)   #Goes at least to 50,000. Assume moving 10,000 = moving 0.01in
#command = BinaryCommand(0, 21, 20000)  #Can use negative distances with relative
#devicenum = 0
#distance = 20000
#command = BinaryCommand(devicenum, 21, distance)
#command = BinaryCommand(0, 21, 20000)

# note: Binary motor commands are blocking. Syntax: BinaryCommand(device#, command#, dataValue)
# List of command #s can be found at: https://www.zaber.com/wiki/Manuals/Binary_Protocol_Manual#Command_Reference
port.write(command)