Skip to main content

A python package for operating newport motors

Project description

NewportMotorsPy

This project is in no way affiliated with Newport.

Purpose

This 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 using streamlit that works well with motor alignment projects
  • Mocks: Mock (i.e. simulated) versions of the motors as serial objects, useful for protoyping code before motors ship
  • Motors: Motor driving code for different kinds of newport motors
  • USBs: usb managment code, used to scan USB ports and identify products from a particular manufacturer

Installation

This repo is not currently on pypi, so you must install it manually. To do so, clone the repo and run pip install . from the root directory.

Usage

There are a few different use cases for this package, outlined below.

Connecting a single motor

To connect a single motor, you use the relevant motor class from newport_motors.motors. For example, to connect a newport_motors.motors.Motor object, you would do the following:

from newport_motors.motors import Motor

tip_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 motor

To simulate a single motor, you use the relevant motor class from newport_motors.mocks. For example, to simulate a newport_motors.motors.Motor object, you would do the following:

from newport_motors.mocks import Motor
from visa_mock.base.register import register_resource

motor1_port = "MOCK0::mock1::INSTR"
register_resource(motor1_port, Mock_M100D())

Then use the motor as above, but with the port as motor1_port.

Connecting multiple motors

To connect multiple motors, you use the newport_motors.instrument module. This module contains a class called Instrument that 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 is

from newport_motors.instrument import Instrument

inst = Instrument("path/to/config.json")

Individual motors can still be accessed using inst.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 do

inst.zero_all()

Using a GUI with the motors

The newport_motors.gui module contains a generic GUI that can be used to control motors. This uses streamlit to 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 issues

Newport devices did not natively show on ttyUSB* for me. Run the following, replacing product id if needed for different products

sudo 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'
fi

Since this has sudo commands, you will need to enter your password the first time you open a new terminal.

Sim mode:

Uses https://github.com/microsoft/pyvisa-mock. If you wish to use it you must install it from source (and possibly change python_requires in setup.py).

The pyvisa_mock package is defined in this package and is correctly re-exported with pip install ..

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

newport-motors-py-0.1.3.tar.gz (14.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

newport_motors_py-0.1.3-py3.9.egg (39.8 kB view details)

Uploaded Egg

newport_motors_py-0.1.3-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file newport-motors-py-0.1.3.tar.gz.

File metadata

  • Download URL: newport-motors-py-0.1.3.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for newport-motors-py-0.1.3.tar.gz
Algorithm Hash digest
SHA256 356589ead11c442ec9e702cdee1d467c1e4d504f9a9ea5794403380aa8a23a39
MD5 24461e2001d73072262b97915bbc0430
BLAKE2b-256 88d121dd2d20bb8363ec3dfb61f3365ba7d3b6367ec4f35df76ad636b1c42d68

See more details on using hashes here.

File details

Details for the file newport_motors_py-0.1.3-py3.9.egg.

File metadata

  • Download URL: newport_motors_py-0.1.3-py3.9.egg
  • Upload date:
  • Size: 39.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for newport_motors_py-0.1.3-py3.9.egg
Algorithm Hash digest
SHA256 9c7f86680c7cbcefcaf75fd872a896be3d61d52e47a9263540801d92f533b67e
MD5 f378e93daf46d46711197ff135483a88
BLAKE2b-256 d79cfb2ca45ac6fa088e20215b7d8b6ed7392c90ce6051c81acf4f0c74aa8262

See more details on using hashes here.

File details

Details for the file newport_motors_py-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for newport_motors_py-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 54d97d934809f786c5800a96aa175507debd919504371d678c7b3e6db0bb86ce
MD5 b08a0b58b6b4bc105e9d65579efda407
BLAKE2b-256 dbc2d05e1f4b5c288693edcbae67cbfb1e7cd813592fb12a62cb42f8912913f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page