freegsnke.control_loop.pcs module

Module to implement a Plasma Control System (PCS) in FreeGSNKE.

Copyright 2025 UKAEA, UKRI-STFC, and The Authors, as per the COPYRIGHT and README files.

This file is part of FreeGSNKE.

FreeGSNKE is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

FreeGSNKE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FreeGSNKE. If not, see <http://www.gnu.org/licenses/>.

class freegsnke.control_loop.pcs.PlasmaControlSystem(plasma_data: dict[str, dict[str, Any]], shape_data: dict[str, dict[str, dict[str, Any]]], circuits_data: dict[str, Any], systems_data: dict[str, dict[str, Any]], pf_data: dict[str, dict[str, Any]], vertical_data: dict[str, dict[str, Any]], coil_activation_data: dict[str, dict[str, Any]], active_coils: list[str], ctrl_coils: list[str], vertical_coils: list[str], ctrl_targets: list[str], plasma_target: list[str], shape_control_mode: str | None = None, vc_generator: object | None = None)[source]

Bases: object

A high-level class for managing multiple controllers in a plasma control system.

This class integrates several subsystem controllers responsible for different aspects of plasma control, including shape control, vertical stabilization, coil current regulation, and virtual circuit modelling. It provides a unified interface for coordinating these controllers based on time-dependent input waveforms.

active_coils

List of all active coils used.

Type:

list of str

ctrl_coils

List of all active coils being used for shape control.

Type:

list of str

vertical_coils

List of all active coils being used for vertical control.

Type:

list of str

ctrl_targets

List of all shape control targets (e.g., X-points, strike points).

Type:

list of str

plasma_target

List of all plasma control targets.

Type:

list of str

shape_control_mode

Select which shape control algorithm to use (see shape_category.py).

Type:

str

PlasmaController

Handles plasma current control.

Type:

PlasmaController

ShapeController

Handles shape target control.

Type:

ShapeController

VirtualCircuitsController

Computes unapproved coil currents in ctrl coils using virtual circuits.

Type:

VirtualCircuitsController

SystemsController

Applies perturbations and enforces coil current and ramp rate limits to find approved coil currents.

Type:

SystemsController

PFController

Transforms approved coil currents into ctrl coil voltages.

Type:

PFController

VerticalControl

Controls vertical plasma position via vertical control coil.

Type:

VerticalController

CoilActivationControl

Controls coil resistances, depending on if they’re switched on or off.

Type:

CoilActivationController

vc_generator

An optional class object for applying emulated virtual circuits. If not provided, default waveform-defined VCs will be used. Its vc_update_rate attribute (set when the generator was initialised) controls how often, in seconds, new VCs are computed.

Type:

object, optional

__init__(plasma_data: dict[str, dict[str, Any]], shape_data: dict[str, dict[str, dict[str, Any]]], circuits_data: dict[str, Any], systems_data: dict[str, dict[str, Any]], pf_data: dict[str, dict[str, Any]], vertical_data: dict[str, dict[str, Any]], coil_activation_data: dict[str, dict[str, Any]], active_coils: list[str], ctrl_coils: list[str], vertical_coils: list[str], ctrl_targets: list[str], plasma_target: list[str], shape_control_mode: str | None = None, vc_generator: object | None = None) → None[source]

Initialise the top-level control system, composing all sub-controllers.

Builds and wires together the individual controllers (plasma, shape, virtual circuits, systems, PF, vertical, and coil activation), each given its own slice of input data plus whatever coil groupings and targets it needs.

Parameters:
  • plasma_data (dict) – Time-series data passed to PlasmaController.

  • shape_data (dict) – Time-series data passed to ShapeController.

  • circuits_data (dict) – Time-series data passed to VirtualCircuitsController.

  • systems_data (dict) – Time-series data passed to SystemsController.

  • pf_data (dict) – Time-series data passed to PFController.

  • vertical_data (dict) – Time-series data passed to VerticalController.

  • coil_activation_data (dict) – Time-series data passed to CoilActivationController.

  • active_coils (list of str) – Names of all coils that are active in this configuration. Passed to CoilActivationController.

  • ctrl_coils (list of str) – Names of the coils used for shape/virtual-circuit control. Passed to VirtualCircuitsController and SystemsController.

  • vertical_coils (list of str) – Names of the coils used for vertical position control.

  • ctrl_targets (list or dict) – Shape control targets, passed to ShapeController and VirtualCircuitsController.

  • plasma_target (float or array_like or dict) – Target value(s) for the plasma, passed to VirtualCircuitsController.

  • shape_control_mode (str, optional) – Mode used by ShapeController to determine how shape control is performed. If None, ShapeController’s default mode is used.

  • vc_generator (callable, optional) – Generator function used by VirtualCircuitsController to produce virtual circuit outputs. If None, VirtualCircuitsController’s default generator is used. Its vc_update_rate attribute controls how often VirtualCircuitsController updates its virtual circuits.

active_coils

Stored copy of active_coils.

Type:

list of str

ctrl_coils

Stored copy of ctrl_coils.

Type:

list of str

vertical_coils

Stored copy of vertical_coils.

Type:

list of str

ctrl_targets

Stored copy of ctrl_targets.

Type:

list or dict

plasma_target

Stored copy of plasma_target.

Type:

float or array_like or dict

PlasmaController

Sub-controller handling plasma-related quantities.

Type:

PlasmaController

ShapeController

Sub-controller handling shape control.

Type:

ShapeController

VirtualCircuitsController

Sub-controller handling virtual circuit generation and control.

Type:

VirtualCircuitsController

SystemsController

Sub-controller handling systems-level control.

Type:

SystemsController

PFController

Sub-controller handling PF coil control.

Type:

PFController

VerticalController

Sub-controller handling vertical position control.

Type:

VerticalController

CoilActivationController

Sub-controller handling per-coil activation state.

Type:

CoilActivationController

calculate_ctrl_voltages(t: float, dt: float, ip_meas: float, ip_hist_prev: float, ip_err_prev: float, T_meas: ndarray, T_err_prev: ndarray, T_hist_prev: ndarray, I_approved_prev: ndarray, I_meas: ndarray, V_approved_prev: ndarray, zip_meas: float, zipv_meas: float, active_coil_resists: ndarray, dt_simulator: float | None = None, vcg_inputs: ndarray | None = None, tikhonov_lambda: ndarray | None = None, verbose: bool = False) → Tuple[ndarray, float, float, ndarray, ndarray, ndarray, ndarray][source]

Run the full control pipeline to compute approved coil voltage commands.

This method coordinates all subsystem controllers (plasma current, shape control, virtual circuits, systems constraints, PF, and vertical) to compute the final voltage commands for the coils. It also returns updated histories and error signals for use in the next control cycle.

Parameters:
  • t (float) – Current time [s].

  • dt (float) – Time step to run the controllers at (must have ‘dt = dt_simulator/n’ where n is a natural number) [s].

  • ip_meas (float) – Measured plasma current [A].

  • ip_hist_prev (float) – Previous value of the integrated plasma current error [A.s].

  • ip_err_prev (float) – Previous value of the plasma current error [A].

  • T_meas (np.ndarray) – Measured values of the shape targets at the current time [m].

  • T_err_prev (np.ndarray) – Previously shape target filtered error signal (used for damping) [m].

  • T_hist_prev (np.ndarray) – Previous shape target integral term (used for PI control) [m.s].

  • I_approved_prev (numpy.ndarray) – Previously approved coil currents [A].

  • I_meas (numpy.ndarray) – Measured coil currents at the current time step [A].

  • V_approved_prev (numpy.ndarray) – Previously approved control coil voltages from the last control step [V].

  • zip_meas (float) – Measured vertical position of the plasma multiplied by measured Ip [A.m].

  • zipv_meas (float) – Measured vertical velocity of the plasma multiplied by measured Ip [A.m/s].

  • active_coil_resists (numpy.ndarray) – Array of active coil resistances when coils are switched on [Ohms].

  • dt_simulator (float) – Time step of the simulator (must have ‘dt_simulator = dt*n’ where n is a natural number) [s].

  • vcg_inputs (np.ndarray , optional) – Array of input values required to compute the emulated virtual circuit, as returned by vc_generator.get_inputs_from_eq(...). Only used if a vc_generator was provided to this PlasmaControlSystem.

  • tikhonov_lambda (numpy.ndarray , optional) – Array of regularisation values for Tikhonov regularisation in emulated VC matrix inversion. Must be same length as coils_calc.

  • verbose (bool, optional) – If True, prints diagnostic information from subsystem controllers.

Returns:

  • V_active (numpy.ndarray) – Final (all active) coil voltage demands after applying all constraints [V].

  • ip_hist (list of float) – Updated integrated plasma current error [A.s].

  • ip_err (list of float) – Updated plasma current error [A].

  • T_err (numpy.ndarray) – Updated shape target filtered error signal (used for damping) [m].

  • T_hist (list of numpy.ndarray) – Updated shape target integral term (used for PI control) [m.s].

  • I_approved (numpy.ndarray) – Approved coil currents after applying perturbations and clipping [A].

  • coil_resists (numpy.ndarray) – Active coil resistances to be used (some coils may be on or off at time t) [Ohms].