= PicoMotor control system using EPICS and Python = * [[#Overview|Overview]] * [[#Usage|Usage]] * [[#Installation|Installation]] * [[#EpicsCA|EpicsCA]] * [[#EPICSIOC|EPICS IOC]] * [[#GenerateDb|Generating db file, MEDM screens and autoBurt file]] <> == Overview == In CLIO, Picomotors are used everywhere. In this page, how to control those Picomotors through EPICS 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 k1pico, which holds PVs (or channels) used to communicate with Picomotors. This IOC resides in {{{/cvs/cds/kami/target/k1pico}}}. 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 k1pico 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, {{{K1:PICO-MC_END_PIT_SPD}}} is used to set the speed (pulses/sec) of the Picomotor for MC end mirror pitch. Another example is {{{K1: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.||{{{/cvs/cds/kami/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}}}||{{{/cvs/cds/kami/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.||{{{/cvs/cds/kami/scripts/PicoMotor/}}}|| ||{{{pmepics.db}}}||A database file for the EPICS IOC (k1pico). It is automatically generated by {{{pmGenDbMedm.py}}}||{{{/cvs/cds/kami/target/k1pico/db/}}}|| ||{{{autoBurt.req}}}||This is a Burt request file for the IOC k1pico||{{{/cvs/cds/kami/target/k1pico/}}}|| ||{{{*.adl}}}||MEDM screens are generated for each motor by {{{pmGenDbMedm.py}}}.||{{{/cvs/cds/kami/medm/k1/pico/}}}|| ||{{{startpico}}}||A shell script to run the k1pico IOC. It will restore old values of speed and acceleration for each motor with Burt.||{{{/cvs/cds/kami/scripts/}}}|| ||{{{killpico}}}||A shell script to kill the k1pico IOC. It will save the values of speed and acceleration for each motor with Burt.||{{{/cvs/cds/kami/scripts/}}}|| <> == Usage == 1. 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. 1. Run {{{pmGenDbMedm.py -c pmepics.conf}}} to generate a necessary db file, MEDM screens and an autoBurt file. 1. Start IOC with {{{startpico}}}. It first tries to kill existing k1pico. So you don't have to run killpico first. 1. Run {{{pmepics.py -c pmepics.conf}}} to start EPICS-Picomotor bridge daemon. 1. Open, for example, {{{/cvs/cds/kami/medm/k1/pico/K1: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 /cvs/cds/kami/lib/epics/base. <> === EpicsCA === Download EpicsCA version 2 (not 3 yet) from below: http://cars9.uchicago.edu/~newville/Epics/Python/ Extract it in {{{/cvs/cds/kami/lib/epics/}}}. Set appropriate environmental variables (these are actually set by .cshrc, so you shouldn't have to be bothered). {{{ LD_LIBRARY_PATH=/cvs/cds/kami/lib/epics/base/lib/linux-x86_64 EPICS_BASE=/cvs/cds/kami/lib/epics/base EPICS_EXTENSIONS=/cvs/cds/kami/lib/epics/extensions EPICS_HOST_ARCH=linux-x86_64 }}} Run {{{ python setup.py build }}} You may need to install development files for python, if these are not installed yet. Run {{{ python setup.py install }}} as root. 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 {{{/cvs/cds/kami/target}}}. In this example, we create {{{/cvs/cds/kami/target/k1pico}}}.<
> Run the following commands in the created directory: {{{ /cvs/cds/kami/lib/epics/base/bin/linux-x86_64/makeBaseApp.pl -t example k1pico /cvs/cds/kami/lib/epics/base/bin/linux-x86_64/makeBaseApp.pl -i -t example k1pico }}} {{{example}}} is the name of a template. {{{example}}} is a good template to start. {{{k1pico}}} is the name of your IOC. Usually, we want to start it with {{{k1}}}. Type {{{make}}} in the directory. The EPICS build system will compile an IOC. Modify {{{db/*.db}}} file. Then go to {{{iocBoot/iock1pico}}} 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/iock1pico/st.cmd}}}. {{{ dbLoadRecords("db/pmepics.db", "site=K1") }}} Run the IOC by typing {{{ cd /cvs/cds/kami/target/k1pico/iocBoot/iock1pico ./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.