Skip to content

Software:camera

Vincent Deo edited this page Sep 16, 2024 · 4 revisions

About cameras

Camera remote control can be achieved in two ways. Through the tmux session that actively controls the camera, and through Pyro remote procedure call.

Local control with ctrl tmux session

An ipython shell is persistently running in a tmux on the computer where the camera is plugged.

This tmux is called <camera>_ctrl, e.g. glint_ctrl, apapane_ctrl.

In this ipython sessions lives the object cam, that allows to access camera parameters and controls.

Such as cam.set_tint(), cam.get_fps, cam.get_temperature(). cam.set_NDR(), ...

The most-regularly used functions of the cam object are directly promoted to the ipython shell namespace. For example, get_tint() is a direct shorthand to cam.get_tint()

This is really local control, but it's been heavily (and conveniently) abused with ssh and tmux's send-keys to achieve remote control, such as:

ssh scexao@scexao5 "tmux send-keys -t glint_ctrl \"set_tint(0.3)\""

Remote control with pyro

This will work from any computer on the Subaru network (a side note on great power and great responsibility, yada yada), pending the appropriate packages are installed.

Pyro is a remote procedure call package for python object. It works essentially as:

  • You create an object that has the functionality you need (e.g., camera controller), on a given machine.
  • This object is given a NAME and a PyroServer is started in its process to expose it to the world.
  • NAME is registered to a Pyro phonebook (called the nameserver).

When you want to establish a client connection:

  • You hit up the nameserver (which has a persistent address) for a given object NAME
  • Nameserver provides you back with the exact address of object NAME
  • You now have a network pointer to object NAME and can call its functions!

In practice:

For the most used cameras, the cam object that lives in the ipython in the <cam>_ctrl tmux is bound to a pyro server.

From the client side, practically changing the NDR on GLINT can become as easy as:

from swmain.network.pyroclient import connect # Requires scxconf and will fetch the IP addresses there.
from camstack.pyro_keys import GLINT # Optional, it's really just the string "GLINT"
g = connect(GLINT) # The address of the SCExAO nameserver is hardcoded in the connect function. You can otherwise use connect_generic if you need the AO nameserver or another one.

# And now you have the g object alive in this terminal.
g.get_NDR()
g.set_tint(0.01234)
# Most of these basic setter functions are properly synchronous. So you can use them in scripts and be comfortable with the consistency of the camera state.
# Have fun.

Note that this method is not appropriate for fetching data. However, the key is that you can deploy it on the same machine where the data is dispatched into a SHM. This eventually enables scripting through a variety of camera states. Such as:

from pyMilk.interfacing.shm import SHM
g_shm = SHM('glint')

data = []
for ndr in range(1, 101):
    g.set_NDR(ndr)
    data += [g_shm.multi_recv_data(int(3000 / ndr), 1)]
Clone this wiki locally