Skip to main content

Spectroscopy lock application using RedPitaya

Project description

LINIEN

Spectroscopy locking of lasers using RedPitaya (STEMlab 125-14) that just works. Linien aims to follow the UNIX philosophy of doing one thing very well. It is built with Python and Migen and is based on RED PID.

Features

  • All included: Sinusoidal modulation (up to 50 MHz), demodulation, filtering and servo implemented on the FPGA.
  • Client-server architecture: Autonomous operation on RedPitaya. One or multiple GUI clients or scripts can connect to the server.
  • Autolock: Click and drag over a line, and linien will automatically approach it and lock to it.
  • Lock detection: linien is capable of detecting loss of lock.
  • Automatic relocking: in that case, it can relock automatically using the autolock.
  • Automatic Optimization: linien uses machine learning to optimize spectroscopy parameters
  • Remote-controllable: The client libraries can be used to control or monitor the spectroscopy lock with python.
  • Combined FMS+MTS: Supports dual-channel spectroscopy that can be used to implement combined FMS+MTS
  • Logging: Use linien-influxdb to log the lock status to influxdb.
  • TTL status: Outputs the lock status via TTL

image

Getting started

Linien runs on Windows and Linux. For most users the standalone binaries containing the graphical user interface are recommended. If you want to use the python interface you should install it using pip.

Standalone binary

You can download standalone binaries for windows and linux on the releases page. On linux you have to mark it as executable before executing:

FIXME: ist das der richtige Dateiname?

chmod +x linien-client-linux*
./linien-client-linux*

Installation with pip

Linien is written for python 3 and can be installed using python's package manager pip:

pip3 install linien

Run the application by calling

linien

If this doesn't work, your local bin directory (e.g. ~/.local/bin) is probably missing in your PATH. Alternatively you can open linien using python:

from linien.client.client import run_application
run_application()

Then, you can enter your RedPitaya's credentials and connect. If you agree, linien's server component is automatically installed.

Physical setup

The default setup looks like this:

image

You can also configure linien for different setups, e.g. if you want to have the modulation frequency and the control on the same output. Additionally, it is possible to set up a slow integrator on ANALOG OUT 0 (0 V to 1.8 V).

image

Using the application

Connecting to the RedPitaya

After launching the application you have to set up a new device. The host address is given by

rp-XXXXXX.local
, where XXXXXX are the last 6 digits of the device's MAC address. You will find these on a sticker on the ethernet port:

FIXME: Photo

Username and password default to root.

When connecting to a RedPitaya for the first time, the application will ask you whether you want to install the server component on the device. In order to do so, the RedPitaya has to have access to the internet.

FIXME: screenshot

After installation of the server libraries, Linien will start the server and connect to it. You never need to start or stop anything on the server manually as the client automatically takes care of this.

FIXME: missing

Setting things up

Using the autolock

Using the manual lock

Optimization of spectroscopy parameters using machine learning

Updating the application

Scripting interface

In addition to the GUI, Linien can also be controlled using python scripts. For that purpose, installation via pip is required (see above).

from linien.client.connection import BaseClient, MHz, Vpp
c = BaseClient(host, 18862, False)

# read out the modulation frequency
print(c.parameters.modulation_frequency.value / MHz)

# set modulation amplitude
c.parameters.modulation_amplitude.value = 1 * Vpp
# in the line above, we set a parameter. This is not written directly to the
# FPGA, though. In order to do this, we have to call write_data():
c.connection.root.write_data()

# plot control and error signal
import pickle
from matplotlib import pyplot as plt
plot_data = pickle.loads(c.parameters.to_plot.value)

# depending on the status (locked / unlocked), different signals are available
print(plot_data.keys())

# if unlocked, signal1 and signal2 contain the error signal of channel 1 and 2
# if the laser is locked, they contain error signal and control signal.
if c.parameters.lock.value:
    plt.plot(plot_data['control_signal'], label='control')
    plt.plot(plot_data['error_signal'], label='error')
else:
    plt.plot(plot_data['error_signal_1'], label='error 1')
    plt.plot(plot_data['error_signal_2'], label='error 2')

plt.legend()
plt.show()

For a full list of parameters that can be controlled or accessed have a look at parameters.py.

Development

As linien uses a git submodule, you should check it out like this:

git clone https://github.com/hermitdemschoenenleben/linien.git --recursive

Then, create a file named checked_out_repo/linien/VERSION with contents

dev

(no newlines).

This ensures that changes you made to the server component are automatically uploaded to the RedPitaya when you launch the client.

Architecture

Linien contains three components:

  • The client: Connects to the server, runs the GUI, etc.
  • The server: Handles connections from the client, runs long-running tasks like the autolock or the optimization algorithm. Connects to the acquisition process for communication with the FPGA.
  • The acquisition process: Handles the low-level communication with the FPGA (reading / writing registers)

The communication between the components takes place using rpyc.

For development purposes, you can run the first two components on your local machine to simplify debugging. Only the acquisition process has to run on the RedPitaya. In a production version of linien, server and acquisition process run on RedPitaya.

Running the code

Before running the development version check that no production version of the server is running on the RedPitaya by executing linien_stop_server on the RedPitaya. Now you need to have an FPGA bitstream at linien/server/linien.bin. You have two choices:

  • Build the gateware: this makes sense if you want to change the FPGA programming.
  • Use the gateware of the latest release: if you just want to work on the python client or server code without touching the FPGA gateware, this approach is right for you as it is way easier:
    • Install linien-server using pip: pip3 install linien-server
    • Find out where it was installed to: python3 -c "import linien; print(linien.__path__)"
    • In that folder go to linien/server and copy this file to your development server folder.

Now you can launch the client

python3 linien/client/client.py

and you can connect to your RedPitaya. If you have set checked_out_repo/linien/VERSION to dev (see above), this automatically uploads your local code to the RedPitaya and starts the server. The FPGA bitstream will also be transferred to the RedPitaya and loaded on the FPGA.

Run server locally

For debugging it may be helpful to execute the server component on your machine (e.g. if you want to work on the autolock and want to plot the spectra). In order to make this work, you have to start /linien/server/acquisition_process.py on your RedPitaya using SSH. This process provides remote access to the FPGA registers. Then, you can run the server locally and connect to the FPGA registers:

python3 server/server.py --remote-rp=root:password@rp-f0xxxx.local

Now, you can start the client. Important: Be sure not to connect your client to the RedPitaya, but to "localhost" instead.

Fake server

If you just want to test the GUI, there is also a fake server that you can run locally on your machine:

python3 server/server.py --fake

This fake server just outputs random data. Then you can connect to "localhost" using the client.

Building the FPGA image

For building the FPGA image, you need to install Xilinx Vivado first. Then, call scripts/build\_gateware.sh. In the end, the bitstream should be located under linien/server/linien.bin.

FIXME: Windows?

Releasing a new version

FIXME: windows?

First, update the version number in the checked_out_repo/linien/VERSION file. Then you can build and upload the package to pypi using scripts/upload_pypi.sh. Finally, build the standalone client using build_standalone_client.sh (you have to do this on the platform you want to build the standalone client for). The standalone client should be uploaded to a github release.

Troubleshooting

Connection problems

If the client fails to connect to a RedPitaya, first check whether you can ping it by executing

ping rp-f0xxxx.local

in a command line. If this works, check whether you can connect via SSH. On Windows, you have to install a SSH client, on linux you can execute

ssh rp-f0xxxx.local

on the command line.

FAQs

Can I run linien and the RedPitaya web application / scpi interface at the same time

No, this is not possible as linien relies on a customized FPGA bitstream.

What control bandwidth is achievable with linien?

The propagation delay is roughly 300 ns, thus approximately 3 MHz bandwidth are possible.

See Also

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

linien-0.1.4.tar.gz (106.2 kB view details)

Uploaded Source

Built Distribution

linien-0.1.4-py3-none-any.whl (110.8 kB view details)

Uploaded Python 3

File details

Details for the file linien-0.1.4.tar.gz.

File metadata

  • Download URL: linien-0.1.4.tar.gz
  • Upload date:
  • Size: 106.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.4

File hashes

Hashes for linien-0.1.4.tar.gz
Algorithm Hash digest
SHA256 966a0a571f54fb5494a9de606f51bfb19d0c1f2ff32df02eeab4b79d495a313e
MD5 d74c44dafe0cc6151ae71982ebd1fda2
BLAKE2b-256 8a5906fea47d18ee7cef06020156660763daa1dc634bc78142af4fcbb083b3a7

See more details on using hashes here.

File details

Details for the file linien-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: linien-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 110.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.4

File hashes

Hashes for linien-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1ad5393720d7b45967bca8f70460423c361488a456afcf8c4ae428e7d1aa73ba
MD5 48c8fe486ad0cb0913b8ee291d09312f
BLAKE2b-256 2b29597ac932bfc5af7a469a6b440c53a0f44efeca03780daebf96c4493aee74

See more details on using hashes here.

Supported by

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