The Cooler Synchrotron COSY  operated at the Research Center Jülich is undergoing staged machine control upgrades driven by the requirements of the JEDI (Jülich Electric Dipole moment Investigations) collaboration . The upgrades aim towards better beam control e.g. beam orbit, tune, and chromaticity control improvements. A better orbit control was achieved through the upgrade of BPM electronics and migration from initial Tcl/Tk based control system to Control System Studio (CSS) utilizing EPICS . Currently, a design for improved beam tune control is in development. The main part of work is the transition towards a faster and less restrictive magnet control. It further includes improved tune measurement tools as well as the migration of control for quadrupole magnets to EPICS. Ultimately the control of all systems should be centralized around EPICS to enable ease of operation, automation, setup of services, etc. The decision path, technical details of the upgrade and performance of the upgraded sub-systems are presented. We also showcase how the COSY team’s physics and research goals are complemented by Cosylab’s technical design and implementation to form a synergetic collaboration.
The Cooler Synchrotron COSY-Jülich was taken into operation in 1993 . COSY was operated 24/7 as a user facility until 2014 providing polarized and unpolarized particle beams to a community of scientists primarily concentrated around the universities in the federal state of North RhineWestphalia, Germany and international users. COSY is a multipurpose facility serving experiments that use beams circulating in the storage ring or extracted and transported to three external experimental stations. Special emphasis is made on beam cooling  , ultra-slow extraction , spin control  and operation of internal targets of different types . Since 2014 COSY is a test facility for FAIR and precision experiments. Electron and stochastic beam cooling, beam instrumentation, cluster-jet target technologies are developed and tested at COSY. The JEDI collaboration uses the facility for research and developments towards a dedicated high-precision EDM storage ring and the first measurement as proof-of-principle at COSY.
The machine control system was developed in-house. During initial commissioning and first years of operation HP-UX running on HP-9000 workstations was used. The front-end hardware was mainly based on VME and G64 bus systems. A Real-time operating system (RT/OS) was developed at COSY for the VME systems. The Single Command Single Response (SCSR) data exchange protocol is a major component of RT/OS. Most of the GUIs were written in Tcl/Tk. To minimize the cost of technical support the control system was migrated to SuSE 8 running on Intel PC in 2002. Later on OpenSUSE and Ubuntu were used.
In the early phase of the control system design a decision was made to use Ethernet as the main transport mechanism. This fact had many implications, as the availability of the Ethernet-capable hardware was rather limited at that time. On the other hand, this is a significant advantage for the upgrade presented here.
With the JEDI experiment, new requirements concerning the overall RMS beam orbit deviation were introduced . Therefore an automated beam orbit control system had to be developed. Furthermore, other components were identified as being in need to be upgraded or to be added. One example is the analogue BPM readout electronics, whose signal offsets prevented an accurate position determination, especially around the 0 position. The decision was made, instead of implementing the new sub-systems and features into the old control system, to upgrade the latter in a step-wise manner, in order to avoid long down-times of the machine. In addition, the following considerations were taken into account:
- Add a logging and archiving mechanism
- Use software developed and supported by a larger community
- Software and compatible hardware available without protocol adaption
In order to satisfy the above-mentioned requirements EPICS was chosen as a new control system environment.
Orbit Correction Implementation
At COSY, the orbit can be measured using beam position monitors (BPM) and corrected using steerer magnets. The orbit correction controller has to synchronize with COSY operating cycles. A typical cycle is depicted in Fig. 1.
It starts with injection, followed by a synchronous ramping of the magnets initiated by a timing signal and ends with a ramp down phase. While ramping, the magnet power supplies are controlled by function generators that follow pre-defined waveforms. During this time, the magnet current cannot be set manually, so during normal operation the orbit cannot be adjusted in the middle of the machine cycle. The left part of the diagram in Fig. 2 depicts a newly developed algorithm that uses information broadcasted by the timing system to synchronize to the machine operation, switches the magnets from ramp mode to DC mode, enabling direct current manipulation in flat top and enabling orbit correction.
The same algorithm has to ramp the magnets back to the starting values before the end of the cycle and re-arm the function generators so they can start ramping when the timing system signals the beginning of the next cycle.
The orbit correction itself follows a common singular value decomposition correction algorithm. When the magnets are in the DC mode, a procedure implemented in an EPICS Input/Output Controller (IOC) uses the SCSR protocol to collect the orbit measurement values, calculate new correction values based on the difference between the current measured orbit and the desired orbit, calculate new corrector strengths, and send them to the steerer magnets using the SCSR protocol. A custom GUI for CSS  was developed in Java to allow control of the orbit correction algorithm and allow users to view the results. It can be seen in Fig. 3.
Migration of Steerer Magnet Controls to EPICS
While operators were using the orbit correction implemented as described above, it was discovered that the process is cumbersome for day to day usage. The operators had to use the Tcl/Tk based version of the control system to define the base ramp parameters, turn off this old system, modify (shorten) the ramp for orbit control purposes, load it to the targets (custom scripts running from the command line) and then start the new orbit correction software (based on EPICS). To mitigate the usability issue, the ramp definition parameters for the steerer magnets, ramp generation, loading onto the targets, and the GUIs, shown in Fig. 4, were migrated to EPICS and CSS. This now allows operators to focus on the status and control of the accelerator and not to spend time on the software itself. This system also serves as a test bed for migration of other Tcl/Tk based systems to EPICS.