PicoMotor control system using EPICS and Python
Overview
In KAGRA, Picomotors will be used everywhere. In this page, how to control those Picomotors through EPICS on a standalone system is explained. There are a few scripts and configuration files to make the EPICS-Picomotor system work in harmony. The list of scripts and files involved are shown below.
This system mainly consists of two programs. One is an EPICS IOC, named x1pico, which holds PVs (or channels) used to communicate with Picomotors. This IOC resides in /opt/rtcds/tst/x1/target/x1pico. The IOC can be started by running startpico command.
Another part of the system is a daemon script called pmepics.py. This script connects to those PVs provided by x1pico and wait for changes. Once it detects a change in one of the PVs, it takes an appropriate action, such as changing the speed of a motor, or start/stop motor rotation, etc. Therefore, users can control Picomotors by changing the values of those PVs, either through MEDM or command line tools.
For example, X1:PICO-MC_END_PIT_SPD is used to set the speed (pulses/sec) of the Picomotor for MC end mirror pitch. Another example is X1:PICO-MC_END_PIT_FWD. If pmepics.py detects a change in this channel, it starts or stops the rotation of the Picomotor in the forward direction depending on the value of this channel. If it is 1, the Picomotor starts moving. If it is 0, the motor stops.
The way pmepics.py controls the Picomotors are somewhat hidden from users. However, it is worth explaining the mechanism here since it will helpful to understand the syntax of pmepics.conf. In CLIO, Picomotors are connected to 8753 drivers. This driver can drive up to three Picomotors. The 8753 drivers are connected to 8752 controller (currently there is only one controller) through RS-485 daisy-chain network. (Note that this RS-485 network uses ethernet cables, but it is not a TCP/IP network) The 8752 controller is connected to the CDS private network via ethernet (this time it is TCP/IP). pmepics.py talks to 8752 by connecting to it at TCP port 23.
File name |
Description |
Location |
pmepics.py |
The main script which bridges EPICS PVs and Picomotors. This is run by a user. |
/opt/rtcds/tst/x1/scripts/PicoMotor/ |
pmepics.conf |
The main configuration file. This file describes the layout of the Picomotors and associates them with EPICS PVs. This file is used both by pmepics.py and pmGenDbMedm.py |
/opt/rtcds/tst/x1/scripts/PicoMotor/ |
pmGenDbMedm.py |
A script to automatically generate necessary configuration files for EPICS IOC, MEDM and Burt from pmepics.conf. It has to be run by a user every time pmepics.conf is modified in order to reflect the changes. |
/opt/rtcds/tst/x1/scripts/PicoMotor/ |
pmepics.db |
A database file for the EPICS IOC (x1pico). It is automatically generated by pmGenDbMedm.py |
/opt/rtcds/tst/x1/target/x1pico/db/ |
autoBurt.req |
This is a Burt request file for the IOC x1pico |
/opt/rtcds/tst/x1/target/x1pico/ |
*.adl |
MEDM screens are generated for each motor by pmGenDbMedm.py. |
/opt/rtcds/tst/x1/medm/x1/pico/ |
startpico |
A shell script to run the x1pico IOC. It will restore old values of speed and acceleration for each motor with Burt. |
/opt/rtcds/tst/x1/scripts/ |
killpico |
A shell script to kill the x1pico IOC. It will save the values of speed and acceleration for each motor with Burt. |
/opt/rtcds/tst/x1/scripts/ |
Usage
Edit pmepics.conf. It is an XML file and you will describe the layout of the Picomotors and the drivers/controllers. You also define the association of the Picomotors with EPICS PVs. The detailed syntax of the file is explained in the comment of the file.
Run pmGenDbMedm.py -c pmepics.conf to generate a necessary db file, MEDM screens and an autoBurt file.
Start IOC with startpico. It first tries to kill existing x1pico. So you don't have to run killpico first.
Run pmepics.py -c pmepics.conf to start EPICS-Picomotor bridge daemon.
Open, for example, /opt/rtcds/tst/x1/medm/x1/pico/X1:PICO-MC_END_PIT.adl with MEDM. It will show an auto generated MEDM screen to control a Picomotor.
Installation
This is a memo on how to install the EPICS-Picomotor system. We assume that EPICS base is installed at /opt/rtcds/tst/x1/lib/epics/base.
EpicsCA
Download EpicsCA version 3 below:
http://cars9.uchicago.edu/software/python/pyepics3/
if version 3 does not work, download version 2 from
http://cars9.uchicago.edu/~newville/Epics/Python/
Extract it in /opt/apps/linux-x86_64/epics/.
Set appropriate environmental variables (these are actually set in /opt/apps/etc/epics-user-env.sh sourced by .bashrc, so you shouldn't have to be bothered).
LD_LIBRARY_PATH=/opt/apps/linux-x86_64/epics/base/lib/linux-x86_64 EPICS_BASE=/opt/apps/linux-x86_64/epics/base EPICS_EXTENSIONS=/opt/apps/linux-x86_64/epics/extensions EPICS_HOST_ARCH=linux-x86_64
Change directory to setup python EPICS
cd /opt/apps/linux-x86_64/epics/pyepics-3.2.3
and run
python setup.py build
If you see error message like
epics_wrap.c:112: fatal error: Python.h: No such file or directory
you may need to install development files for python, if these are not installed yet.
Run
python setup.py install
as root (sudo may not work, just use su). Be sure to source /home/controls/.cshrc to set the environmental variables.
EPICS IOC
We want to have a dedicated IOC for the PicoMotor controller. Actually, this section gives you a general procedure to make a generic IOC.
Make a directory in /opt/rtcds/tst/x1/target. In this example, we create /opt/rtcds/tst/x1/target/x1pico.
Run the following commands in the created directory:
/opt/apps/linux-64/epics/base/bin/linux-x86_64/makeBaseApp.pl -t example x1pico /opt/apps/linux-64/epics/base/bin/linux-x86_64/makeBaseApp.pl -i -t example x1pico
example is the name of a template. example is a good template to start. x1pico is the name of your IOC. Usually, we want to start it with x1. The default name can be used for IOC.
Type make in the directory. The EPICS build system will compile an IOC.
Modify db/*.db file. Then go to iocBoot/iocx1pico and run st.cmd.
Now, for the PicoMotor controller, we have to put pmepics.db in the db/ directory. This file is automatically generated by pmGenDbMedm.py script. Then you have to add a line like the following to iocBoot/iocx1pico/st.cmd.
dbLoadRecords("db/pmepics.db", "site=X1")
Run the IOC by typing
cd /opt/rtcds/tst/x1/target/x1pico/iocBoot/iocx1pico ./st.cmd
Generating db file, MEDM screens and autoBurt file
pmGenDbMedm.py is a python script to automatically generate an EPICS db file, MEDM screens and an autoBurt request file.
The usage is:
pmGenDbMedm.py -c pmepics.conf
The syntax of pmepics.conf is explained at the beginning of the file as comments.