Package: newport-motors-py
NewportMotorsPyThis project isin no way affiliated with Newport.PurposeThis repo contains code used to drive a large project with many newport motors. It is split into the following sub modules:GUI: generic GUI code usingstreamlitthat works well with motor alignment projectsMocks: Mock (i.e. simulated) versions of the motors as serial objects, useful for protoyping code before motors shipMotors: Motor driving code for different kinds of newport motorsUSBs: usb managment code, used to scan USB ports and identify products from a particular manufacturerInstallationThis repo is not currently on pypi, so you must install it manually. To do so, clone the repo and runpip install .from the root directory.UsageThere are a few different use cases for this package, outlined below.Connecting a single motorTo connect a single motor, you use the relevant motor class fromnewport_motors.motors. For example, to connect anewport_motors.motors.Motorobject, you would do the following:fromnewport_motors.motorsimportMotortip_tilt=M100D("ASRL/dev/ttyUSB0::INSTR",pyvisa.ResourceManager(visa_library="@_py"))print(tip_tilt.read_pos(tip_tilt.AXES.U))tip_tilt.set_absolute_position(0.0,tip_tilt.AXES.U)print(tip_tilt.read_pos(tip_tilt.AXES.U))Simulating a single motorTo simulate a single motor, you use the relevant motor class fromnewport_motors.mocks. For example, to simulate anewport_motors.motors.Motorobject, you would do the following:fromnewport_motors.mocksimportMotorfromvisa_mock.base.registerimportregister_resourcemotor1_port="MOCK0::mock1::INSTR"register_resource(motor1_port,Mock_M100D())Then use the motor as above, but with the port asmotor1_port.Connecting multiple motorsTo connect multiple motors, you use thenewport_motors.instrumentmodule. This module contains a class calledInstrumentthat is used to connect to multiple motors. To use it, you must first create a config file. This config file is a json file that contains a list of motors and their serial numbers. For example:[{"name":"Spherical_1_TipTilt","motor_type":"M100D","motor_config":{"orientation":"reversed"},"serial_number":"A67BVBOJ"},{"name":"Spherical_2_TipTilt","motor_type":"M100D","motor_config":{"orientation":"normal"},"serial_number":"A675RRE6"}]The relevant python code then isfromnewport_motors.instrumentimportInstrumentinst=Instrument("path/to/config.json")Individual motors can still be accessed usinginst.motors["motor_name"], but the instrument class also provides some useful methods for accessing multiple motors at once. For example, to move all motors to their home position, you can doinst.zero_all()Using a GUI with the motorsThenewport_motors.guimodule contains a generic GUI that can be used to control motors. This usesstreamlitto create a web app that can be run locally. We provide small blocks to make a larger GUI so that custom projects are easy to create.Linux connection issuesNewport devices did not natively show on ttyUSB* for me.
Run the following, replacing product id if needed for different productssudo modprobe ftdi_sio vendor=0x104d:3008 product=3008
sudo sh -c 'echo "104d 3008" > /sys/bus/usb-serial/drivers/ftdi_sio/new_id'You can also automated this by altering~/.bashrc:# newport motors
if [ ! -d "/sys/bus/usb-serial/drivers/ftdi_sio" ]; then
   sudo modprobe ftdi_sio vendor=0x104d:3008 product=3008
   sudo sh -c 'echo "104d 3008" > /sys/bus/usb-serial/drivers/ftdi_sio/new_id'
fiSince this hassudocommands, you will need to enter your password the first time you open a new terminal.Sim mode:Useshttps://github.com/microsoft/pyvisa-mock. If you wish to use it you must install it from source (and possibly changepython_requiresinsetup.py).The pyvisa_mock package is defined in this package and is correctly re-exported withpip install ..