Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,10 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
#- os: macos-latest
# release: R2024a
# products: >
# Simulink
# Simulink_Test
# Simulink_Coverage
# Simulink_Check
# Simulink_Coder
# Embedded_Coder
- os: ubuntu-22.04
release: R2024a
products: >
Simulink
Simulink_Test
Simulink_Coverage
Simulink_Check
Simulink_Coder
Embedded_Coder
os: [ubuntu-22.04]
release: [R2024a, R2025a]



# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -51,7 +36,13 @@ jobs:
# MATLAB release to set up (R2021a or later)
release: ${{matrix.release}}
# Products to set up in addition to MATLAB, specified as a list of product names separated by spaces
products: ${{matrix.products}}
products: >
Simulink
Simulink_Test
Simulink_Coverage
Simulink_Check
Simulink_Coder
Embedded_Coder

# Run the run_tests script in the root of the repo
- name: Run script
Expand Down Expand Up @@ -84,6 +75,16 @@ jobs:
output: both
thresholds: '40 60'

- name: upload artifact
uses: actions/upload-artifact@v4
if: success() || failure()
with:
# Name of the artifact to upload.
# Optional. Default is 'artifact'
name: testreport${{matrix.release}}
path: ./testreport/*
retention-days: 30

- name: Update Summary
if: success() || failure()
run: |
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Introduction to the Plasma Control System Simulation Platform (PCSSP)
PCSSP provides standardized methods for the design and assessment of modules and models for plasma control. It essentially provides you with a systematic framework to develop, test, integrate, and deploy controller and tokamak models. PCSSP relies on a git submodule called SCDDS to implement the Simulink functionality regarding data dictionaries and referenced models. Both PCSSP and SCDDS are developed under a GPL license. You are invited to contribute to both projects that ultimately will be merged into one toolbox for control development and deployment on tokamaks.
PCSSP provides standardized methods for the design and assessment of modules and models for plasma control. It essentially provides you with a systematic framework to develop, test, integrate, and deploy controller and tokamak models. PCSSP relies on a git submodule called SCDDS (Simulink-based Control Design & Deployment Suite) to implement the Simulink functionality regarding data dictionaries and referenced models. Both PCSSP and SCDDS are developed under a LGPL license. You are invited to contribute to both projects that ultimately will be merged into one toolbox for control development and deployment on tokamaks.

## Full documentation
The full documentation of PCSSP is automatically deployed from its source code in this repository to readthedocs. You can find it [here](https://pcssp.readthedocs.io/en/latest/index.html)

## Directory structure:
- configurations: Simulink configuration definitions for codegen and simulation
- scdds-core: git submodule (!) to handle data-dictionaries and module references in Simulink
- scdds: git submodule (!) to handle data-dictionaries and module references in Simulink
- src: inherited PCSSP classes
- testing: inherited PCSSP classes for testing modules
- templates: pcssp examples
Expand All @@ -19,7 +19,7 @@ The full documentation of PCSSP is automatically deployed from its source code i

## To run:
### (Only required for code generation): define an environment variable SCDDS_COREPATH to point to scdds-core in your ~/.bashrc. For example, on a typical linux system the path could be:
`export SCDDS_COREPATH="~/Documents/MATLAB/pcssp-nightly/scdds"`
`export SCDDS_COREPATH="~/Documents/MATLAB/pcssp/scdds"`

### Open Matlab on your system. On the ITER SDCC cluster you can for example type the following in a new terminal window:
`module load intel MATLAB`
Expand All @@ -31,7 +31,7 @@ The full documentation of PCSSP is automatically deployed from its source code i
This will tell git to use the simulink 3-way merge tool to resolve merge conflicts in binary slx files.

### Navigate to the templates/ directory, and open one of the provided examples
Detailed documentation on how to develop your own PCSSP modules is not yet integrated in this repo, you can contact one of the lead developers below to obtain a PDF.
Detailed documentation on how to develop your own PCSSP modules is available on the [readthedocs](https://pcssp.readthedocs.io/en/latest/index.html)

### License
This code is distributed under the `LGPL-v3` license. Copyright is retained by the ITER Organization.
Expand All @@ -43,7 +43,7 @@ The authors would greatly appreciate it if the modifications are shared back to

The above is a non binding summary of the legal text. The full and legally binding text is in the license file `LICENSE.md`.

Note that this software requires Matlab/Simulink, including toolboxes needed for C code generation (typically Embedded coder) and Simulink Test. Users must obtain their own licenses from Mathworks.
Note that this software requires Matlab/Simulink, including toolboxes needed for C code generation (typically Embedded coder) and Simulink Check, Test, Coder. Users must obtain their own licenses from Mathworks.

### Contributing
The code is hosted on [https://github.com/iterorganization/pcssp](https://github.com/iterorganization/pcssp) and can be freely cloned. The Git submodule is hosted on [https://gitlab.epfl.ch/spc/scdds/scdds-core](https://gitlab.epfl.ch/spc/scdds/scdds-core)
Expand Down
1 change: 1 addition & 0 deletions run_tests.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function results = run_tests()


% main script to initialize PCSSP and run all tests in batch

% PCSSP - Plasma Control System Simulation Platform
Expand Down
2 changes: 1 addition & 1 deletion scdds
Submodule scdds updated from 795f68 to ef9f9e
6 changes: 3 additions & 3 deletions templates/KMAG/test_PCSSP_KMAG.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ function run_verification_sim(testCase)

u_base = timeseries(ulog.Data(:,ii),ulog.Time);

% remove first 1s transient before comparing
u_out = u_out.delsample('Index',[1:20]);
u_base = u_base.delsample('Index',[1:20]);
% % remove first 1s transient before comparing
% u_out = u_out.delsample('Index',[1:20]);
% u_base = u_base.delsample('Index',[1:20]);

plot(u_out); hold on; plot(u_base);

Expand Down
7 changes: 4 additions & 3 deletions templates/PID_example/modules/TF/pcssp_TF_obj.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
obj = obj.addbus('pcssp_PID_outBus', 'pcssp_PID_outBus_def' );
obj = obj.addbus('pcssp_TF_outBus', 'pcssp_TF_outBus_def' );

%% link PID refdd for shared bus

% obj = obj.addrefdd('pcssp_PID.sldd');

%% Tasks

%% Print (optional)
obj.printinfo;
%% Tasks

end

2 changes: 1 addition & 1 deletion templates/PID_example/modules/TF/pcssp_TF_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
isCodegen = false;
end

methods
methods(Test)
function bla(testCase)

end
Expand Down
5 changes: 1 addition & 4 deletions templates/PID_example/modules/sensor/pcssp_PID_sensor_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
isCodegen = 0; % flag to trigger module tests for codeGen
end

methods
function bla(testCase)

end
methods(Test)

end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function [fp] = cruise_controller_load_fp(obj)


fp.timing = obj.gettiming;
end

25 changes: 25 additions & 0 deletions templates/cruise_control/controller/cruise_controller_load_tp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function [tp] = cruise_controller_load_tp()
%% function to define tunable parameters for the cruise controller

%% define PID parameter for PID pcssp module for velocity control

tp.Pvel = 3;
tp.Ivel =0;
tp.Dvel = 0;

%% define Transfer function numerator and denominator for position control
tp.pos_num = [4320 -4.2772e+03];
tp.pos_den = [1 -0.8931];

%% saturation limits
tp.pos_acc_saturation = 1000;
tp.neg_acc_saturation = -1000;

%% controller constants
tp.switch_constant = 10; % distance between cars when to switch to pos control
tp.min_safety_distance= 5; % minimum safety distance between cars
tp.safe_time = 2; % safe time between cars


end

Binary file not shown.
15 changes: 15 additions & 0 deletions templates/cruise_control/controller/pcssp_cruise_controller_obj.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function obj = pcssp_cruise_controller_obj()


obj = pcssp_module('pcssp_cruise_controller');

%% Timing of the algorithm
obj=obj.settiming(0,1e-3,10.0);

%% Fixed parameters init functions
obj=obj.addfpinitfcn('cruise_controller_load_fp','cruise_controller_fp');

%% Tunable parameters structure name
obj=obj.addtunparamstruct('cruise_controller_tp', @()cruise_controller_load_tp());

end
26 changes: 26 additions & 0 deletions templates/cruise_control/controller/pcssp_cruise_controller_test.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
classdef pcssp_cruise_controller_test < pcssp_module_test
% test for PCSSP_PID demo module
% see pcssp_module test class for all standard pcssp module tests

properties
algoobj = @()pcssp_cruise_controller_obj();
isCodegen = 1; % flag to trigger module tests for codeGen
end

methods(Test)
function build_cruise_controller(testCase)

obj = testCase.algoobj();
obj.init;
obj.setup;
obj.build('auto');

obj.write_XML

end

end



end
35 changes: 35 additions & 0 deletions templates/cruise_control/cruise_control_run_topm.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%% main script to run the cruise control example

% define PCSSP modules and top model class instances
[topm,obj_voiture,obj_controller] = cruise_control_topm_obj();

% initialize and setup all PCSSP models
topm.init;
topm.setup;

%% compile and simulate

topm.compile;
out = topm.sim;
simout = logsout2struct(out);

%% plot

h = tiledlayout(3,1,'TileSpacing','compact','Padding','compact');

h1 = nexttile;
plot(h1,simout.follower_position_position.Time,simout.follower_position_position.Values);
hold on;
plot(h1,simout.leader_position_position.Time,simout.leader_position_position.Values);
legend(h1,'follower position','leader position')

h2 = nexttile;

plot(h2,simout.velocity_error.Time,simout.velocity_error.Values);
legend(h2,'velocity error')

h3 = nexttile;
plot(simout.controller_mode.Time,simout.controller_mode.Values);
legend(h3,'controller mode');

h.XLabel.String = 't (s)';
Binary file added templates/cruise_control/cruise_control_topm.slx
Binary file not shown.
17 changes: 17 additions & 0 deletions templates/cruise_control/cruise_control_topm_obj.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function [topm,obj_voiture,obj_controller] = cruise_control_topm_obj()

%% configure top model
topm = pcssp_top_class('cruise_control_topm');


%% initialize PCSSP modules
obj_voiture = pcssp_Voiture_obj(); % input is the size of the inBus
obj_controller = pcssp_cruise_controller_obj();

%% add modules and wrappers to top model

topm = topm.addmodule(obj_voiture);
topm = topm.addmodule(obj_controller);


end
Binary file added templates/cruise_control/model/pcssp_Voiture.slx
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions templates/cruise_control/model/pcssp_Voiture_harness_run.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function out = pcssp_Voiture_harness_run(obj)

% initialize object
obj.init;
obj.setup;

% define waveforms
SimIn = Simulink.SimulationInput([obj.getname '_harness']);
ds = createInputDataset(obj.getname);


input.acceleration = timeseries(5*ones(1,2),[0 10]);
ds = setElement(ds,1,input,'acceleration');

SimIn = SimIn.setExternalInput(ds);

out = sim(SimIn);

end
24 changes: 24 additions & 0 deletions templates/cruise_control/model/pcssp_Voiture_inBus_def.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function [busNames, Buses] = pcssp_Voiture_inBus_def()

busNames={};
Buses={};

clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'acceleration';
elems(1).Dimensions = 1;
elems(1).DimensionsMode = 'Fixed';
elems(1).DataType = 'double';
elems(1).SampleTime = -1;
elems(1).Complexity = 'real';
elems(1).DocUnits = 'm/s^2';

pcssp_voiture_inBus = Simulink.Bus;
pcssp_voiture_inBus.Description = 'input acceleration for car model';
pcssp_voiture_inBus.DataScope = 'Auto';
pcssp_voiture_inBus.Elements = elems;

busNames{1} = 'pcssp_voiture_inBus';
Buses{1} = pcssp_voiture_inBus;

end
6 changes: 6 additions & 0 deletions templates/cruise_control/model/pcssp_Voiture_loadfp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function fp = pcssp_Voiture_loadfp(obj)

%% store module timing in fixed parameter structure

fp.timing = obj.gettiming;
end
10 changes: 10 additions & 0 deletions templates/cruise_control/model/pcssp_Voiture_loadtp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function TP = pcssp_Voiture_loadtp()
% Setup tunable control params default values for PCSSP car module in the
% cruise control example
%
TP.numerator = 1;
TP.denominator = [1e-2 1];
TP.v0 = 0;
TP.s0 = 0;

end
22 changes: 22 additions & 0 deletions templates/cruise_control/model/pcssp_Voiture_obj.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function obj = pcssp_Voiture_obj()

% example PCSSP module that implements a simple PID controller

obj = pcssp_module('pcssp_Voiture');

%% Timing of the algorithm
obj=obj.settiming(0,1e-3,10.0);

%% Fixed parameters init functions
obj=obj.addfpinitfcn('pcssp_Voiture_loadfp','pcssp_Voiture_fp');

%% Tunable parameters structure name
obj=obj.addtunparamstruct('pcssp_Voiture_tp', @()pcssp_Voiture_loadtp());


%% Buses
obj = obj.addbus('', @() pcssp_Voiture_inBus_def());
obj = obj.addbus('', @() pcssp_Voiture_outBus_def());

end

Loading