Applying Model Predictive Control toRegulate Thermal Stability of a Hard X-ray
Monochromator Using the Karabo SCADA
Framework
M. A. Smith, G. Giovanetti, S. Hauf, I. Karpics, A. Parenti, A. Samadli, L. Samoylova, A. Silenzi, F. Sohn, P. Zalden,
European XFEL, Schenefeld, Germany

Abstract / Introduction

Integration

Model Predictive Control (MPC) is an advanced method of process control whereby a model
is developed for a real-life system and an optimal control solution is then calculated andapplied to control the system. At each time step, the MPC controller uses the system modeland system state to minimize a cost function for optimal control. The Karabo SCADA
Framework is a distributed control system developed specifically for European XFEL facility,
consisting of tens of thousands of hardware and software devices and over two million
attributes to track system state.
This contribution describes the application of the Python MPC Toolbox within the Karabo
SCADA Framework to solve a monochromator temperature control problem. Additionally, theexperiences gained in this solution have led to a generic method to apply MPC to any groupof Karabo SCADA devices.

Motivation
Silicon monochromators are used to select the pass band of X-ray energies that continue
through to the instrument. Thermal drift in a monochromator causes a drift of thetransmitted photon energy.
To mitigate the impact of temperature jumps caused by the X-ray pulse trains at
European XFEL, the monochromator temperature has to stay just below thistemperature.
There are multiple sources and sinks of energy in the system that affect temperature,making temperature regulation of both crystals challenging:
1. Cryogenic cold head to coolboth crystals down
2. Local heater attached toeach crystal
3. Parasitic heat from the local
heater of the other crystal
4. Heating of the first incident
crystal due to the X-ray
beam input

Karabo has a declarative API which enables the creation of a generic, reusable datatypethat can update the MPC model parameters seamlessly.
Model inputs, both locally fixed and remote time-varying parameters retrieved from thecontrol system, are defined in the Karabo device just like other numeric parameters ofthe device.
""" example declaration of Karabo parameter""“
connectionTimeout = Float(
displayedName="Connection Timeout",
description="Maximum time to wait for remote“"device connections.",
unitSymbol=Unit.SECONDS,
maxInc=10.0)""" example declaration of Karabo parameterthat auto-updates MPC parameter""“
temperature1Setpoint = MPCFloat(
displayedName="XTAL1 Temperature Setpoint",
description="Temperature setpoint for the “"first crystal in the X-ray path",
unitSymbol=Unit.DEGREE_CELSIUS,
minInc=-200.0,# the datatype's 'alias' is used to declare# the name of the MPC model variable
alias='T_setpoint1’)

Sample parameter declaration

while True:
self.elapsed_time = time.time()# read system state from device proxies# (get feedback variables from system)y = [proxy.value for proxyin self.temperatureProxies]# calculate next set of control actionsu = self.mpc.make_step(y)# apply control actions (write# new values to device proxies)
self.heaterProxies[0].targetPower = u[0]self.heaterProxies[1].targetPower = u[1]# time between control actions is defined# in the MPC as self.mpc.t_step
time_step = self.mpc.t_step - \(time.time() - self.elapsed_time)
await sleep(time_step)

Sample control loop

Results
The Karabo device based on the MPC toolkit was deployed to control two
monochromator devices in the Femosecond X-ray Experiments (FXE) instrument in
September 2022.
When the regulator is active, it is able to bring the two crystal temperatures to the
setpoint of -180°C within a few minutes and hold the temperature with a standard
deviation of 0.006°C.

CAD drawing of the X-ray
monochromator, showing thepath of the X-ray beam throughthe two silicon crystals of themonochromator. Tx and HTx
identify the temperature
sensors and heater elements
respectively.
Temperature plot of both monochromator crystals in °C, showing the temperature regulation
before and after the MPC is activated.

Methods
The Python MPC Toolbox is a comprehensive python library that supports creation,
simulation, and runtime implementation of Model Predictive Controllers.
This toolbox provides a framework in Python for describing a system’s behaviour by
defining the ordinary differential equations (ODEs) that relate the rate of change of its
process variables to other measurable states of the system.

This implementation demonstrates that it is possible to capture all the control logic
of a high-level process control device into a software model using the MPC Toolbox.
Once the model has been synthesized, the effort of writing a control system device
is reduced to defining device configuration for the model's constant parameters andwriting code to read and write attributes from other remote control system devices.
Additionally, the model is fully reusable for unit testing and simulation.

𝑑𝑇!"#$%&'
1=𝑃!"#( + 𝑃)*&%*" + 𝑃+*&,
𝑑𝑡𝑚𝑐𝑚 = mass of crystal
𝑐 = speci1ic heat capacity of crystal
P = powers added to and removed from crystal
Once these are defined, a ‘model’ instance is created and can be used by other parts of
the MPC Toolbox to synthesize an optimal MPC controller as well as a model simulator.

References[1] The Karabo distributed control system, Journal of synchrotron radiation 26.5 (2019), 1448-1461.
[2] The Python Model Predictive Control Toolbox, 2023, https://www.do-mpc.com.
[3] Thermal expansion coefficient of single crystal silicon from 7K to 293K,
https://doi.org/10.1103/PhysRevB.92.174113.
[4] X-Ray Optics and Beam Transport, XFEL Technical Design Report, XFEL.EU TR-2012 006.

European XFEL GmbH, Michael Smith, Holzkoppel 4, 22869 Schenefeld, Germany, Phone +49 40 8998-6703, michael.smith@xfel.eu
www.xfel.eu