├── .gitmodules
├── 3rdparty
├── +hinfcd
│ ├── +standard
│ │ └── +projlem
│ │ │ ├── genplant_d.m
│ │ │ ├── genplant_ss.m
│ │ │ ├── projlem_d.m
│ │ │ └── projlem_ss.m
│ ├── +util
│ │ ├── bold.m
│ │ ├── dirsumdec.m
│ │ ├── explicitnull.m
│ │ ├── explicitsym.m
│ │ ├── gensylvester.m
│ │ ├── isectspace.m
│ │ ├── link.m
│ │ ├── mergestruct.m
│ │ ├── niljordan.m
│ │ ├── orderbound.m
│ │ ├── orthtol.m
│ │ ├── preim.m
│ │ ├── removehtml.m
│ │ ├── roundsmall.m
│ │ ├── strucsylvester.m
│ │ └── wongseq.m
│ ├── +watchdog
│ │ ├── printer.m
│ │ └── watchdog.m
│ ├── @dss
│ │ ├── balreal.m
│ │ ├── dss.m
│ │ ├── kalreal.m
│ │ ├── kronreal.m
│ │ ├── minreal.m
│ │ ├── oredreal.m
│ │ ├── oredrealsvd.m
│ │ └── svdreal.m
│ ├── @hinfcd
│ │ ├── hinfcd.m
│ │ ├── options.m
│ │ ├── setoptions.m
│ │ └── solve.m
│ ├── @postprocessor
│ │ └── postprocessor.m
│ ├── @preprocessor
│ │ └── preprocessor.m
│ └── @problem
│ │ └── problem.m
├── LCT_CExport
│ ├── c_export.m
│ ├── make_example.m
│ ├── make_header.m
│ ├── make_makefile.m
│ ├── make_source.m
│ ├── matrix_expand.m
│ ├── test
│ │ ├── attitude_controller.cpp
│ │ ├── attitude_controller.h
│ │ ├── example
│ │ │ ├── example
│ │ │ ├── example.cpp
│ │ │ └── makefile
│ │ └── test.m
│ └── vector_expand.m
├── LCT_LPV_identification
│ ├── BSplineSMILE.m
│ ├── Iij.m
│ ├── buildKnotSeq.m
│ ├── evalnstackGlob.m
│ ├── evalnstackLoc.m
│ ├── getFRFerror_LCT.m
│ ├── getFRFjacobian_LCT.m
│ ├── getGriddedFRF.m
│ ├── getJacobianFast_LCT_arr.m
│ ├── glocalIdent.m
│ ├── nllsLPV.m
│ ├── normalise.m
│ ├── plotGriddedFRF.m
│ ├── plotLPVSSmatrices.m
│ ├── projectModel.m
│ ├── regBSplineNLS.m
│ ├── simLPV.m
│ ├── simLPVc.m
│ └── smile_techniqueOC_spline.m
├── LCT_LTI_identification
│ ├── BA_construct.m
│ ├── crest2.m
│ ├── effval.m
│ ├── four2ti.m
│ ├── lnorm.m
│ ├── merge2frfs.m
│ ├── mlfdi.m
│ ├── mlfdi_res.m
│ ├── msinl2pi.m
│ ├── musin_type.m
│ ├── nllsfdi.m
│ ├── polytraj.m
│ ├── randph.m
│ ├── schroed.m
│ ├── time2fo.m
│ └── time2frf.m
├── LCT_MECOtools
│ ├── exportBallscrewData.m
│ ├── importBallscrewData.m
│ ├── importDSPACE.m
│ ├── importELMO.m
│ └── importQRC.m
├── LCT_MixSynMIMO_LPV
│ ├── LPV_analysis.m
│ ├── LPV_discrete_example.m
│ ├── LPV_example.m
│ ├── LPV_example_mix.m
│ ├── LPV_unstructured_OF.m
│ ├── LPV_unstructured_OF_new.m
│ ├── LPV_unstructured_mix.m
│ ├── LPV_unstructured_mix_new.m
│ ├── helpers
│ │ ├── build_Lyapmat.m
│ │ ├── build_Lyapmat_new.m
│ │ ├── build_derivative.m
│ │ ├── controller_recon_cL.m
│ │ └── extract_generalized_plant.m
│ └── obsolete
│ │ ├── LPV_Control_Opt.m
│ │ ├── build_grid.m
│ │ ├── build_indices_grid.m
│ │ ├── compute_Bode_grid.m
│ │ ├── compute_norm_grid.m
│ │ ├── grid_system.m
│ │ └── plot_bound.m
├── LCT_MixSynMIMO_LTI
│ └── LTI_unstructured_mix.m
├── LCT_MixedFixedOrder
│ ├── compute_FO_mix.m
│ └── compute_RO_mix.m
├── LCT_MixedHinfSyn
│ └── mixedHinfsyn.m
├── LCT_MixedHinfsynMIMO
│ └── mixedHinfsynMIMO.m
├── LCT_MixedHinfsynMIMO_unstab
│ ├── FPmodel.m
│ ├── FPmodel_MIMO.m
│ ├── control_beam.m
│ ├── control_beam_MIMO.m
│ ├── mixedHinfsyn_MIMO.m
│ ├── test_mixedhinfsynMIMO.m
│ ├── test_motor_MIMO.m
│ └── unstabpant_test.m
└── LCT_mixedHinflmitlab_MIMO
│ └── mixedHinflmilab.m
├── Examples
├── BasicControllerDesign
│ ├── example1_augmented_plant.m
│ ├── example2_simple_cd.m
│ ├── example3_better_cd.m
│ ├── example4_rolloff_cd.m
│ └── example5_optimal_cd.m
├── Standalone
│ ├── BLUX2016
│ │ └── BLUX2016_main.m
│ ├── Ballbot
│ │ └── ballbot.m
│ ├── Crane_LTI
│ │ ├── main.m
│ │ ├── measurements
│ │ │ ├── meas1.mat
│ │ │ ├── meas2.mat
│ │ │ ├── meas3.mat
│ │ │ ├── meas4.mat
│ │ │ └── meas5.mat
│ │ └── multisines
│ │ │ ├── musin1.mat
│ │ │ ├── musin2.mat
│ │ │ ├── musin3.mat
│ │ │ ├── musin4.mat
│ │ │ └── musin5.mat
│ ├── ECC2016
│ │ ├── ecc_2016_compare.m
│ │ ├── ecc_2016_hifoo.m
│ │ ├── ecc_2016_hinfstruct.m
│ │ ├── ecc_2016_mixedhinfsynmimo.m
│ │ ├── ecc_2016_systune.m
│ │ └── show_list.m
│ ├── IFAC2017
│ │ ├── Crane_fixedparam.m
│ │ ├── Crane_varyparam.m
│ │ ├── myODE.m
│ │ └── myOutput.m
│ ├── InvertedPendulum
│ │ ├── draw_pendulum.m
│ │ ├── pendulum_free.m
│ │ ├── pendulum_model.m
│ │ └── solo_pendulum_controller_design.m
│ ├── LAB_LSB250
│ │ ├── LAB_LSB250_demo.m
│ │ ├── excitations.mat
│ │ ├── exp1.mat
│ │ ├── exp2.mat
│ │ ├── exp3.mat
│ │ └── exp4.mat
│ ├── MBSE
│ │ ├── main.m
│ │ └── sys.mat
│ ├── SateliteTracking
│ │ └── SateliteTracking.m
│ ├── XYtable
│ │ ├── controllerX.m
│ │ └── identifiedX.mat
│ ├── XYtable_demo
│ │ ├── XYTable_demo.m
│ │ ├── longMeasurement_01508_1.mat
│ │ ├── longMeasurement_01508_3.mat
│ │ ├── longMeasurement_01508_5.mat
│ │ ├── longMeasurement_01508_7.mat
│ │ └── longMeasurement_01508_9.mat
│ └── drivetrain
│ │ ├── speedcontrol
│ │ ├── speedcontrol.m
│ │ └── speedcontrol_multiple.m
│ │ └── torquecontrol
│ │ ├── K.png
│ │ ├── S.png
│ │ ├── T.png
│ │ ├── U.png
│ │ ├── controller.zip
│ │ └── torquecontrol.m
└── VariousSolvers
│ ├── example1_Hinfsyn.m
│ ├── example2_weightedHinfsyn.m
│ ├── example3_mixedHinfsyn.m
│ ├── example4_mixedHinfsynMIMO.m
│ ├── example5_mixedHinfsynMIMO.m
│ └── example6_mixedFixedOrder.m
├── LICENSE
├── Modules
├── Control
│ ├── Channel.m
│ ├── ControlProblem.m
│ ├── ControllerDesign.m
│ ├── Norm.m
│ ├── NormConstraint.m
│ ├── Order.m
│ ├── Painter
│ │ ├── PaintStyleConference.m
│ │ ├── PaintStyleInterface.m
│ │ ├── PaintStyleNormal.m
│ │ ├── PaintStylePaperFancy.m
│ │ ├── PaintStylePaperPlain.m
│ │ └── Painter.m
│ ├── Processor
│ │ ├── MultiplicationProcessor.m
│ │ ├── ProcessorInterface.m
│ │ └── SimpleProcessor.m
│ ├── Region.m
│ ├── SchedulingParameter.m
│ ├── Solvers
│ │ ├── Gridsolver.m
│ │ ├── Solver.m
│ │ ├── Solver_HIFOO.m
│ │ ├── Solver_Hinfsyn.m
│ │ ├── Solver_SynLPV.m
│ │ ├── Solver_gssshinfcd.m
│ │ ├── Solver_hinfcd.m
│ │ ├── Solver_mixSynLPV.m
│ │ ├── Solver_mixedFixedOrder.m
│ │ ├── Solver_mixedHinfsyn.m
│ │ ├── Solver_mixedHinfsynMIMO.m
│ │ ├── Solver_mixedHinfsynMIMO_unstab.m
│ │ ├── Solver_mixedpoleMIMO.m
│ │ ├── Solver_sshinfcd.m
│ │ └── Solver_systune.m
│ ├── Specification.m
│ └── Weight.m
├── Identification
│ ├── FDMeasurementData.m
│ ├── MeasurementData.m
│ ├── Signals
│ │ ├── MonomialSignal.m
│ │ ├── MonomialSignal_real.m
│ │ ├── Multisine.m
│ │ ├── Parabola.m
│ │ ├── Ramp.m
│ │ ├── SmoothStep.m
│ │ ├── Step.m
│ │ └── TimeSignal.m
│ ├── TDMeasurementData.m
│ ├── nonpar_ident.m
│ └── param_ident.m
└── Modeling
│ ├── Models
│ ├── @ODEmod
│ │ ├── ODEmod.m
│ │ ├── impulse.m
│ │ ├── sim.m
│ │ ├── simfixed.m
│ │ └── step.m
│ ├── DSSmod.m
│ ├── FRDmod.m
│ ├── Gridmod.m
│ ├── IdentFRDmod.m
│ ├── LFTmod.m
│ ├── LPVDSSmod.m
│ ├── LPVLFTmod.m
│ ├── LTIDSSmod.m
│ ├── LTILFTmod.m
│ ├── SSmod.m
│ ├── SUMmod.m
│ ├── TFmod.m
│ ├── USSmod.m
│ ├── UTFmod.m
│ ├── UZPKmod.m
│ ├── Umod.m
│ ├── ZPKmod.m
│ ├── fromstd.m
│ └── helpers
│ │ ├── AbstractDSSmod.m
│ │ ├── AbstractLFTmod.m
│ │ ├── AbstractLPVmod.m
│ │ ├── AbstractLTImod.m
│ │ ├── AnalyticModel.m
│ │ ├── Model.m
│ │ ├── blkdiag_model.m
│ │ ├── safeeval.m
│ │ ├── safegrideval.m
│ │ └── stdargs.m
│ └── Systems
│ ├── @SystemOfSystems
│ ├── SystemOfSystems.m
│ └── solve.m
│ ├── AbstractSystem.m
│ ├── IOSystem.m
│ ├── Signal.m
│ ├── SystemOfModels.m
│ ├── restore.m
│ └── util
│ ├── extend_in.m
│ ├── extend_io.m
│ └── extend_out.m
├── README.md
└── Util
├── Hinfsyn_design_plot.m
├── Parameter.m
├── augw2.m
├── butter2.m
├── butterpoly.m
├── check_label.m
├── check_optispline.m
├── clean_plant.m
├── ctrbf_ip.m
├── dampen.m
├── db.m
├── dbtolinspline.m
├── diag2.m
├── diagE_ip.m
├── dss2ss.m
├── dss2ss_test.m
├── entrynorm.m
├── ismembertols.m
├── linestyles.m
├── lsimlpv.m
├── matrix_expand.m
├── mergestruct.m
├── minrealr.m
├── obsvf_ip.m
├── perfbode.m
├── range.m
├── removehigh.m
├── removelow.m
├── removeres.m
├── robust_rref.m
├── rrefE.m
├── shiftlow.m
├── ssOC.m
├── ssStaircase.m
├── sscomp.m
├── ssminreal.m
├── ssprescale_test.m
├── sstransform.m
├── test_perfbode.m
└── vector_expand.m
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "Modules/Identification/Resmile"]
2 | path = Modules/Identification/Resmile
3 | url = https://github.com/meco-group/resmile
4 |
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/bold.m:
--------------------------------------------------------------------------------
1 | function formatmsg = bold(msg)
2 | % BOLD Puts a message to be displayed in bold
3 |
4 | % This file is part of hinfcd.
5 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
6 | %
7 | % hinfcd is free software: you can redistribute it and/or modify it under
8 | % the terms of the GNU Lesser General Public License as published by the
9 | % Free Software Foundation, version 3.
10 | %
11 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
12 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 | % more details.
15 | %
16 | % You should have received a copy of the GNU Lesser General Public License
17 | % along with hinfcd. If not, see .
18 |
19 | if verLessThan('matlab','7.13') || (usejava('jvm') && ~feature('ShowFigureWindows'))
20 | formatmsg = msg;
21 | else
22 | formatmsg = ['' msg ''];
23 | end
24 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/dirsumdec.m:
--------------------------------------------------------------------------------
1 | function Z = dirsumdec(varargin)
2 | % DIRSUMDEC Returns the summand required to decompose a vector space through the direct sum
3 | %
4 | % Z = DIRSUMDEC(A,B,C,...,sum) returns Z, with orthonormal columns, such
5 | % that the direct sum of Col(A), Col(B), ... and the subspace Col(Z)
6 | % forms Col(sum).
7 | %
8 | % Helper function to make other functions more readible.
9 |
10 | % This file is part of hinfcd.
11 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
12 | %
13 | % hinfcd is free software: you can redistribute it and/or modify it under
14 | % the terms of the GNU Lesser General Public License as published by the
15 | % Free Software Foundation, version 3.
16 | %
17 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
18 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
20 | % more details.
21 | %
22 | % You should have received a copy of the GNU Lesser General Public License
23 | % along with hinfcd. If not, see .
24 |
25 | import hinfcd.util.*;
26 |
27 | assert(nargin>=2,'DIRSUMDEC: Not enough input arguments.');
28 | assert(all(cellfun(@(x) isnumeric(x) && size(x,1)==size(varargin{1},1), varargin)),'DIRSUMDEC: Inputs must be matrices with the same numbers of rows.');
29 | sum = varargin{end};
30 |
31 | % check for linear dependency
32 | m = horzcat(varargin{1:end-1});
33 | assert(size(m,2)<=size(m,1) && rank(m')<=size(m,2),'DIRSUMDEC: The summands provided are not linearly independent. A direct sum decomposition does not exist.');
34 |
35 | % calculate the summand that makes Z = R^n (n = size(sum,1))
36 | Z = null(m');
37 |
38 | % remove the dimensions of R^n such that the columns of Z span exactly
39 | % the same space as the columns of sum
40 | Z = isectspace(Z,sum);
41 |
42 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/explicitnull.m:
--------------------------------------------------------------------------------
1 | function A = explicitnull(E,nofcol)
2 | % EXPLICITNULL Explicit formulation of equality constraints
3 | %
4 | % A = EXPLICITNULL(E,nofcol) reparametrizes the equality constraint
5 | % E'*X = 0 as a constraint vec(X) = A(:,1)*x1 + A(:,2)*x2 + ... where the
6 | % optimization matrix variable X is transformed to an optimization vector
7 | % variable [x1 x2 ...]'. The length of this vector depends on the rank of
8 | % E. E is assumed to be square, X is not necessarily. X has nofcol columns.
9 | %
10 | % See also HINFCD.UTIL.EXPLICITSYM.
11 | %
12 | % This file is part of hinfcd.
13 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
14 | %
15 | % hinfcd is free software: you can redistribute it and/or modify it under
16 | % the terms of the GNU Lesser General Public License as published by the
17 | % Free Software Foundation, version 3.
18 | %
19 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
20 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
22 | % more details.
23 | %
24 | % You should have received a copy of the GNU Lesser General Public License
25 | % along with hinfcd. If not, see .
26 |
27 | B = kron(eye(nofcol),E');
28 | A = null(B);
29 |
30 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/isectspace.m:
--------------------------------------------------------------------------------
1 | function Z = isectspace(varargin)
2 | % ISECTSPACE Returns an orthonormal basis for the intersection of spaces
3 | % Returns an orthonormal basis for the intersection of vector spaces.
4 | %
5 | % This approach is adopted from G.H. Golub, C.F. Van Loan, "Matrix
6 | % Computations", 4th edition, The John Hopkin University Press, Baltimore,
7 | % 1996.
8 | %
9 | % Z = ISECTSPACE(A,B,C,...) returns Z such that the columns of Z are an
10 | % orthonormal basis for the intersection of Col(A), Col(B), ...
11 |
12 | % This file is part of hinfcd.
13 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
14 | %
15 | % hinfcd is free software: you can redistribute it and/or modify it under
16 | % the terms of the GNU Lesser General Public License as published by the
17 | % Free Software Foundation, version 3.
18 | %
19 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
20 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
22 | % more details.
23 | %
24 | % You should have received a copy of the GNU Lesser General Public License
25 | % along with hinfcd. If not, see .
26 |
27 | assert(nargin>=1, 'ISECTSPACE: Not enough input arguments.');
28 | n = size(varargin{1},1);
29 | assert(all(cellfun(@(x) isnumeric(x) && size(x,1)==n, varargin)), 'ISECTSPACE: Inputs must be matrices with the same number of rows.');
30 | tol = sqrt(eps);
31 |
32 | if nargin==1 % trivial case
33 | Z = orth(varargin{1});
34 | elseif nargin>2 % recursion
35 | Z = isectspace(varargin{2:end});
36 | Z = isectspace(varargin{1},Z);
37 | else % actual algorithm
38 | A = varargin{1};
39 | B = varargin{2};
40 | if size(A,2).
18 |
19 | if verLessThan('matlab','7.13') || (usejava('jvm') && ~feature('ShowFigureWindows'))
20 | formatmsg = msg;
21 | else
22 | formatmsg = ['' msg ''];
23 | end
24 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/mergestruct.m:
--------------------------------------------------------------------------------
1 | function [s] = mergestruct(varargin)
2 | % MERGESTRUCT Merge multiple structures
3 | % Merges 2 or more structures into 1 structure where the first structure
4 | % has priority on the second, meaning that fields with the same name will
5 | % be taken from the first and not from the second. When there are more
6 | % than 2 structures, the 2nd has priority over the 3rd and so on. This
7 | % file was originally written by Maarten Verbandt for LCToolbox.
8 |
9 | % This file is part of hinfcd.
10 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
11 | %
12 | % hinfcd is free software: you can redistribute it and/or modify it under
13 | % the terms of the GNU Lesser General Public License as published by the
14 | % Free Software Foundation, version 3.
15 | %
16 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
17 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
19 | % more details.
20 | %
21 | % You should have received a copy of the GNU Lesser General Public License
22 | % along with hinfcd. If not, see .
23 |
24 | s = struct();
25 |
26 | for k = 1:length(varargin)
27 | if ~isempty(varargin{k})
28 | s0 = varargin{k};
29 | fields0 = fieldnames(s0);
30 | fields = fieldnames(s);
31 |
32 | % check which fields needed merge and which are new
33 | [lia,~] = ismember(fields0,fields);
34 |
35 | for(j = 1:length(fields0)) % iterate over fields that are set and change them to the new value
36 | if(lia(j)) % merge
37 | if(isstruct(s.(fields0{j,1})))
38 | s.(fields0{j,1}) = mergestruct(s.(fields0{j,1}),s0.(fields0{j,1})); % merge the structured fields recursively
39 | end
40 | else % add
41 | s.(fields0{j,1}) = s0.(fields0{j,1});
42 | end
43 | end
44 | end
45 | end
46 | end
47 |
48 |
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/orthtol.m:
--------------------------------------------------------------------------------
1 | function B = orthtol(A,zerotol)
2 | % ORTHTOL Returns an orthonormal basis of the range of a matrix
3 | %
4 | % Same functionality as b = orth(a) from MATLAB, but allows for a
5 | % tolerance.
6 | %
7 | % b = ORTHTOL(a) returns a matrix b such that its columns form an
8 | % orthonormal basis of Col(a)
9 | %
10 | % b = ORTHTOL(a,zerotol) returns the same as the previous syntax, but
11 | % treats the singular values that are smaller than zerotol (default value:
12 | % sqrt(eps)) as exact zeros
13 |
14 | % This file is part of hinfcd.
15 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
16 | %
17 | % hinfcd is free software: you can redistribute it and/or modify it under
18 | % the terms of the GNU Lesser General Public License as published by the
19 | % Free Software Foundation, version 3.
20 | %
21 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
22 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
24 | % more details.
25 | %
26 | % You should have received a copy of the GNU Lesser General Public License
27 | % along with hinfcd. If not, see .
28 |
29 | if nargin>0; zerotol = sqrt(eps); end
30 | [U,S] = svd(A,'econ');
31 | B = U(:,abs(diag(S))>=zerotol);
32 |
33 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/preim.m:
--------------------------------------------------------------------------------
1 | function BAI = preim(A,S)
2 | % PREIM Returns a basis of a preimage under a linear transformation
3 | % Returns an orthonormal basis of the preimage of (the image of) S under
4 | % the linear mapping A. See S. Trenn, "Distributional differential
5 | % algebraic equations", PhD thesis, Institute for Mathematics, University
6 | % of Ilmenau, Germany, 2009.
7 | %
8 | % Helper function to make other functions more readible.
9 | %
10 | % BAI = PREIM(A,S) returns BAI such that Col(BAI) spans A^(-1)(S) and BAI
11 | % has orthonormal columns
12 |
13 | % This file is part of hinfcd.
14 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
15 | %
16 | % hinfcd is free software: you can redistribute it and/or modify it under
17 | % the terms of the GNU Lesser General Public License as published by the
18 | % Free Software Foundation, version 3.
19 | %
20 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
21 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
23 | % more details.
24 | %
25 | % You should have received a copy of the GNU Lesser General Public License
26 | % along with hinfcd. If not, see .
27 |
28 | assert(size(A,1)==size(S,1), 'PREIM: A and S must have compatible dimensions.');
29 | BAI = null([A,S]);
30 | BAI = BAI(1:size(A,2),:);
31 |
32 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/removehtml.m:
--------------------------------------------------------------------------------
1 | function msg = removehtml(formatmsg)
2 | % REMOVEHTML Removes HTML tags from a formatted message
3 |
4 | % This file is part of hinfcd.
5 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
6 | %
7 | % hinfcd is free software: you can redistribute it and/or modify it under
8 | % the terms of the GNU Lesser General Public License as published by the
9 | % Free Software Foundation, version 3.
10 | %
11 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
12 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 | % more details.
15 | %
16 | % You should have received a copy of the GNU Lesser General Public License
17 | % along with hinfcd. If not, see .
18 |
19 | msg = regexprep(formatmsg,'<(.*?)>','');
20 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/+util/roundsmall.m:
--------------------------------------------------------------------------------
1 | function A = roundsmall(A,zerotol)
2 | % ROUNDSMALL Sets small values to zero
3 | % Sets values of the array A that are smaller than a tolerance to zero
4 | %
5 | % Ar = ROUNDSMALL(A, tol) returns Ar, such that Ar(i) = A(i) if abs(A(i))>=
6 | % zerotol, else Ar(i) = 0. The default value of zerotol is sqrt(eps).
7 |
8 | % This file is part of hinfcd.
9 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
10 | %
11 | % hinfcd is free software: you can redistribute it and/or modify it under
12 | % the terms of the GNU Lesser General Public License as published by the
13 | % Free Software Foundation, version 3.
14 | %
15 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
16 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
18 | % more details.
19 | %
20 | % You should have received a copy of the GNU Lesser General Public License
21 | % along with hinfcd. If not, see .
22 |
23 | if nargin<2
24 | zerotol = sqrt(eps);
25 | end
26 | A(abs(A).
32 |
33 | import hinfcd.util.*;
34 |
35 | assert(size(E,1)==size(E,2) && size(A,1)==size(A,2) && size(A,1)==size(E,1), 'WONGSEQ: E and A must be square matrices of the same size.');
36 | assert(size(A,1)==size(B,1), 'WONGSEQ: A and B should have the same number of rows.');
37 | assert(size(A,2)==size(C,2), 'WONGSEQ: A and C should have the same number of columns.');
38 | assert(size(A,1)==size(S,1), 'WONGSEQ: S should have the same number of rows as A and B.');
39 |
40 | % calculate constants
41 | imB = orth(B);
42 | kerC = null(C);
43 |
44 | % initial element
45 | W = S;
46 |
47 | % iterate
48 | for i=1:size(A,1)+1
49 | Wn = isectspace(preim(A,orth([E*W,imB])),kerC);
50 | if size(Wn,2)==size(W,2)
51 | break; % converged
52 | elseif i==size(A,1)+1
53 | assert(size(Wn,2)==size(W,2), 'WONGSEQ: Wong sequence did not converge.');
54 | end
55 | W = Wn;
56 | end
57 |
58 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/@dss/dss.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/3rdparty/+hinfcd/@dss/dss.m
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/@dss/kronreal.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/3rdparty/+hinfcd/@dss/kronreal.m
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/@dss/svdreal.m:
--------------------------------------------------------------------------------
1 | function [obj,U,V] = svdreal(obj)
2 | % SVDREAL SVD canonical realization
3 | %
4 | % b = SVDREAL(a) returns b, an equivalent realization of a, such that
5 | % E = [I 0]
6 | % [0 0]
7 | %
8 | % [b,U,V] = OREDREALSVD(obj) returns the same as the previous
9 | % syntax, and furthermore returns the transformation matrices that were
10 | % used to obtain the canonical form as follows: Aa = U*Ab*V', Ba = U*Bb,
11 | % Ca = Cb*V', Ea = U*Eb*V'.
12 | %
13 | % See also HINFCD.UTIL.OREDREALSVD.
14 |
15 | % This file is part of hinfcd.
16 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
17 | %
18 | % hinfcd is free software: you can redistribute it and/or modify it under
19 | % the terms of the GNU Lesser General Public License as published by the
20 | % Free Software Foundation, version 3.
21 | %
22 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
23 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
25 | % more details.
26 | %
27 | % You should have received a copy of the GNU Lesser General Public License
28 | % along with hinfcd. If not, see .
29 |
30 | re = rank(obj.E);
31 | [U,S,V] = svd(obj.E);
32 | U = U*blkdiag(sqrt(S(1:re,1:re)),eye(size(obj.E)-re));
33 | V = V*blkdiag(sqrt(S(1:re,1:re)),eye(size(obj.E)-re));
34 | A = U\obj.A/V';
35 | B = U\obj.B;
36 | C = obj.C/V';
37 | obj = obj.set('A',A,'B',B,'C',C,'E',diag([ones(1,re) zeros(1,size(obj.E,1)-re)]));
38 |
39 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/@hinfcd/options.m:
--------------------------------------------------------------------------------
1 | function s = options(obj)
2 | % OPTIONS Returns the standard settings and allows the user to easily change his/her preferred options in the structure
3 |
4 | % synthesis
5 | s.synthesis.gammasolver = 'lmilab'; % 'lmilab', 'cvx', 'yalmip'
6 | s.synthesis.minrank = false; % true, false
7 | s.synthesis.lyapunovsolver = 'lmilab'; % 'lmilab', 'cvx', 'yalmip'
8 | s.synthesis.relaxation = 1.01; % any real number >= 1
9 | s.synthesis.zerotol = 0; % any real number >= 0
10 | s.synthesis.formulation = 'statespace'; % 'statespace' or 'descriptor'
11 |
12 | % reconstruction
13 | s.reconstruction.reducedorder = false; % true, false
14 | s.reconstruction.solver = 'basiclmi'; % 'lmilab', 'cvx', 'yalmip', 'basiclmi'
15 | s.reconstruction.method = 'transform'; % 'actual', 'transform'
16 | s.reconstruction.zerotol = 1e-8; % any real number >= 0
17 | s.reconstruction.maxiter = 50; % any integer number >= 0
18 | s.reconstruction.singvaltol = 0; % any real number >= 0
19 |
20 | % LMILAB interface
21 | s.lmilab = [1e-8 500 0 0 0]; % LMILAB options, see the mincx() and feasp() documentation
22 |
23 | % YALMIP interface
24 | try
25 | s.yalmip = sdpsettings(); % YALMIP options, see the YALMIP documentation
26 | catch
27 | s.yalmip = struct();
28 | end
29 |
30 | % CVX interface
31 | s.cvx.solver = ''; % solver for CVX, see the CVX documentation
32 | s.cvx.solver_settings = {''}; % solver settings for CVX, see the CVX documentation
33 | s.cvx.precision = 'default'; % precision settings for CVX, see the CVX documentation
34 |
35 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/@hinfcd/setoptions.m:
--------------------------------------------------------------------------------
1 | function obj = setoptions(obj,s)
2 | % SETOPTIONS Sets the options for the control problem and its handling
3 |
4 | % This file is part of hinfcd.
5 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
6 | %
7 | % hinfcd is free software: you can redistribute it and/or modify it under
8 | % the terms of the GNU Lesser General Public License as published by the
9 | % Free Software Foundation, version 3.
10 | %
11 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
12 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 | % more details.
15 | %
16 | % You should have received a copy of the GNU Lesser General Public License
17 | % along with hinfcd. If not, see .
18 |
19 | % get default options
20 | defops = options(obj);
21 |
22 | % recursively merge options
23 | if nargin>1
24 | obj.opts = mergestruct(s,defops);
25 | else
26 | obj.opts = defops;
27 | end
28 |
29 | end
--------------------------------------------------------------------------------
/3rdparty/+hinfcd/@hinfcd/solve.m:
--------------------------------------------------------------------------------
1 | function [K,gamma] = solve(obj,options)
2 | % SOLVE Solves the control problem
3 |
4 | % This file is part of hinfcd.
5 | % Copyright (c) 2019, Laurens Jacobs, MECO Research Team @ KU Leuven.
6 | %
7 | % hinfcd is free software: you can redistribute it and/or modify it under
8 | % the terms of the GNU Lesser General Public License as published by the
9 | % Free Software Foundation, version 3.
10 | %
11 | % hinfcd is distributed in the hope that it will be useful, but WITHOUT ANY
12 | % WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 | % FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 | % more details.
15 | %
16 | % You should have received a copy of the GNU Lesser General Public License
17 | % along with hinfcd. If not, see .
18 |
19 | import hinfcd.util.*;
20 |
21 | if nargin>1 && isstruct(options)
22 | obj = obj.setoptions(options);
23 | else
24 | obj = obj.setoptions();
25 | end
26 |
27 | % 0. Start
28 | obj.watchdog.info(bold('THIS IS HINFCD, VERSION 1.0 (May 2020)'));
29 |
30 | % 1. Formulate the problem as an SDP
31 | obj.watchdog.info('STARTED PREPROCESSING');
32 | obj.watchdog.startSubTask();
33 | obj.watchdog.info('Formulating the SDP...');
34 | obj.preprocessor = hinfcd.preprocessor(obj.problem, obj.opts);
35 | obj.watchdog.endSubTask();
36 |
37 | % 2. Solve the SDP
38 | obj.watchdog.info('STARTED SOLVING');
39 | obj.watchdog.startSubTask();
40 | obj.watchdog.info('Solving the SDP...');
41 | [K,gamma]= obj.preprocessor.solve();
42 | obj.watchdog.endSubTask();
43 |
44 | % 3. Postprocess the solution
45 | obj.watchdog.info('STARTED POSTPROCESSING...');
46 | obj.postprocessor = hinfcd.postprocessor(obj.problem, K, gamma);
47 | obj.watchdog.startSubTask();
48 | obj.watchdog.info('Recombining the controller with the unstable and improper modes of the weighting filters...');
49 | obj.postprocessor = obj.postprocessor.recombine();
50 | obj.postprocessor = obj.postprocessor.elimstaticmodes();
51 | obj.postprocessor = obj.postprocessor.compensateDyu();
52 | obj.watchdog.endSubTask();
53 |
54 | % 4. Return
55 | K = obj.postprocessor.K;
56 |
57 | end
--------------------------------------------------------------------------------
/3rdparty/LCT_CExport/c_export.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function c_export(settings,varargin)
18 | %C_EXPORT Summary of this function goes here
19 | % Detailed explanation goes here
20 |
21 | assert(mod(length(varargin),2)==0,'expected even number of controllers and names');
22 |
23 | % split input arguments
24 | controllers = varargin(1:2:end);
25 | names = varargin(2:2:end);
26 | Ts = controllers{1}.Ts;
27 |
28 | sprintf('Exporting %d %s to %s',length(controllers),settings.cname,settings.filename);
29 |
30 | % make header
31 | make_header(settings,controllers,names);
32 | % make source
33 | make_source(settings,controllers,names,Ts);
34 |
35 | if(isfield(settings,'example') && settings.example)
36 | % make example
37 | make_example(settings,names);
38 | % make makefile
39 | make_makefile(settings);
40 | end
41 |
42 | end
43 |
44 |
--------------------------------------------------------------------------------
/3rdparty/LCT_CExport/make_example.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function make_example(settings,names)
18 | %MAKE_EXAMPLE Summary of this function goes here
19 | % Detailed explanation goes here
20 |
21 | % create example file
22 | mkdir([settings.folder 'example']);
23 | example = fopen([settings.folder 'example/example.cpp'],'w');
24 |
25 | fprintf(example,'#include "%s.h"\n#include \n\n',settings.filename);
26 | fprintf(example,'int main() {\n');
27 | fprintf(example,'\tfloat input[1];\n\n');
28 | fprintf(example,'\t%s::%s controller;\n',settings.namespace,settings.cname);
29 | cellfun(@(x)impulse(example,settings,x),names);
30 | fprintf(example,'}');
31 |
32 | fclose(example);
33 | end
34 |
35 | function impulse(example,settings,name)
36 |
37 | fprintf(example,'\tstd::cout << "%s" << std::endl << "=======" << std::endl;\n',name);
38 | fprintf(example,'\tcontroller.load(%s::%s::%s);\n',settings.namespace,settings.cname,upper(name));
39 | fprintf(example,'\tinput[0] = 1.0f/controller.Ts();\n');
40 | fprintf(example,'\tcontroller.update(input);\n\n');
41 | fprintf(example,'\tinput[0] = 0.0;\n');
42 | fprintf(example,'\tfor(int k=0;k<50;k++){\n');
43 | fprintf(example,'\t\tstd::cout << controller.actuation()[0] << std::endl;\n');
44 | fprintf(example,'\t\tcontroller.update(input);\n\t}\n\n');
45 |
46 | end
47 |
--------------------------------------------------------------------------------
/3rdparty/LCT_CExport/make_header.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function make_header(settings,controllers,names)
18 |
19 | % check controllers
20 | nstates = max(cellfun(@(x)size(x.a,1),controllers));
21 | nout = max(cellfun(@(x)size(x.c,1),controllers));
22 |
23 | % create header file
24 | header = fopen([settings.folder settings.filename '.h'],'w');
25 |
26 | % include guard
27 | fprintf(header,'#ifndef %s_H\n',upper(settings.cname));
28 | fprintf(header,'#define %s_H\n\n',upper(settings.cname));
29 |
30 | % namespace
31 | fprintf(header,'namespace %s {\n\n',settings.namespace);
32 |
33 | % class
34 | fprintf(header,'class %s\n{\n',settings.cname);
35 |
36 | % namespace and enum
37 | fprintf(header,'public:\n');
38 | fprintf(header,'\ttypedef enum algorithm_t {\n');
39 | cellfun(@(x) fprintf(header,'\t\t%s,\n',upper(x)),names);
40 | fprintf(header,'\t} algorithm_t;\n\n');
41 |
42 | fprintf(header,'private:\n\tconst float _Ts;\n\tint _algorithm;\n\n');
43 | fprintf(header,'\tfloat _x[%d];\n',nstates);
44 | fprintf(header,'\tfloat _y[%d];\n\n',nout);
45 |
46 | % load and update per controller
47 | cellfun(@(x) fprintf(header,'\t//%s functions\n\tinline void load_%s();\n\tinline void update_%s(float* measurements);\n\n',x,x,x),names);
48 |
49 | fprintf(header,'public:\n');
50 | fprintf(header,'\t%s();\n\n',settings.cname);
51 |
52 | fprintf(header,'\tvoid load(int algorithm);\n');
53 | fprintf(header,'\tfloat* update(float* measurements);\n\n');
54 |
55 | fprintf(header,'\tfloat* actuation();\n');
56 | fprintf(header,'\tfloat Ts();\n');
57 | fprintf(header,'\tvoid reset();\n');
58 |
59 | fprintf(header,'}; //class\n\n');
60 | fprintf(header,'}; //namespace\n\n');
61 | fprintf(header,'#endif //%s_H\n',upper(settings.cname));
62 |
63 | fclose(header);
64 | end
65 |
--------------------------------------------------------------------------------
/3rdparty/LCT_CExport/make_makefile.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [ output_args ] = make_makefile(settings)
18 | %MAKE_MAKEFILE Summary of this function goes here
19 | % Detailed explanation goes here
20 |
21 | % create makefile
22 | makefile = fopen([settings.folder 'example/makefile'],'w');
23 |
24 | fprintf(makefile,'example: example.cpp ../%s.cpp\n',settings.filename);
25 | fprintf(makefile,'\tg++ -o example example.cpp ../%s.cpp -I ..\n',settings.filename);
26 |
27 | fclose(makefile);
28 | end
29 |
30 |
--------------------------------------------------------------------------------
/3rdparty/LCT_CExport/matrix_expand.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [code] = matrix_expand(X,v,varargin)
18 | %MATRIX_EXPAND expands a matrix product to C code
19 | % Detailed explanation goes here
20 |
21 | options = struct('optZ',1e-10,...
22 | 'optO',1e-10);
23 | if(nargin>2)
24 | options = mergestruct(varargin{1},options);
25 | end
26 |
27 | N = size(X,1);
28 | code = cell(N,1);
29 | for k=1:size(X,1)
30 | % expand cell
31 | code{k,1} = row_expand(X(k,:),v,options);
32 | end
33 |
34 | end
35 |
36 | function [line] = row_expand(R,v,options)
37 | %ROW_EXPAND expand row to corresponding C code
38 | % Detailed explanation goes here
39 |
40 | line = [];
41 | for k=1:length(R)
42 | % expand cell
43 | if((options.optZ>0)&&(abs(R(k))0)&&(abs(R(k)-1)0)&&(abs(R(k)+1)
3 |
4 | int main() {
5 | float input[1];
6 |
7 | Ballbot::AttitudeController controller;
8 | std::cout << "controller1" << std::endl << "=======" << std::endl;
9 | controller.load(Ballbot::AttitudeController::CONTROLLER1);
10 | input[0] = 1.0f/controller.Ts();
11 | controller.update(input);
12 |
13 | input[0] = 0.0;
14 | for(int k=0;k<50;k++){
15 | std::cout << controller.actuation()[0] << std::endl;
16 | controller.update(input);
17 | }
18 |
19 | std::cout << "controller2" << std::endl << "=======" << std::endl;
20 | controller.load(Ballbot::AttitudeController::CONTROLLER2);
21 | input[0] = 1.0f/controller.Ts();
22 | controller.update(input);
23 |
24 | input[0] = 0.0;
25 | for(int k=0;k<50;k++){
26 | std::cout << controller.actuation()[0] << std::endl;
27 | controller.update(input);
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/3rdparty/LCT_CExport/test/example/makefile:
--------------------------------------------------------------------------------
1 | example: example.cpp ../attitude_controller.cpp
2 | g++ -o example example.cpp ../attitude_controller.cpp -I ..
3 |
--------------------------------------------------------------------------------
/3rdparty/LCT_CExport/test/test.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | clear all
18 | close all
19 | clc
20 |
21 | settings.namespace = 'Ballbot';
22 | settings.filename = 'attitude_controller';
23 | settings.cname = 'AttitudeController';
24 |
25 | Ts = 0.01;
26 |
27 | A1 = [-0.1916, -0.1814; 0.1814, -0.1916];
28 | B1 = [0; 0.5447];
29 | C1 = [-0.1379, 0.6199];
30 | D1 = [0];
31 | c1 = ss(A1,B1,C1,D1,Ts);
32 |
33 | A2 = [-0.3573, 0.2659, -0.3172; 0.2523, -0.09952, -0.5243; -0.3281, -0.5175, 0.131];
34 | B2 = [ 0; 0.06922; 2.487];
35 | C2 = [-1.666, -0.4159, -0.08422];
36 | D2 = [0];
37 |
38 | c2 = ss(A2,B2,C2,D2,Ts);
39 |
40 | n1 = 'controller1';
41 | n2 = 'controller2';
42 |
43 | c_export(settings,c1,n1,c2,n2);
--------------------------------------------------------------------------------
/3rdparty/LCT_CExport/vector_expand.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [code] = vector_expand(N,v)
18 | %VECTOR_EXPAND Expands a vector to its entries
19 | % Detailed explanation goes here
20 |
21 | code = cell(N,1);
22 | for k=1:N
23 | code{k,1} = [v '[' num2str(k-1) ']'];
24 | end
25 |
26 | end
27 |
28 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/Iij.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [ output ] = Iij( dim1, dim2, i, j )
18 |
19 | output = zeros(dim1, dim2);
20 | output(i,j) = 1;
21 |
22 | end
23 |
24 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/buildKnotSeq.m:
--------------------------------------------------------------------------------
1 | function [ lambda ] = buildKnotSeq(varargin)
2 |
3 | required = {'breakpoints','degree'};
4 | optional = {};
5 |
6 | calls = varargin(1:2:end);
7 | assert(mod(nargin,2) == 0,'Odd number of arguments.');
8 | assert(iscellstr(calls),'The names of your name/value pairs should be strings.');
9 | assert(~any(~ismember(required,calls)),['These arguments are required: ' strjoin(required)]);
10 | for i = 1:nargin/2
11 | if strcmp(varargin{2*i-1},'breakpoints'); assert(~exist('breakpoints','var'),'You cannot define breakpoints twice.'); breakpoints = varargin{2*i}; end;
12 | if strcmp(varargin{2*i-1},'degree'); assert(~exist('degree','var'),'You cannot define degree twice.'); degree = varargin{2*i}; end;
13 | end
14 |
15 | lambda = [min(breakpoints)*ones(1, degree), sort(breakpoints), max(breakpoints)*ones(1, degree)];
16 |
17 | end
18 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/evalnstackGlob.m:
--------------------------------------------------------------------------------
1 | function [ As, Bs, Cs, Ds ] = evalnstackGlob( A, B, C, D, basisEval)
2 | % suppose size(basisEval) = [nb 1 N]
3 | As = zeros(size(basisEval,3),size(A,2),size(A,3));
4 | Bs = zeros(size(basisEval,3),size(B,2),size(B,3));
5 | Cs = zeros(size(basisEval,3),size(C,2),size(C,3));
6 | Ds = zeros(size(basisEval,3),size(D,2),size(D,3));
7 |
8 | for t = 1:size(basisEval,3)
9 | for i = 1:size(basisEval,1)
10 | As(t,:,:) = As(t,:,:) + A(i,:,:)*basisEval(i,:,t);
11 | Bs(t,:,:) = Bs(t,:,:) + B(i,:,:)*basisEval(i,:,t);
12 | Cs(t,:,:) = Cs(t,:,:) + C(i,:,:)*basisEval(i,:,t);
13 | Ds(t,:,:) = Ds(t,:,:) + D(i,:,:)*basisEval(i,:,t);
14 | end
15 |
16 | end
17 |
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/evalnstackLoc.m:
--------------------------------------------------------------------------------
1 | function [ As, Bs, Cs, Ds ] = evalnstackLoc( A, B, C, D, basisEval)
2 | % suppose size(basisEval) = [nb 1 N]
3 | As = zeros(size(basisEval,3),size(A,2),size(A,3));
4 | Bs = zeros(size(basisEval,3),size(B,2),size(B,3));
5 | Cs = zeros(size(basisEval,3),size(C,2),size(C,3));
6 | Ds = zeros(size(basisEval,3),size(D,2),size(D,3));
7 |
8 | for t = 1:size(basisEval,3)
9 | for i = 1:size(basisEval,1)
10 | As(t,:,:) = As(t,:,:) + A(i,:,:)*basisEval(i,:,t);
11 | Bs(t,:,:) = Bs(t,:,:) + B(i,:,:)*basisEval(i,:,t);
12 | Cs(t,:,:) = Cs(t,:,:) + C(i,:,:)*basisEval(i,:,t);
13 | Ds(t,:,:) = Ds(t,:,:) + D(i,:,:)*basisEval(i,:,t);
14 | end
15 | end
16 |
17 | end
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/getFRFerror_LCT.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [ errorFRF ] = getFRFerror_LCT(freqLines, OmegaConc, FRFmConc, pGridIdent, schParam, model )
18 |
19 | FRFerror = zeros(numel(FRFmConc),1);
20 | for k = 1:numel(pGridIdent)
21 | mdlEval = model.evalme(pGridIdent(k),{schParam});
22 | FRFerror(((freqLines(k)-1)*nout(mdlEval)*nin(mdlEval)+1):((freqLines(k+1)-1)*nout(mdlEval)*nin(mdlEval)),1) = vec(freqresp(mdlEval,OmegaConc((freqLines(k):(freqLines(k+1)-1)),1))) - FRFmConc(((freqLines(k)-1)*nout(mdlEval)*nin(mdlEval)+1):((freqLines(k+1)-1)*bout(mdlEval)*nin(mdlEval)),1);
23 | end
24 | errorFRF = [real(FRFerror); imag(FRFerror)];
25 |
26 | end
27 |
28 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/getJacobianFast_LCT_arr.m:
--------------------------------------------------------------------------------
1 | function [Jacobian] = getJacobianFast_LCT_arr(As, Bs, Cs, u, basisEval, x0)
2 |
3 | % size(As) = N n n, size(Bs) = N n nu
4 | % size(Cs) = N ny n, size(Ds) = N ny nu
5 | % size(u) = N nu 1
6 | % size(basisEval) = nb 1 N
7 | na = size(As,2);
8 | nu = size(Bs,3);
9 | ny = size(Cs,2);
10 | nb = size(basisEval,1);
11 | N = size(u,1);
12 | x = zeros(N+1,na,1);
13 | x(1,:,1) = x0;
14 | dx = zeros(N+1,na,nb*(na*na+na*nu+ny*na+ny*nu));
15 | Jacobian = zeros(ny*N,nb*(na*na+na*nu+ny*na+ny*nu));
16 |
17 | for t = 1:N
18 | for i = 1:nb
19 | % A
20 | for k = 1:na
21 | for j = 1:na
22 | Jacobian(((t-1)*ny+1):(t*ny),(i-1)*na*na+(k-1)*na+j) = reshape(Cs(t,:,:),[ny na])*reshape(dx(t,:,(i-1)*na*na+(k-1)*na+j),[na 1]);
23 | dx(t+1,:,(i-1)*na*na+(k-1)*na+j) = reshape(basisEval(i,:,t),[1 1])*Ijk([na na],[j k])*reshape(x(t,:,:),[na 1]) + reshape(As(t,:,:),[na na])*reshape(dx(t,:,(i-1)*na*na+(k-1)*na+j),[na 1]);
24 | end
25 | end
26 | % B
27 | for k = 1:nu
28 | for j = 1:na
29 | Jacobian(((t-1)*ny+1):(t*ny),nb*na*na+(i-1)*na*nu+(k-1)*na+j) = reshape(Cs(t,:,:),[ny na])*reshape(dx(t,:,nb*na*na+(i-1)*na*nu+(k-1)*na+j),[na 1]);
30 | dx(t+1,:,nb*na*na+(i-1)*na*nu+(k-1)*na+j) = reshape(basisEval(i,:,t),[1 1])*Ijk([na nu],[j k])*reshape(u(t,:,:),[size(u,2) size(u,3)]) + reshape(As(t,:,:),[na na])*reshape(dx(t,:,nb*na*na+(i-1)*na*nu+(k-1)*na+j),[na 1]);
31 | end
32 | end
33 | % C
34 | for k = 1:na
35 | for j = 1:ny
36 | Jacobian(((t-1)*ny+1):(t*ny),nb*(na*na+na*nu)+(i-1)*ny*na+(k-1)*ny+j) = reshape(basisEval(i,:,t),[1 1])*Ijk([ny na],[j k])*reshape(x(t,:,:),[na 1]);
37 | end
38 | end
39 | % D
40 | for k = 1:nu
41 | for j = 1:ny
42 | Jacobian(((t-1)*ny+1):(t*ny),nb*(na*na+na*nu+ny*na)+(i-1)*ny*nu+(k-1)*ny+j) = reshape(basisEval(i,:,t),[1 1])*Ijk([ny nu],[j k])*reshape(u(t,:,:),[size(u,2) size(u,3)]);
43 | end
44 | end
45 | end
46 | x(t+1,:,:) = reshape(As(t,:,:),[na na])*reshape(x(t,:,:),[na 1]) + reshape(Bs(t,:,:),[na nu])*reshape(u(t,:,:),[size(u,2) size(u,3)]);
47 | end
48 |
49 | end
50 |
51 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/normalise.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [J,scaling] = normalise(J)
18 |
19 | scaling = rms(J);
20 | scaling_better = ones(size(scaling));
21 | indices = find(scaling);
22 | scaling_better(indices) = scaling(indices);
23 | scaling = scaling_better;
24 | J = J*diag(1./scaling');
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/plotLPVSSmatrices.m:
--------------------------------------------------------------------------------
1 | function plotLPVSSmatrices( varargin )
2 |
3 | required = {'LPVmod'};
4 | optional = {'figNumber','color'};
5 |
6 | calls = varargin(1:2:end);
7 | assert(mod(nargin,2) == 0,'Odd number of arguments.');
8 | assert(iscellstr(calls),'The names of your name/value pairs should be strings.');
9 | assert(~any(~ismember(required,calls)),['These arguments are required: ' strjoin(required)]);
10 | for i = 1:nargin/2
11 | if strcmp(varargin{2*i-1},'LPVmod'); assert(~exist('LPVmod','var'),'You cannot define the LPVmod twice.'); LPVmod = varargin{2*i}; end;
12 | if strcmp(varargin{2*i-1},'figNumber'); assert(~exist('figNumber','var'),'You cannot define the figNumber twice.'); figNumber = varargin{2*i}; end;
13 | if strcmp(varargin{2*i-1},'color'); assert(~exist('color','var'),'You cannot define the color twice.'); color = varargin{2*i}; end;
14 | if ~ismember(varargin{2*i-1},[required, optional]); warning(['I could not identify the option ''' varargin{2*i-1} ''' and I am going to ignore it.']); end;
15 | end
16 | assert(isa(LPVmod,'LPVDSSmod'),'Unsupported data type.')
17 |
18 | if exist('color','var')
19 | assert(ischar(color),'Variable color must be a character.')
20 | else
21 | color = 'b';
22 | end
23 |
24 | schedGrid = linspace(LPVmod.getdssdata.domain.domain.min,LPVmod.getdssdata.domain.domain.max,1e3);
25 | T = [LPVmod.A LPVmod.B; LPVmod.C LPVmod.D];
26 | T_eval = T.list_eval(schedGrid);
27 | T_eval_knots = T.list_eval(T.basis.knots);
28 |
29 | if exist('figNumber','var')
30 | assert(isnumeric(figNumber),'Variable figNumber must be have a numeric value.')
31 | figure(figNumber)
32 | for i = 1:T.size(1)
33 | for j = 1:T.size(2)
34 | subplot(T.size(1),T.size(2),(i-1)*T.size(2)+j)
35 | plot(schedGrid,T_eval(:,i,j),color,'Linewidth',1.5); hold on
36 | scatter(T.basis.knots,T_eval_knots(:,i,j),'MarkerEdgeColor',color); hold on
37 | end
38 | end
39 | else
40 | figure
41 | for i = 1:T.size(1)
42 | for j = 1:T.size(2)
43 | subplot(T.size(1),T.size(2),(i-1)*T.size(2)+j)
44 | plot(schedGrid,T_eval(:,i,j),color,'Linewidth',1.5); hold on
45 | scatter(T.basis.knots,T_eval_knots(:,i,j),'MarkerEdgeColor',color); hold on
46 | end
47 | end
48 | end
49 |
50 | end
51 |
52 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/projectModel.m:
--------------------------------------------------------------------------------
1 | function [ regMdlProj ] = projectModel( varargin )
2 |
3 | required = {'model','schParam','slackVars','threshold'};
4 | optional = {};
5 |
6 | calls = varargin(1:2:end);
7 | assert(mod(nargin,2) == 0,'Odd number of arguments.');
8 | assert(iscellstr(calls),'The names of your name/value pairs should be strings.');
9 | assert(~any(~ismember(required,calls)),['These arguments are required: ' strjoin(required)]);
10 | for i = 1:nargin/2
11 | if strcmp(varargin{2*i-1},'model'); assert(~exist('model','var'),'You cannot define model twice.'); model = varargin{2*i}; end;
12 | if strcmp(varargin{2*i-1},'schParam'); assert(~exist('schParam','var'),'You cannot define schParam twice.'); schParam = varargin{2*i}; end;
13 | if strcmp(varargin{2*i-1},'slackVars'); assert(~exist('slackVars','var'),'You cannot define griddedFRFs twice.'); slackVars = varargin{2*i}; end;
14 | if strcmp(varargin{2*i-1},'threshold'); assert(~exist('threshold','var'),'You cannot define globalData twice.'); threshold = varargin{2*i}; end;
15 | if ~ismember(varargin{2*i-1},[required, optional]); warning(['I could not identify the option ''' varargin{2*i-1} ''' and I am going to ignore it.']); end;
16 | end
17 |
18 | oldKnots = model.A.basis.knots;
19 | filter = [boolean(ones(1, model.A.basis.degree + 1)), (slackVars' > threshold), boolean(ones(1, model.A.basis.degree + 1))]';
20 | newKnots = oldKnots(filter);
21 | T = [model.A model.B; model.C model.D];
22 | basisNew = BSplineBasis(newKnots, T.basis.degree);
23 | Tnew = project_to(T, basisNew);
24 |
25 | Aproj = slice(Tnew,1:model.A.size(1),1:model.A.size(2));
26 | Bproj = slice(Tnew,1:model.B.size(1),model.A.size(2)+1:model.A.size(2)+model.B.size(2));
27 | Cproj = slice(Tnew,model.A.size(1)+1:model.A.size(1)+model.C.size(1),1:model.C.size(2));
28 | Dproj = slice(Tnew,model.A.size(1)+1:model.A.size(1)+model.D.size(1),model.C.size(2)+1:model.C.size(2)+model.D.size(2));
29 | regMdlProj = SSmod(Aproj,Bproj,Cproj,Dproj,schParam,model.Ts);
30 |
31 | end
32 |
33 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LPV_identification/simLPV.m:
--------------------------------------------------------------------------------
1 | function [ y ] = simLPV( A,B,C,D,u,x0 )
2 |
3 | % n -> model order, nu -> nr of inputs, ny -> nr of outputs, N -> nr of data samples
4 | % size(A) = N n n, size(B) = N n nu, size(C) = N ny n, size(D) = N ny nu, size(u) = N nu 1, size(x0) = n 1
5 | % for codegen:
6 | % cfg = coder.config('mex');
7 | % cfg.DynamicMemoryAllocation = 'AllVariableSizeArrays';
8 | % codegen -config cfg simLPV -args { zeros(size(A)), zeros(size(B)), zeros(size(C)), zeros(size(D)), zeros(size(u)), zeros(size(x0)) }
9 | x = x0;
10 | y = zeros(size(u,1),size(C,2),1);
11 | for t = 1:size(u,1)
12 | y(t,:,:) = reshape(C(t,:,:),[size(C,2) size(C,3)])*x + reshape(D(t,:,:),[size(D,2) size(D,3)])*reshape(u(t,:,:),[size(u,2) size(u,3)]);
13 | x = reshape(A(t,:,:),[size(A,2) size(A,3)])*x + reshape(B(t,:,:),[size(B,2) size(B,3)])*reshape(u(t,:,:),[size(u,2) size(u,3)]);
14 | end
15 |
16 | end
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/BA_construct.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [Bn,An]=BA_construct(y,nh,nl,M_mh,M_ml)
18 |
19 | M_ml = M_ml(:);
20 | M_mh = M_mh(:);
21 |
22 | nino=length(M_ml(:));
23 |
24 | maxB = max([M_mh;nh]);
25 |
26 | % storing the solution in matrices An and Bn
27 | An = [1 y(1:nh-nl)' zeros(1,nl)];
28 | Bn = zeros(nino,maxB+1);
29 | index_count = nh-nl+1;
30 | for (i=1:nino)
31 | yy = y(index_count:index_count + M_mh(i)-M_ml(i))';
32 | % Bn(i,maxB-M_mh(i):maxB-M_ml(i))=yy;
33 | Bn(i,maxB+1-M_mh(i):maxB+1-M_ml(i))=yy;
34 |
35 | index_count = index_count + M_mh(i)-M_ml(i) + 1;
36 | end;
37 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/crest2.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [cf,cferr]=crest2(X,N,Fe)
18 | % CREST2 Compute the crest factors (Kr').
19 | % Use cf=crest2(X,N,Fe) with
20 | % Input argument :
21 | % - X : Matrix containing the Fourier coefficients of signals
22 | % column by column
23 | % - N : Number of time samples to be used
24 | % - Fe : Set of the effective harmonic numbers
25 | % Output argument :
26 | % - cf : Matrix containing two row vector with the lower and
27 | % upper crest factor values
28 | % See also CREST1, SCHROEDER.
29 | %
30 | % P.A.N. Guillaume - version 1 / 17 November 1990
31 | % Copyright (c) 1990 by dept. ELEC, V.U.B.
32 | %
33 | % Reference : The calculation of the error on the crest factor
34 | % approximation is based on the inequality of Berstein.
35 | % See : Approximation of Functions, G.G. Lorentz, p. 39.
36 | %
37 | if nargin<3
38 | if nargin<2, x=four2ti(X); else x=four2ti(X,N); end
39 | cf=lnorm(x,inf)./effval(X);
40 | else
41 | if isempty(N), x=four2ti(X); else x=four2ti(X,N); end
42 | cf=lnorm(x,inf)./effval(X,Fe);
43 | end
44 | if nargin<2, [N,colno]=size(x); end
45 | [rowno,colno]=size(X);
46 | if colno==1, dummy=X; else dummy=max(abs(X)')'; end
47 | Ft=cumsum(ones(size(dummy)));
48 | Ft=Ft(dummy>max(dummy)*1e-6);
49 | clear dummy
50 | if nargin<3, Fe=Ft; end
51 | kmax=max(max(Ft))-1;
52 | if N>pi*kmax
53 | cferr=cf/(1-pi*kmax/N);
54 | end
55 |
56 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/effval.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function eff=effval(X,Fe)
18 | %EFFVAL Calculate the effective value of all the column vectors
19 | % present in the matrix X (Fourier coefficients).
20 | %
21 | % P.A.N. Guillaume - version 1 / 19 November 1990
22 | % Copyright (c) 1990 by dept. ELEC, V.U.B.
23 | %
24 | X(1,:)=sqrt(2)*X(1,:); % Correction for the DC-component
25 | if nargin==2, X=X(Fe(:),:); end
26 | eff=sqrt(sum(abs(X).^2)/2);
27 |
28 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/four2ti.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function x=four2ti(X,N)
18 | %FOUR2TI Compute the time domain signals from the Fourier
19 | % serie coefficients.
20 | % Use x=four2ti(X,N) with
21 | % Input arguments :
22 | % - X : Matrix containing the Fourier coefficients of
23 | % the different signals column by column
24 | % - N : Number of required time samples
25 | % Output argument :
26 | % - x : Matrix containing the time signals
27 | % See also TIME2FO.
28 | %
29 | % P.A.N. Guillaume - version 1 / 17 November 1990
30 | % Copyright (c) 1990 by dept. ELEC, V.U.B.
31 | %
32 | if nargin==1
33 | [rowno,colno]=size(X);
34 | Ndummy=rowno*2;
35 | N=2;
36 | while Ndummy>N, N=N*2; end
37 | end
38 | x=N*real(ifft(X,N));
39 |
40 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/lnorm.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function Lp=lnorm(A,p)
18 | %LNORM Calculate the vector Lp-norm of all the column vectors
19 | % present in the matrix A.
20 | % See also NORM.
21 | %
22 | % P.A.N. Guillaume - version 1 / 18 November 1990
23 | % Copyright (c) 1990 by dept. ELEC, V.U.B.
24 | %
25 | if nargin==1, p=2; end
26 | [rowno,colno]=size(A);
27 | for i=1:colno, Lp(i)=norm(A(:,i),p); end
28 | if p~=inf, Lp=Lp/(rowno^(1/p)); end
29 |
30 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/merge2frfs.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [ mergedFRF ] = merge2frfs( FDmeas1, FDmeas2 )
18 |
19 | assert(nargin == 2, 'Incorrect number of input arguments.')
20 | Gnonp = [FDmeas1.Response; FDmeas2.Response];
21 | [freq, indFreq] = sort([FDmeas1.Frequency; FDmeas2.Frequency]);
22 | [freqUniq, indFreqUniq] = unique(freq);
23 | Gnonp = Gnonp(indFreq(indFreqUniq));
24 | mergedFRF = struct('Frequency',freqUniq,'Response',Gnonp);
25 |
26 | end
27 |
28 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/mlfdi_res.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function cost = mlfdi_res(Bn,An,freq,X,Y,sX2,sY2,cXY,cORd,fs)
18 | %
19 | % cost = mlfdi_res(Bn,An,freq,X,Y,sX2,sY2,cXY,cORd,fs)
20 | %
21 |
22 | j=sqrt(-1);
23 | freq=freq(:);
24 | N=length(freq);
25 | [x,n]=size(An);
26 | n=n-1;
27 |
28 | % calculation of the frequency axis
29 | if (cORd == 'c')
30 | waxis = j*2*pi*freq;
31 | elseif (cORd == 'd')
32 | waxis = exp(j*2*pi*freq/fs);
33 | else
34 | disp('time domain is undefined; it is set to continuous time');
35 | cORd = 'c';
36 | waxis = j*2*pi*freq;
37 | end;
38 |
39 |
40 | % matrices P and Q are used to form the complex set of equations
41 | P = kron(ones(1,n+1),waxis).^kron(ones(N,1),(n:-1:0));
42 |
43 | Num = P*Bn';
44 | Den = P*An';
45 | SE = sqrt(sX2.*(abs(Num).^2) + sY2.*(abs(Den).^2) - 2*real(cXY.*Den.*conj(Num)) );
46 | E = (Num.*X - Den.*Y)./SE;
47 |
48 | cost = (norm(E)^2)/2;
49 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/randph.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function X=randph(X)
18 | %RANDPH random generation of phase between -pi and +pi.
19 | % Use X=randph(X) with
20 | % Input argument :
21 | % - X : abs(X) is a matrix containing the ampl. spectrum of the
22 | % different signals column by column.
23 | % Output argument :
24 | % - X : Matrix containing the spectrum with random phases
25 | % phase.n = phase.1 - 2p.[S{k=1,n-1} (n-k)Ak^2].
26 | %
27 | ampl=abs(X);
28 | [freqno,signo]=size(ampl);
29 | %rand('uniform');
30 | rand('seed',sum(100*clock));
31 | phase = (2*rand(size(ampl))-1)*pi;
32 | X=ampl.*exp(j*phase);
33 |
34 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/schroed.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function X=schroed(X)
18 | %SCHROED Schroeder phase coding to obtain low crest factors.
19 | % Use X=schroed(X) with
20 | % Input argument :
21 | % - X : abs(X) is a matrix containing the ampl. spectrum of the
22 | % different signals column by column.
23 | % Output argument :
24 | % - X : Matrix containing the spectrum with shroeder phases
25 | % phase.n = phase.1 - 2p.[S{k=1,n-1} (n-k)Ak^2].
26 | % See also CREST1, CREST2, CFMINIMAX.
27 | %
28 | % P.A.N. Guillaume - version 1 / 19 May 1990
29 | % Copyright (c) 1990 by dept. ELEC, V.U.B.
30 | %
31 | ampl=abs(X);
32 | [freqno,signo]=size(ampl);
33 | phase=zeros(size(ampl));
34 | amplnorm=ampl./(ones(size(freqno,1))*sqrt(sum(ampl.^2)));
35 | amplnorm=2*pi*amplnorm.^2;
36 | for i=3:freqno,
37 | phase(i,:)=phase(i-1,:)-sum(amplnorm(1:i-1,:));
38 | end
39 | X=ampl.*exp(j*phase);
40 |
41 |
--------------------------------------------------------------------------------
/3rdparty/LCT_LTI_identification/time2fo.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function X=time2fo(x,N)
18 | %TIME2FO Compute the Fourier serie coefficients from
19 | % the time domain signals.
20 | % Use X=time2fo(x,N) with
21 | % Input arguments :
22 | % - x : Matrix containing the time signals
23 | % - N : Number of required time samples
24 | % Output argument :
25 | % - X : Matrix containing the Fourier coefficients of
26 | % the different signals column by column
27 | % See also FOUR2TI.
28 | %
29 | % P.A.N. Guillaume - version 1 / 18 November 1990
30 | % Copyright (c) 1990 by dept. ELEC, V.U.B.
31 | %
32 | if nargin==1
33 | [rowno,colno]=size(x);
34 | Ndummy=rowno;
35 | N=2;
36 | while Ndummy>N, N=N*2; end
37 | end
38 | X=fft(x,N);
39 | X=[X(1,:);2*X(2:floor(N/2),:)]/N;
40 |
41 |
--------------------------------------------------------------------------------
/3rdparty/LCT_MECOtools/exportBallscrewData.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function exportBallscrewData(TimeSignal)
18 | %EXPORTBALLSCREWDATA Exports TimeSignal into a text file which can be
19 | %parsed by the ball screw interface.
20 |
21 | [time,val] = signal(TimeSignal);
22 | data = [time, val];
23 |
24 | [file,path] = uiputfile('inputdata.txt','Export data for ball screw set-up');
25 | path = fullfile(path, file);
26 |
27 | dlmwrite(path,data,'delimiter','\t');
28 |
29 | % !! You should make sure yourself that you assign the right reference
30 | % values to the right control input for identification !!
31 |
32 | end
--------------------------------------------------------------------------------
/3rdparty/LCT_MECOtools/importBallscrewData.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function meas = importBallscrewData(label, path, inputSignal, varargin)
18 | %IMPORTBALLSCREWDATA Imports data in NetCDF format and casts it into a
19 | %MeasurementData object.
20 |
21 | if ~isa(label,'char') || ~isa(path,'char')
22 | error('You provided wrong input arguments: both the label and the path should be strings.');
23 | else if ~isa(inputSignal,'TimeSignal')
24 | error('Your input signal must be a TimeSignal object.');
25 | end
26 | end
27 |
28 | info = '';
29 | if nargin > 3
30 | if ~isa(varargin{1},'char'); error('Additional information should be provided in string format.'); end;
31 | info = varargin{1};
32 | else if nargin > 4
33 | error('Too many input arguments.');
34 | end
35 | end
36 |
37 | refTorque = ncread(path,'controller.ControlValues.0');
38 | refVMotor = ncread(path,'controller.ControlValues.2');
39 | refXMotor = ncread(path,'controller.ControlValues.1');
40 | measTorque = ncread(path,'plant.Measurements.2');
41 | measXLoad = ncread(path,'plant.Measurements.3');
42 | measXMotor = ncread(path,'plant.Measurements.1');
43 | measALoad = ncread(path,'plant.Measurements.4');
44 |
45 | timeStamp = ncread(path,'TimeStamp');
46 |
47 | try
48 | file = dir(path);
49 | experimentDate = file.date;
50 | catch
51 | path = which(path);
52 | file = dir(path);
53 | experimentDate = file.date;
54 | end
55 |
56 | % we assume we work in torque mode
57 | meas = MeasurementData(label,inputSignal,[timeStamp refTorque measXMotor measXLoad measALoad],{'time','refTorque','measXMotor','measXLoad','measALoad'},experimentDate,info);
58 |
59 | end
60 |
61 |
--------------------------------------------------------------------------------
/3rdparty/LCT_MECOtools/importQRC.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [ out ] = importQRC( in )
18 |
19 | % Parse the file
20 | % ==============
21 | if ischar(in)
22 | rec = readlog(in);
23 | else
24 | rec = in;
25 | end
26 |
27 | e = in.excitation;
28 | if strcmp(e.type,'multisine')
29 | inputSignal = Multisine('label','multisine','fs',e.fs,'fwindow',[e.fmin,e.fmax],'ppp',e.period*e.fs);
30 | else
31 | inputSignal = Multisine('label','multisine','fs',e.fs,'fwindow',[e.fmin,e.fmax],'ppp',e.period*e.fs,'type','odd');
32 | end
33 |
34 | date = sprintf('%i-%i-%i_%i-%i',rec.time.year,rec.time.month,rec.time.day,rec.time.hour,rec.time.minute);
35 |
36 | out = TDMeasurementData('label',rec.file,'excitation',inputSignal,'data',rec.data,'datalabels',rec.labels,'date',date,'info',rec.comment,'periodic',true);
37 | end
38 |
--------------------------------------------------------------------------------
/3rdparty/LCT_MixSynMIMO_LPV/helpers/build_derivative.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [ dPdt ] = build_derivative(P,varargin)
18 | % This function computes the derivative of any B-spline function and
19 | % returns zeros if the variable is constant and returns rate dependent
20 | % function in case of varying variable.
21 | n = size(P,1);
22 | dPdt = zeros(n);
23 | if (nargin == 2)
24 | param = varargin{1};
25 | for i = 1:length(param)
26 | if ~(all(param{i}.rate == 0)) && ~any(isinf(param{i}.rate)) % if rate is not zero or unbounded, take derivative
27 | p = SchedulingParameter(strcat(param{i}.tensor_basis.arguments,'dot'),param{i}.rate,0);
28 | dPdt = dPdt + P.derivative(1,param{i}.tensor_basis.arguments)*p;
29 | end
30 | end
31 | end
32 | end
33 |
34 |
--------------------------------------------------------------------------------
/3rdparty/LCT_MixSynMIMO_LPV/helpers/controller_recon_cL.m:
--------------------------------------------------------------------------------
1 | function [Ak,Bk,Ck,Dk] = controller_recon_cL(A,Bu,Cy,Xe,Ye,Ac_hat,Bc_hat,Cc_hat,Dc_hat,param)
2 | % Dimensions
3 | for i = 1:length(param)
4 | arr(i) = mean(param{i}.range);
5 | end
6 | X = Xe.eval(arr);
7 | Y = Ye.eval(arr);
8 |
9 | nx = size(A,1); nu = size(Bu,2); ny = size(Cy,1);
10 |
11 | % Apply singular value decomposition
12 | [Left,D1,Right] = svd(eye(size(X,1))-X*Y);
13 | M = Left*sqrt(D1); N = Right*sqrt(D1);
14 |
15 | % Transformation
16 | Dk = Dc_hat;
17 | Ck = (Cc_hat-Dk*Cy*X)*pinv(M');
18 | Bk = pinv(N)*(Bc_hat - Y*Bu*Dk);
19 | Ak = pinv(N)*(Ac_hat - N*Bk*Cy*X - Y*Bu*Ck*M' - Y*(A + Bu*Dk*Cy)*X)*pinv(M');
20 | % Extract controller state-space matrices
21 | % Ak = K(1:nx , 1:nx); Bk = K(1:nx , nx+1:end);
22 | % Ck = K(nx+1:end, 1:nx); Dk = K(nx+1:end, nx+1:end);
23 | end
--------------------------------------------------------------------------------
/3rdparty/LCT_MixSynMIMO_LPV/obsolete/build_grid.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [grid,args] = build_grid(param,N)
18 |
19 | if nargin == 1
20 | N = 5*ones(1,length(param)); % default grid
21 | end
22 | if isscalar(N)
23 | N = N*ones(1,length(param)); % same #grid points in each coordinate
24 | end
25 | for k = 1:length(param)
26 | grid{k} = linspace(param{k}.basis.domain.min,param{k}.basis.domain.max,N(k));
27 | args{k} = param{k}.tensor_basis.arguments;
28 | end
29 |
30 | end
--------------------------------------------------------------------------------
/3rdparty/LCT_MixSynMIMO_LPV/obsolete/build_indices_grid.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function index_list = build_indices_grid(grid)
18 |
19 | % build index list for grid
20 | for k = 1:length(grid)
21 | varargin{k} = 1:length(grid{k});
22 | end
23 | index_list = num2cell(combvec(varargin{:})');
24 |
--------------------------------------------------------------------------------
/3rdparty/LCT_MixSynMIMO_LPV/obsolete/compute_Bode_grid.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function compute_Bode_grid(sys,param,N)
18 |
19 | [grid,args] = build_grid(param,N); % parameter grid
20 | index_list = build_indices_grid(grid); % index list grid
21 | M = sys.M.grid_eval(grid,args); % gridded system matrix
22 | figure; % draw bode plots
23 | for k = 1:size(index_list,1)
24 | bode(LFTmod(squeeze(M(index_list{k,:},:,:)),sys.Nu,sys.Nl,eye(sys.nx))); hold on
25 | end
26 |
27 | end
--------------------------------------------------------------------------------
/3rdparty/LCT_MixSynMIMO_LPV/obsolete/compute_norm_grid.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function grid_norm = compute_norm_grid(sys,ny,nu,param,N,opts,norm)
18 |
19 | grid_sys = grid_system(sys,param,N); % gridded system
20 | grid = build_grid(param,N); % parameter grid
21 | index_list = build_indices_grid(grid); % index list grid
22 | for k = 1:size(index_list,1)
23 | sys_loc.A = squeeze(grid_sys.A(index_list{k,:},:,:));
24 | sys_loc.B = squeeze(grid_sys.B(index_list{k,:},:,:));
25 | sys_loc.C = squeeze(grid_sys.C(index_list{k,:},:,:));
26 | sys_loc.D = squeeze(grid_sys.D(index_list{k,:},:,:));
27 | G = extract_generalized_plant(sys_loc,nu,ny);
28 | if norm == inf
29 | Info = compute_FO_Hinf_LTI(G.A,G.Bw,G.Bu,G.Cz,G.Cy,G.Dzw,G.Dzu,G.Dyw,G.Dyu,opts);
30 | grid_norm(index_list{k,:}) = Info.gam;
31 | elseif norm == 2
32 | error('gridded H2 norm not yet supported')
33 | else
34 | error('select Hinf or H2 norm');
35 | end
36 | end
37 |
38 | end
--------------------------------------------------------------------------------
/3rdparty/LCT_MixSynMIMO_LPV/obsolete/grid_system.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function grid_sys = grid_system(sys,param,N)
18 |
19 | [grid,args] = build_grid(param,N); % parameter grid
20 | index_list = build_indices_grid(grid); % index list grid
21 |
22 | % grid system
23 | if isa(sys.A,'splines.Function')
24 | grid_sys.A = sys.A.grid_eval(grid,args);
25 | else
26 | for k = 1:size(index_list,1)
27 | grid_sys.A(index_list{k,:},:,:) = sys.A;
28 | end
29 | end
30 | if isa(sys.B,'splines.Function')
31 | grid_sys.B = sys.B.grid_eval(grid,args);
32 | else
33 | for k = 1:size(index_list,1)
34 | grid_sys.B(index_list{k,:},:,:) = sys.B;
35 | end
36 | end
37 | if isa(sys.C,'splines.Function')
38 | grid_sys.C = sys.C.grid_eval(grid,args);
39 | else
40 | for k = 1:size(index_list,1)
41 | grid_sys.C(index_list{k,:},:,:) = sys.C;
42 | end
43 | end
44 | if isa(sys.D,'splines.Function')
45 | grid_sys.D = sys.D.grid_eval(grid,args);
46 | else
47 | for k = 1:size(index_list,1)
48 | grid_sys.D(index_list{k,:},:,:) = sys.D;
49 | end
50 | end
51 |
52 | end
53 |
--------------------------------------------------------------------------------
/3rdparty/LCT_MixSynMIMO_LPV/obsolete/plot_bound.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function plot_bound(f,param,N)
18 |
19 | [grid,args] = build_grid(param,N);
20 | if isa(f,'splines.Function')
21 | f = f.grid_eval(grid,args);
22 | end
23 | if length(grid) == 1
24 | xlabel(args{1}); ylabel('bound');
25 | plot(grid{1},f);
26 | elseif length(grid) == 2
27 | xlabel(args{1}); ylabel(args{2}); zlabel('bound');
28 | surf(grid{1},grid{2},f');
29 | else
30 | error('plotting works only for functions depending on 1 or 2 variables')
31 | end
32 |
33 | end
34 |
--------------------------------------------------------------------------------
/3rdparty/LCT_MixedHinfsynMIMO_unstab/unstabpant_test.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | clear all
18 | close all
19 | clc
20 | %%
21 | addpath(genpath('../../lti_toolbox'))
22 | %% build plant
23 |
24 | Gmod = TFmod(20,conv([1 25],[1 -35]))
25 |
26 | % Weights
27 | WS = tf([1],[1 0]);
28 | MS = Weight.DC(8);
29 | WU = Weight.DC(60);
30 |
31 |
32 | %% Solve control problem
33 | G = IOSystem(Gmod);
34 | K = IOSystem(1,1);
35 | r = Signal()
36 | u = G.in;
37 | y = G.out;
38 | e = r - y;
39 |
40 | connections = [K.in == e; K.out == u];
41 | P = IOSystem(G,K,connections);
42 |
43 | S = Channel(e/r,'Sensitivity');
44 | U = Channel(u/r,'Actuator\_Effort');
45 |
46 | obj = WS*S;
47 | constr = [MS*S<=1,WU*U<=1];
48 | [P,C,info] = P.solve(obj,constr,K);
49 |
50 | figure, bodemag(info)
--------------------------------------------------------------------------------
/3rdparty/LCT_mixedHinflmitlab_MIMO/mixedHinflmilab.m:
--------------------------------------------------------------------------------
1 | function [ K, sol_info ] = mixedHinflmilab( sys, ny, nu, alpha, channel)
2 |
3 | gen_sys = extract_generalized_plant(sys,nu,ny);
4 |
5 | n_pspecs = length(channel); %number of performance specs
6 | A = gen_sys.A; nx = gen_sys.nx; Bu = gen_sys.Bu; Cy = gen_sys.Cy;
7 | [Bw,Cz,Dzw,Dzu,Dyw] = deal(cell(1,n_pspecs));
8 | [nw,nz] = deal(zeros(1,n_pspecs));
9 |
10 | for j = 1:n_pspecs
11 | Bw{j} = gen_sys.Bw(:,channel(j).In);
12 | Cz{j} = gen_sys.Cz(channel(j).Out,:);
13 | Dzw{j} = gen_sys.Dzw(channel(j).Out,channel(j).In);
14 | Dzu{j} = gen_sys.Dzu(channel(j).Out,:);
15 | Dyw{j} = gen_sys.Dyw(:,channel(j).In);
16 | nw(j) = size(Bw{j},2);
17 | nz(j) = size(Cz{j},1);
18 | end
19 |
20 | setlmis([]);
21 |
22 | X = lmivar(1,[nx,1]);
23 | Y = lmivar(1,[nx,1]);
24 |
25 | Ac_hat = lmivar(2,[nx nx]);
26 | Bc_hat = lmivar(2,[nx ny]);
27 | Cc_hat = lmivar(2,[nu nx]);
28 |
29 | for j = 1:n_pspecs
30 | gam2{j} = lmivar(2,[1 1]);
31 | end
32 |
33 | Q = newlmi;
34 | lmiterm([Q,1,1,X],1,1);
35 | lmiterm([Q,1,2,0],eye(nx));
36 | lmiterm([Q,2,2,Y],1,1);
37 |
38 | for j = 1:n_pspecs
39 | Term{j} = newlmi;
40 | lmiterm([Term{j},1,1,X],A,1,'s');
41 | lmiterm([Term{j},1,1,Cc_hat],Bu,1,'s');
42 | lmiterm([Term{j},1,2,Ac_hat],1,1);
43 | lmiterm([Term{j},1,2,0],A);
44 | lmiterm([Term{j},2,2,Y],1,A,'s');
45 | lmiterm([Term{j},2,2,Bc_hat],1,Cy,'s');
46 | lmiterm([Term{j},1,3,0],Bw{j});
47 | lmiterm([Term{j},3,3,0],-eye(nw(j)));
48 | lmiterm([Term{j},1,4,X],1,Cz{j}');
49 | %lmiterm([Term{j},1,4,Cc_hat],Dzu{j}',1);
50 | lmiterm([Term{j},2,4,0],Cz{j}');
51 | lmiterm([Term{j},3,4,0],Dzw{j});
52 | lmiterm([Term{j},4,4,gam2{j}],-1,eye(nz(j)));
53 |
54 | end
55 | LMIs = getlmis;
56 | c = zeros(decnbr(LMIs),1);
57 |
58 | for j = 1:n_pspecs
59 | G{j} = decinfo(LMIs,gam2{j});
60 | f = G{j};
61 | c(f(f~=0)) = alpha((f~=0));
62 | end
63 | [fopt,xopt] = mincx(LMIs,c);
64 | LMIsopt = evallmi(LMIs,xopt);
65 |
66 | K = 0;
67 |
68 |
69 | end
70 |
71 |
--------------------------------------------------------------------------------
/Examples/Standalone/BLUX2016/BLUX2016_main.m:
--------------------------------------------------------------------------------
1 | clear all
2 | close all
3 | clc
4 |
5 | %%
6 | % Example for the BENELUX MEETING ON SYSTEMS AND CONTROL 2016
7 | % This example describes the controller design for the absolute position of
8 | % the load of an overhead crane. It will demonstrate analysis with a
9 | % prefixed proportional controller. This is followed by some optimal
10 | % feedback controller design and some trade-off analysis on tracking vs
11 | % disturbance rejection.
12 |
13 | %% 1. System definition
14 | g = 9.81; %[m/s/s]
15 | l = 0.6; %[m]
16 | z = 1e-3;%[-] damping of the pendulum
17 |
18 | % G is a 2x1 lti system with as input the cart velocity and as output the
19 | % angle and the cart position.
20 | Gm = TFmod({[1 0];[1]},{[l 2*sqrt(g*l)*z g];[1 0]});
21 | G = IOSystem(Gm);
22 |
23 | % C0 is a simple proportional controller to check the performance
24 | C0 = TFmod(100,1);
25 | C0.name = 'proportional';
26 | K = IOSystem(C0);
27 |
28 | % Define some weights corresponding to what we want to achieve
29 | WS = Weight.LF(0.4,1);
30 | MS = Weight.DC(4);
31 | WT = Weight.HF(5,1);
32 | WD = Weight.DC(35);
33 |
34 | %% 2. LTI toolbox
35 | % Define variables to do the eventual controller design
36 | r = Signal();
37 | u = G.in;
38 |
39 | % compute the relative position from the angle
40 | theta = G.out(1);
41 | xr = l*theta;
42 |
43 | % compute the absolute position from xr and x0
44 | x0 = G.out(2);
45 | x = xr + x0;
46 |
47 | % define the error on the absolute position
48 | e = r - x;
49 |
50 | % define the connections
51 | conn1 = [K.in == e]; % Assign the error to the controller input
52 | conn2 = [K.out == u]; % Assign the plant input to the controller output
53 |
54 | % construct the closed loop system
55 | P = IOSystem(G,K,[conn1;conn2]);
56 |
57 | % Do the controller design
58 | S = Channel(e/r,'Sensitivity');
59 | U = Channel(u/r,'Input Sensitivity');
60 | T = Channel(x/r,'Complementary Sensitivity');
61 | D = Channel(theta/r,'Disturbance Rejection');
62 |
63 | obj1 = WS*S;
64 | constr1 = [MS*S <= 1, WT*T <= 1];
65 | opts.gammasolver = 'mosek';
66 | opts.controller_name = 'tracking';
67 | [P,C1,info1] = P.solve(obj1,constr1,K,opts);
68 |
69 | obj2 = WS*S;
70 | constr2 = [WD*D <= 1, WT*T <= 1];
71 | opts.controller_name = 'disturbance';
72 | [P,C2,info2] = P.solve(obj2,constr2,K,opts);
73 |
74 | figure, bodemag(info1,info2,S,U,T,D);
75 | figure, step(P([x;theta;x0],r));
76 |
--------------------------------------------------------------------------------
/Examples/Standalone/Ballbot/ballbot.m:
--------------------------------------------------------------------------------
1 | clear all
2 | close all
3 | clc
4 |
5 | %% Controller design for a ball balancing robot - attitude loop
6 | % The zero in zero in the attitude loop is cancelled by the PI controller
7 | % which acts as a prefilter to the designed controller.
8 |
9 | % Declare model
10 | Gm = ZPKmod(0,[-0.9,0.9],4e-3);
11 | PIm = ZPKmod(-5,0,1);
12 |
13 | G = IOSystem(Gm);
14 | PI = IOSystem(PIm);
15 | K = IOSystem(1,1);
16 |
17 | th_ref = Signal();
18 | u = G.in;
19 | th = G.out;
20 | e = th_ref - th;
21 |
22 | connections = [K.in == e; K.out == PI.in; PI.out == u];
23 | P = IOSystem(G,PI,K,connections);
24 |
25 | % Declare shape functions ad channels
26 | WS = Weight.LF(2,1,-10);
27 | MS = Weight.DC(6);
28 | WU = Weight.HF(10,1,-30)*1e-3;
29 |
30 | S = Channel(e/th_ref,'Sensitivity');
31 | U = Channel(u/th_ref,'Input Sensitivity');
32 | T = Channel(th/th_ref,'Compl. Sensitivity')
33 |
34 | % Specify the optimal controller design problem
35 | obj = WU*U;
36 | constr = [MS*S <= 1, WS*S <= 1];
37 | [P,C,info] = P.solve(obj,constr,K);
38 | figure, bodemag(info,S,U,T)
39 |
40 | % Clean up the controller and plot the results
41 | C = removehigh(ssminreal(C),1e3);
42 | C.name = 'clean';
43 | K.add(C)
44 | figure, bode(K.content(1)*PIm,K.content(2)*PIm)
45 |
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/measurements/meas1.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/measurements/meas1.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/measurements/meas2.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/measurements/meas2.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/measurements/meas3.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/measurements/meas3.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/measurements/meas4.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/measurements/meas4.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/measurements/meas5.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/measurements/meas5.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/multisines/musin1.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/multisines/musin1.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/multisines/musin2.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/multisines/musin2.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/multisines/musin3.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/multisines/musin3.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/multisines/musin4.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/multisines/musin4.mat
--------------------------------------------------------------------------------
/Examples/Standalone/Crane_LTI/multisines/musin5.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/Crane_LTI/multisines/musin5.mat
--------------------------------------------------------------------------------
/Examples/Standalone/ECC2016/ecc_2016_hifoo.m:
--------------------------------------------------------------------------------
1 | function [K,CL,time] = ecc_2016_hifoo(G,WS,MS,WT,new)
2 | %ECC_2016_LTI_MIXEDHINFSYNMIMO Summary of this function goes here
3 | % Detailed explanation goes here
4 |
5 | options.output = struct('controller',0,'performance',1,'closedloop',0,'displaystyle','normal')
6 |
7 | G = LTIsys(G);
8 | WS = LTIsys(WS);
9 | MS = LTIsys(MS);
10 | WT = LTIsys(WT);
11 |
12 | lti_begin(options)
13 | % Define the exogeneous input r
14 | signal r
15 |
16 | % Define the connections
17 | u = G.in; % Control input
18 | y = G.out; % Control output
19 | e = r - y(1); % tracking error
20 |
21 | % Define the control problems
22 | S = Channel(e/r, 'Sensitivity');
23 | U = Channel(u/r, 'Input sensitivity');
24 | T = Channel(y(1)/r, 'Complementary sensitivity');
25 |
26 | show(S,U,T)
27 |
28 | % ctrl_begin('classic')
29 | % K.in = e; % Controller inputs: reference
30 | % K.out = u; % Controller output
31 | %
32 | % minimize(WS*S)
33 | % subject to
34 | % MS*S <= 1
35 | % WT*T <= 1
36 | % ctrl_end
37 |
38 | options.FullOrderSolver = 'HIFOO';
39 | options.ReducedOrderSolver = 'HIFOO';
40 | ctrl_begin('new',options)
41 | if(new)
42 | K.in = [e;y]; % Controller inputs: reference, y(1), y(2)
43 | else
44 | K.in = [e];
45 | end
46 | K.out = u; % Controller output
47 |
48 | minimize(WS*S)
49 | subject to
50 | MS*S <= 1
51 | WT*T <= 1
52 | if(new)
53 | order = 5;
54 | end
55 | ctrl_end
56 | lti_end
57 |
58 | K = extract('new');
59 | CL = extract([e;y(1)]/r);
60 | time = lti_problem.ctrl_prob(1).solver.info.time;
61 | end
62 |
63 |
--------------------------------------------------------------------------------
/Examples/Standalone/ECC2016/ecc_2016_hinfstruct.m:
--------------------------------------------------------------------------------
1 | function [K,CL,time] = ecc_2016_hinfstruct(G,WS,MS,WT,new)
2 | %ECC_2016_RC_HINFSTRUCT synthetize controller with hinfstruct
3 | % Detailed explanation goes here
4 |
5 | %% Make controller block
6 | Ny = 1;
7 | if(new)
8 | Nx = 5;
9 | Nu = 3;
10 | K = ltiblock.ss('K',Nx,Ny,Nu);
11 | K.u = {'e';'y';'ya'}; K.y = 'u';
12 | else
13 | Nx = 7 + length(pole(WT));
14 | Nu = 1;
15 | K = ltiblock.ss('K',Nx,Ny,Nu);
16 | K.u = 'e'; K.y = 'u';
17 | end
18 |
19 |
20 | %% Make the interconnection
21 | WS.u = 'e'; WS.y = 'z1';
22 | MS.u = 'e'; MS.y = 'z2';
23 | WT.u = 'y'; WT.y = 'z3';
24 | G.u = 'u'; G.y = {'y';'ya'};
25 |
26 | % Specify summing junctions
27 | Sum1 = sumblk('e = r - y');
28 |
29 | % Connect the blocks together
30 | P = connect(G,K,WS,MS,WT,Sum1,{'r'},{'z1','z2','z3'})
31 |
32 | %% synthetize controller
33 | opt = hinfstructOptions('Display','final','RandomStart',5);
34 | tic;
35 | [Ps,gam,info] = hinfstruct(P,opt);
36 | time = toc;
37 | K = getBlockValue(Ps,'K');
38 | if(new)
39 | K.u = {'e';'y';'ya'}; K.y = 'u';
40 | else
41 | K.u = 'e'; K.y = 'u';
42 | end
43 |
44 | CL = connect(G,K,Sum1,{'r'},{'e','y'});
45 | end
46 |
47 |
--------------------------------------------------------------------------------
/Examples/Standalone/ECC2016/ecc_2016_mixedhinfsynmimo.m:
--------------------------------------------------------------------------------
1 | function [K,CL,time] = ecc_2016_mixedhinfsynmimo(G,WS,MS,WT,new)
2 | %ECC_2016_LTI_MIXEDHINFSYNMIMO Summary of this function goes here
3 | % Detailed explanation goes here
4 |
5 | options.output = struct('controller',0,'performance',0,'closedloop',0,'displaystyle','normal');
6 |
7 | G = fromstd(G);
8 |
9 | lti_begin(options)
10 | % Define the exogeneous input r
11 | r = Signal();
12 |
13 | % Define the connections
14 | u = G.in; % Control input
15 | y = G.out; % Control output
16 | e = r - y(1); % tracking error
17 |
18 | % Define the control problems
19 | S = Channel(e/r, 'Sensitivity');
20 | U = Channel(u/r, 'Input sensitivity');
21 | T = Channel(y(1)/r, 'Complementary sensitivity');
22 |
23 | options.FullOrderSolver = 'mixedHinfsynMIMO';
24 | if(new)
25 | options.orderreduction = 'on';
26 | end
27 | ctrl_begin('new',options)
28 | if(new)
29 | K.in = [e;y]; % Controller inputs: reference, y(1), y(2)
30 | else
31 | K.in = [e];
32 | end
33 | K.out = u; % Controller output
34 |
35 | minimize(WS*S)
36 | subject to
37 | MS*S <= 1
38 | WT*T <= 1
39 | ctrl_end
40 | lti_end
41 |
42 | K = extract('new');
43 | CL = extract([e;y(1)]/r);
44 | time = lti_problem.ctrl_prob(1).solver.info.time;
45 | end
46 |
47 |
--------------------------------------------------------------------------------
/Examples/Standalone/ECC2016/ecc_2016_systune.m:
--------------------------------------------------------------------------------
1 | function [K,CL,time] = ecc_2016_systune(G,WS,MS,WT,new)
2 | %ECC_2016_RC_SYSTUNE2 Summary of this function goes here
3 | % Do Hinf controller design with systune
4 |
5 | %% Construct controller block
6 | Ny = 1;
7 | if(new)
8 | Nx = 5;
9 | Nu = 3;
10 | K = ltiblock.ss('K',Nx,Ny,Nu);
11 | K.u = {'e';'y';'ya'}; K.y = 'u';
12 | else
13 | Nx = 7 + length(pole(WT));
14 | Nu = 1;
15 | K = ltiblock.ss('K',Nx,Ny,Nu);
16 | K.u = 'e'; K.y = 'u';
17 | end
18 |
19 | %% Make the interconnection
20 | WS.u = 'e'; WS.y = 'z1';
21 | MS.u = 'e'; MS.y = 'z2';
22 | WT.u = 'y'; WT.y = 'z3';
23 | G.u = 'u'; G.y = {'y';'ya'};
24 |
25 | % Specify summing junctions
26 | Sum1 = sumblk('e = r - y');
27 |
28 | % Connect the blocks together
29 | P = connect(G,K,WS,MS,WT,Sum1,{'r'},{'z1','z2','z3'})
30 |
31 | %% synthetize controller
32 | ReqWS = TuningGoal.Gain('r','z1',1);
33 | ReqMS = TuningGoal.Gain('r','z2',1);
34 | ReqWT = TuningGoal.Gain('r','z3',1);
35 |
36 | systuneOptions('RandomStart',5);
37 | tic;
38 | [CL,fSoft,fHard,info] = systune(P,[ReqWS],[ReqMS;ReqWT]);
39 | time = toc;
40 | K = getBlockValue(CL,'K');
41 | if(new)
42 | K.u = {'e';'y';'ya'}; K.y = 'u';
43 | else
44 | K.u = 'e'; K.y = 'u';
45 | end
46 |
47 | CL = connect(G,K,Sum1,{'r'},{'e','y'});
48 | end
49 |
50 |
--------------------------------------------------------------------------------
/Examples/Standalone/IFAC2017/myODE.m:
--------------------------------------------------------------------------------
1 | function dx = myODE(t,x,sys,p,u)
2 | %MYODE Summary of this function goes here
3 | % Detailed explanation goes here
4 |
5 | pt = p(t);
6 | ut = u(t);
7 | syspt = sys.f({pt});
8 | syspt = std(syspt{1});
9 |
10 | dx = syspt.A*x + syspt.B*ut;
11 | end
12 |
13 |
--------------------------------------------------------------------------------
/Examples/Standalone/IFAC2017/myOutput.m:
--------------------------------------------------------------------------------
1 | function y = myOutput(t,x,sys,p,u)
2 | %MYOUTPUT Summary of this function goes here
3 | % Detailed explanation goes here
4 |
5 | pt = p(t);
6 | ut = u(t);
7 |
8 | syspt = sys.f({pt});
9 | syspt = std(syspt{1});
10 |
11 | y = syspt.C*x + syspt.D*ut;
12 | end
13 |
14 |
--------------------------------------------------------------------------------
/Examples/Standalone/InvertedPendulum/draw_pendulum.m:
--------------------------------------------------------------------------------
1 | function [ax] = draw_pendulum(ax,x,theta,varargin)
2 | %PENDULUM_MOVIE Summary of this function goes here
3 | % Detailed explanation goes here
4 |
5 | if(nargin>3)
6 | l = varargin{1}.l;
7 | wc = varargin{1}.wc;
8 | hc = varargin{1}.hc;
9 | wp = varargin{1}.wp;
10 | hp = varargin{1}.hp;
11 | end
12 |
13 | y0 = 0;
14 | r = hc/4;
15 | N = 100;
16 |
17 | c = linspace(0,2*pi,N)';
18 | Pwheel1 = repmat([x-l/2 y0+r],[N,1]) + [cos(c) sin(c)]*r;
19 | Pwheel2 = repmat([x+l/2 y0+r],[N,1]) + [cos(c) sin(c)]*r;
20 | Pcart = [x-wc/2 y0+r;...
21 | x-wc/2 y0+hc+r;...
22 | x+wc/2 y0+hc+r;...
23 | x+wc/2 y0+r;...
24 | x-wc/2 y0+r];
25 |
26 | a = linspace(0,pi,N)';
27 | Ppendle_upper = repmat([0 hp-wp+r+hc/2],[N,1]) + [-cos(a) sin(a)]*wp/2;
28 | Ppendle_lower = repmat([0 r+hc/2],[N,1]) + [cos(a) -sin(a)]*wp/2;
29 | Ppendle = [-wp/2,r+hc/2;...
30 | -wp/2,hp-wp+r+hc/2;...
31 | Ppendle_upper;...
32 | wp/2,hp-wp+r+hc/2;...
33 | wp/2,r+hc/2;...
34 | Ppendle_lower;...
35 | -wp/2,r+hc/2];
36 |
37 | Rot=[cos(theta) sin(theta);-sin(theta) cos(theta)];
38 | Ppendle = Ppendle*Rot + repmat([x y0],[5+2*N,1]);
39 |
40 | hold(ax,'on');
41 | % plot(ax,Pcart(:,1),Pcart(:,2),'k-','Linewidth',2);
42 | % plot(ax,Pwheel1(:,1),Pwheel1(:,2),'k-','Linewidth',2);
43 | % plot(ax,Pwheel2(:,1),Pwheel2(:,2),'k-','Linewidth',2);
44 | %plot(ax,Ppendle(:,1),Ppendle(:,2),'b-','Linewidth',2);
45 | patch(Pcart(:,1),Pcart(:,2),[139 137 137]/255,'EdgeColor','k','Linewidth',2)
46 | patch(Pwheel1(:,1),Pwheel1(:,2),[139 137 137]/255,'EdgeColor','k','Linewidth',2)
47 | patch(Pwheel2(:,1),Pwheel2(:,2),[139 137 137]/255,'EdgeColor','k','Linewidth',2)
48 | patch(Ppendle(:,1),Ppendle(:,2),[65 105 255]/255,'EdgeColor','b','Linewidth',2);
49 | hold(ax,'off');
50 |
51 | axis(ax,'equal');
52 | if(nargin>4)
53 | axis(ax,varargin{2});
54 | end
55 | % daspect(ax,[1 1 1]);
56 |
57 | end
58 |
59 |
--------------------------------------------------------------------------------
/Examples/Standalone/InvertedPendulum/pendulum_free.m:
--------------------------------------------------------------------------------
1 | clear all
2 | close all
3 | clc
4 |
5 | %% Parameters
6 | M = 0.05;
7 | m = 0.010;
8 | l = 0.025;
9 | g = 9.81;
10 | J = 0;
11 | c = 1e-6;
12 |
13 | timespan = [0,20];
14 |
15 | %% Stable position - down
16 | y0s = [pi,0,0,0];
17 | u = @(t) 1*sin(2*pi*t);
18 | [ts,ys] = ode45(@(t,x) pendulum_model(t,x,u,m,l,g,J,c), timespan, y0s);
19 | us = u(ts);
20 | dys = zeros(size(ys));
21 | for k = 1:length(ts)
22 | dys = pendulum_model(ts(k,1),ys(k,:),u,m,l,g,J,c);
23 | end
24 |
25 | % Linearized model
26 | Gs = ss([0 1;-m*g*l/(J+m*l^2) -c/(J+m*l^2)],[0;-m*l/(J+m*l^2)],[1 0],[0]);
27 | ts_lin = linspace(timespan(1), timespan(2), 2000);
28 | us_lin = u(ts_lin);
29 | [ys_lin] = lsim(Gs,us_lin,ts_lin);
30 | ys_lin = ys_lin+pi;
31 |
32 | % Plotting
33 | figure()
34 | subplot(211)
35 | plot(ts,rad2deg(ys(:,1)),'b-',ts_lin,rad2deg(ys_lin),'r-');
36 | legend('Nonlinear','Linear')
37 | subplot(212)
38 | plot(ts,rad2deg(ys(:,3)),'k-');
39 |
40 | %% Unstable position - up
41 | y0u = [0.001,0,0,0];
42 | u = @(t) 0;
43 | [tu,yu] = ode45(@(t,x) pendulum_model(t,x,u,m,l,g,J,c), timespan, y0u);
44 | dyu = zeros(size(yu));
45 | for k = 1:length(tu)
46 | dyu = pendulum_model(tu(k,1),yu(k,:),u,m,l,g,J,c);
47 | end
48 |
49 | % Linearized model
50 | Gu = ss([0 1;m*g*l/(J+m*l^2) -c/(J+m*l^2)],[0;m*l/(J+m*l^2)],[1 0],[0]);
51 | tu_lin = linspace(timespan(1), timespan(2), 2000);
52 | uu_lin = tu_lin*0;
53 | [yu_lin] = lsim(Gu,uu_lin,tu_lin,[0.001;0]);
54 | yu_lin = yu_lin+pi;
55 |
56 | figure()
57 | subplot(211)
58 | plot(tu,rad2deg(yu(:,1)),'b-',tu_lin,rad2deg(yu_lin),'r-');
59 | legend('Nonlinear','Linear')
60 | subplot(212)
61 | plot(tu,yu(:,3),'k-');
--------------------------------------------------------------------------------
/Examples/Standalone/InvertedPendulum/pendulum_model.m:
--------------------------------------------------------------------------------
1 | function [dx] = pendulum_model(t,x,u,m,l,g,J,c)
2 | %PENDULUM_MODEL Summary of this function goes here
3 | % x = [theta,dtheta,x,dx]
4 |
5 | u = u(t);
6 |
7 | dx(1,1) = x(2);
8 | dx(2,1) = (m*g*l*sin(x(1)) - c*x(2) + m*l*cos(x(1))*u - m*l*sin(x(1))*x(4)*x(2))/(J+m*l^2);
9 | dx(3,1) = x(4);
10 | dx(4,1) = u;
11 |
12 | end
13 |
14 |
--------------------------------------------------------------------------------
/Examples/Standalone/LAB_LSB250/excitations.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/LAB_LSB250/excitations.mat
--------------------------------------------------------------------------------
/Examples/Standalone/LAB_LSB250/exp1.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/LAB_LSB250/exp1.mat
--------------------------------------------------------------------------------
/Examples/Standalone/LAB_LSB250/exp2.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/LAB_LSB250/exp2.mat
--------------------------------------------------------------------------------
/Examples/Standalone/LAB_LSB250/exp3.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/LAB_LSB250/exp3.mat
--------------------------------------------------------------------------------
/Examples/Standalone/LAB_LSB250/exp4.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/LAB_LSB250/exp4.mat
--------------------------------------------------------------------------------
/Examples/Standalone/MBSE/main.m:
--------------------------------------------------------------------------------
1 | clear all; close all; clc;
2 |
3 | data = load('sys.mat');
4 |
5 | Gmodel = fromstd(data.Sd);
6 | Ts = Gmodel.Ts;
7 |
8 | G = IOSystem(d2c(Gmodel)); % Make a system for the plant
9 | K = IOSystem(2,2); % Make a system for the controller
10 |
11 | % Weight to maximize the bandwidth
12 | %WS = c2d(Weight.LF(0.5,1,-40),Ts,'Tustin'); % sensitivity weight
13 |
14 | W1 = Weight.DC(5);
15 |
16 | WS = [Weight.DC(5) Weight.DC(5);Weight.DC(5) Weight.DC(5)];
17 | WT = [Weight.DC(5) Weight.DC(5);Weight.DC(5) Weight.DC(5)];
18 |
19 | % Make the control configuration
20 | r = Signal(2); % reference input
21 | u = G.in; % control input
22 | y = G.out; % measured output
23 | e = r - y; % error on the absolute position
24 |
25 | connections = [K.in == e;K.out == u];
26 | CL = IOSystem(G,K,connections);
27 |
28 | % Controller design
29 | S1 = Channel(e(1)/r(1),'Sensitivity');
30 | T = Channel(y/r,'Compl. Sensitivity');
31 |
32 | % Controller design 1
33 | obj = [W1*S1] %WS*S];
34 | constr = [] %WT*T <= 1];
35 | CL.solve(obj,constr,K);
36 |
37 | % Compute closed loop response
38 | mod = CL.model();
39 |
--------------------------------------------------------------------------------
/Examples/Standalone/MBSE/sys.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/MBSE/sys.mat
--------------------------------------------------------------------------------
/Examples/Standalone/SateliteTracking/SateliteTracking.m:
--------------------------------------------------------------------------------
1 | clear all
2 | close all
3 | clc
4 |
5 | addpath(genpath('../lti_toolbox'));
6 |
7 | %% Satelite Tracking example
8 | % The system describes a controller design for a disc-antenna which is to
9 | % track a satelite oribiting through space. Zero steady-state error under
10 | % constant is disturbances is desirable.
11 | % Furthermore, a bandwidth of 0.1Hz is needed. The remaining freedom should
12 | % be used to minimize the actuation effort, which also makes the controller
13 | % robust to high-frequency noise. In that regard, some roll-off on the
14 | % controller is also desirable
15 |
16 | %% 1.1. Define the system and select some weights
17 | mod1 = TFmod(10,[1 15 50 0]);
18 | %mod2 = FRDmod(mod1,logspace(1e-1,1e2,50),'Hz');
19 |
20 | G = IOSystem(1,1);
21 | G.add(mod1);
22 | K = IOSystem(1,1);
23 | r = Signal();
24 |
25 | e = r - G.out;
26 | u = G.in;
27 | y = G.out;
28 | conn = [K.in == e; K.out == G.in];
29 | CL = IOSystem(G,K,conn);
30 |
31 | WS = Weight.LF(0.1,2,-40);
32 | MS = Weight.DC(4);
33 | MS2 = Weight.DC(8);
34 | WU = Weight.HF(3,1,-40);
35 | WT = Weight.HF(1,3);
36 |
37 | %% 1.2. Design the optimal controller using the lti_toolbox
38 | S = Channel(e/r,'Sensitivity');
39 | U = Channel(u/r,'Input sens.');
40 | T = Channel(y/r,'Compl. sens.');
41 |
42 | [CL,C1,info1] = CL.solve(WT*T,[WS*S <= 1,MS*S <= 1],K);
43 | [CL,C2,info2] = CL.solve(WT*T,[WS*S <= 1,MS2*S <= 1],K);
44 |
45 | figure, bodemag(info1,info2,S,T)
46 |
47 | %% 1.3. Time domain simulation
48 | u = @(t) (t>0);
49 | t = 20;
50 | sim(T(CL),u,t);
51 |
52 | %%
53 | [CL,C3,info3] = CL.solve(WU*U,[WS*S <= 1,MS*S <= 1],K);
--------------------------------------------------------------------------------
/Examples/Standalone/XYtable/identifiedX.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/XYtable/identifiedX.mat
--------------------------------------------------------------------------------
/Examples/Standalone/XYtable_demo/longMeasurement_01508_1.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/XYtable_demo/longMeasurement_01508_1.mat
--------------------------------------------------------------------------------
/Examples/Standalone/XYtable_demo/longMeasurement_01508_3.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/XYtable_demo/longMeasurement_01508_3.mat
--------------------------------------------------------------------------------
/Examples/Standalone/XYtable_demo/longMeasurement_01508_5.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/XYtable_demo/longMeasurement_01508_5.mat
--------------------------------------------------------------------------------
/Examples/Standalone/XYtable_demo/longMeasurement_01508_7.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/XYtable_demo/longMeasurement_01508_7.mat
--------------------------------------------------------------------------------
/Examples/Standalone/XYtable_demo/longMeasurement_01508_9.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/XYtable_demo/longMeasurement_01508_9.mat
--------------------------------------------------------------------------------
/Examples/Standalone/drivetrain/torquecontrol/K.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/drivetrain/torquecontrol/K.png
--------------------------------------------------------------------------------
/Examples/Standalone/drivetrain/torquecontrol/S.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/drivetrain/torquecontrol/S.png
--------------------------------------------------------------------------------
/Examples/Standalone/drivetrain/torquecontrol/T.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/drivetrain/torquecontrol/T.png
--------------------------------------------------------------------------------
/Examples/Standalone/drivetrain/torquecontrol/U.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/drivetrain/torquecontrol/U.png
--------------------------------------------------------------------------------
/Examples/Standalone/drivetrain/torquecontrol/controller.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/meco-group/lc_toolbox/22dbaee3cd680527945e188cde2f105d4bebce86/Examples/Standalone/drivetrain/torquecontrol/controller.zip
--------------------------------------------------------------------------------
/Modules/Control/ControllerDesign.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef ControllerDesign < ControlProblem
18 | %CONTROLLERDESIGN Supports controller design
19 | % Controller design class. Stores a set of constraints and objectives
20 | % and calculates the optimal solution when executed.
21 | % Performances can easily be checked
22 |
23 | properties
24 | method = 'none'; % Solver to use: mixedHinfsyn, compute_FO_mix, compute_RO_mix, none
25 | order = -1; % Don't include order constraint to begin with
26 |
27 | solver = []; % solver object
28 | region = [];
29 | processor = SimpleProcessor();
30 | end
31 |
32 | methods
33 | function obj = ControllerDesign(varargin)
34 | obj@ControlProblem(varargin{:});
35 | obj.options = struct('FullOrderSolver',[],'ReducedOrderSolver',[]);
36 | end
37 | end
38 | end
39 |
40 |
--------------------------------------------------------------------------------
/Modules/Control/Painter/PaintStyleConference.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef PaintStyleConference < PaintStyleInterface
18 | %PAINTSTYLECONFERENCE Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | methods
22 | function self = PaintStyleConference()
23 | % do nothing..
24 | end
25 |
26 | function s = channelstyle(self,index)
27 | colors = 'bgrmy';
28 | s = [colors(index),'-'];
29 | end
30 |
31 | function s = weightstyle(self,index)
32 | s = 'k--';
33 | end
34 |
35 | function s = npfrfstyle(self,index)
36 | s = 'k:';
37 | end
38 |
39 | function s = size(self)
40 | s = [300,600];
41 | end
42 | end
43 |
44 | end
45 |
46 |
--------------------------------------------------------------------------------
/Modules/Control/Painter/PaintStyleInterface.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef PaintStyleInterface
18 | %PAINTSTYLEINTERFACE Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | methods(Abstract)
22 | channelstyle(self,index);
23 | weightstyle(self,index);
24 | npfrfstyle(self,index);
25 | size(self);
26 | end
27 | end
28 |
29 |
--------------------------------------------------------------------------------
/Modules/Control/Painter/PaintStyleNormal.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef PaintStyleNormal
18 | %PAINTSTYLENORMAL Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | methods
22 | function self = PaintStyleNormal()
23 | % do nothing..
24 | end
25 |
26 | function s = channelstyle(self,index)
27 | colors = 'bgrmy';
28 | s = [colors(index),'-'];
29 | end
30 |
31 | function s = weightstyle(self,index)
32 | s = 'k--';
33 | end
34 |
35 | function s = npfrfstyle(self,index)
36 | s = 'k:';
37 | end
38 |
39 | function s = size(self)
40 | s = [600,450];
41 | end
42 | end
43 |
44 | end
45 |
46 |
--------------------------------------------------------------------------------
/Modules/Control/Painter/PaintStylePaperFancy.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef PaintStylePaperFancy < PaintStyleInterface
18 | %PAINTSTYLEPAPERFANCY Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | properties
22 | markers = 'odxs*';
23 | end
24 |
25 | methods
26 | function self = PaintStylePaperPlain()
27 | % do nothing..
28 | end
29 |
30 | function s = channelstyle(self,index)
31 | s = ['b-' self.markers(index)];
32 | end
33 |
34 | function s = weightstyle(self,index)
35 | s = ['k--' self.markers(index)];
36 | end
37 |
38 | function s = npfrfstyle(self,index)
39 | s = 'k:';
40 | end
41 |
42 | function s = size(self)
43 | s = [600,450];
44 | end
45 | end
46 |
47 | end
48 |
49 |
--------------------------------------------------------------------------------
/Modules/Control/Painter/PaintStylePaperPlain.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef PaintStylePaperPlain
18 | %PAINTSTYLEPAPERPLAIN Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | properties
22 | markers = 'odxs*';
23 | end
24 |
25 | methods
26 | function self = PaintStylePaperPlain()
27 | % do nothing..
28 | end
29 |
30 | function s = channelstyle(self,index)
31 | s = ['k-' self.markers(index)];
32 | end
33 |
34 | function s = weightstyle(self,index)
35 | s = ['k--' self.markers(index)];
36 | end
37 |
38 | function s = npfrfstyle(self,index)
39 | s = 'k:';
40 | end
41 |
42 | function s = size(self)
43 | s = [600,450];
44 | end
45 | end
46 |
47 | end
48 |
49 |
--------------------------------------------------------------------------------
/Modules/Control/Processor/ProcessorInterface.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef ProcessorInterface
18 | %PROCESSORINTERFACE Interface for pre/postprocessing unit
19 | % Interface for combination of pre- and postprocessing step when
20 | % designing a controller.
21 |
22 | methods (Abstract)
23 | preprocess(self,controllerdesign);
24 | postprocess(self,controllerdesign);
25 | end
26 |
27 | end
28 |
29 |
--------------------------------------------------------------------------------
/Modules/Control/Processor/SimpleProcessor.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef SimpleProcessor < ProcessorInterface
18 | %SIMPLEPROCESSOR Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | methods
22 | function [self,configuration2,problem2,solverhint] = preprocess(self,configuration,problem)
23 | % do nothing: solve problem as stated
24 | configuration2 = configuration;
25 | problem2 = problem;
26 | solverhint = [];
27 | end
28 |
29 | function [self,K] = postprocess(self,K)
30 | % do nothing...
31 | end
32 | end
33 |
34 | end
35 |
36 |
--------------------------------------------------------------------------------
/Modules/Control/Region.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef Region < Specification
18 |
19 | % This class will allow interactive specification of regions for pole
20 | % placement in the near future.
21 | properties
22 | L = [];
23 | M = [];
24 | end
25 |
26 | methods
27 | function self = Region(type,varargin)
28 | if nargin > 1
29 | param = varargin{1};
30 | end
31 | switch type
32 | case 'half'
33 | assert(isreal(param.alphal),'you should enter the left most real desired pole');
34 | if(~isfield(param,'alphar'))
35 | param.alphar = 0;
36 | end
37 | self.L = [2*param.alphal 0; 0 -2*param.alphar];
38 | self.M = [-1 0; 0 1];
39 | case 'conic'
40 | self.L = [0 0; 0 0];
41 | self.M = [cos(param.beta) -sin(param.beta); sin(param.beta) cos(param.beta)];
42 | otherwise
43 | error('For now, it can only take the left half section plane or a conic plane including damping, denoted by either "half" or "conic"');
44 | end
45 | end
46 | function m = region(self)
47 | m.L = self.L;
48 | m.M = self.M;
49 | end
50 | end
51 | end
52 |
53 |
--------------------------------------------------------------------------------
/Modules/Identification/MeasurementData.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef (Abstract) MeasurementData
18 | %MEASUREMENTDATA Class -- Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | properties %(Access = private)
22 | date_ = ''; % string
23 | label_ = ''; % label for the data set
24 | info_ = ''; % string
25 | end
26 |
27 | methods
28 | function self = MeasurementData(label, info, date)
29 | self.label_ = label;
30 | self.info_ = info;
31 | self.date_ = date;
32 | end
33 | end
34 |
35 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Models/@ODEmod/impulse.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function varargout = impulse(varargin)
18 | varargout = cell(1,nargout);
19 | [varargout{:}] = simfixed('impulse',varargin{:});
20 | end
21 |
22 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/@ODEmod/step.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function varargout = step(varargin)
18 | varargout = cell(1,nargout);
19 | [varargout{:}] = simfixed('step',varargin{:});
20 | end
21 |
22 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/DSSmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function mod = DSSmod(A,B,C,D,E,varargin)
18 | % Creates a model based on descriptor state-space data.
19 | % LCToolbox counterpart of MATLAB's \c dss().
20 |
21 | if all([isnumeric(A),isnumeric(B),isnumeric(C),isnumeric(D),isnumeric(E)])
22 | mod = LTIDSSmod(A,B,C,D,E,varargin{:});
23 | else
24 | mod = LPVDSSmod(A,B,C,D,E,varargin{:});
25 | end
26 |
27 | end
28 |
29 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/IdentFRDmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef IdentFRDmod < FRDmod
18 | %IDENTFRDMOD FRDmod generated by nonpar_ident
19 | % FRDmod containing extra info regarding the identification process
20 | %
21 |
22 | properties (Access=public)
23 | G_ % structure containing all model properties
24 | U_ % structure containing all properties of input fourier coeffs
25 | Y_ % structure containing all properties of output fourier coeffs
26 | CYU_ % sturcture containing all convariance properties of CUY
27 | end
28 |
29 | methods
30 | function self = IdentFRDmod(varargin)
31 | self@FRDmod(varargin{:});
32 | end
33 | end
34 | end
35 |
36 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/LFTmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function mod = LFTmod(M,Nu,Nl,E,varargin)
18 | %LFTMOD Unified LFTmod construction
19 | % This function determines the simplest model structure for the given
20 | % input. mod will either be of type LPVLFTmod or LTILFTmod.
21 |
22 | if ~all(size(M)==[4,4])
23 | n = size(M) - (size(Nu) + size(E) + size(Nl));
24 | dims = [size(Nu)',size(E)',n',size(Nl)'];
25 | M = mat2cell(M,dims(1,:),dims(2,:));
26 | end
27 | if iscell(M), checkM = all(cellfun(@isnumeric,M(:)));
28 | else checkM = isnumeric(M); end
29 | if checkM && isnumeric(Nu) && isnumeric(Nl) && isnumeric(E)
30 | mod = LTILFTmod(M,Nu,Nl,E,varargin{:});
31 | else
32 | mod = LPVLFTmod(M,Nu,Nl,E,varargin{:});
33 | end
34 |
35 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Models/LTIDSSmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef (InferiorClasses = {?zpk,?tf,?ss,?frd}) LTIDSSmod < AbstractDSSmod & AbstractLTImod & AnalyticModel
18 | %LTIDSSMOD Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | methods
22 | function self = LTIDSSmod(A,B,C,D,E,varargin)
23 | assert(all([isnumeric(A),isnumeric(B),isnumeric(C),isnumeric(D),isnumeric(E)]),'All inputs should be numeric');
24 | self = self@AbstractDSSmod(A,B,C,D,E,varargin{:});
25 | end
26 |
27 | function sys = std(self)
28 | sys = dss(self.A,self.B,self.C,self.D,self.E,self.Ts);
29 | end
30 |
31 | function sys = simplify(self)
32 | sys = self;
33 | end
34 |
35 | function product = mtimes(self,other)
36 | if isnumeric(self) || isnumeric(other)
37 | product = mtimes@AbstractDSSmod(self,other);
38 | else
39 | product = mtimes@AnalyticModel(self,other);
40 | end
41 | end
42 |
43 | function varargout = c2d(self,varargin)
44 | % TO DO: make difference between builtin and own implementation
45 | [sys,G] = c2d(std(self),varargin{:});
46 | varargout{1} = fromstd(sys);
47 | if nargout >= 2
48 | varargout{2} = G;
49 | end
50 | end
51 |
52 | function varargout = d2c(self,varargin)
53 | [sys,G] = d2c(std(self),varargin{:});
54 | varargout{1} = fromstd(sys);
55 | if nargout >= 2
56 | varargout{2} = G;
57 | end
58 | end
59 |
60 | end
61 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Models/LTILFTmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef (InferiorClasses = {?zpk,?tf,?ss,?frd}) LTILFTmod < AbstractLFTmod & AbstractLTImod & AnalyticModel
18 | %LTILFTMOD Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | methods
22 | function self = LTILFTmod(M,Nu,Nl,E,Ts)
23 | if iscell(M), checkM = all(cellfun(@isnumeric,M(:)));
24 | else checkM = isnumeric(M); end
25 | assert(checkM&&isnumeric(Nu)&&isnumeric(Nl)&&isnumeric(E),'All inputs should be numeric');
26 | self = self@AbstractLFTmod(M,Nu,Nl,E,Ts);
27 | end
28 |
29 | function sys = std(self)
30 | S = transpose(lft2ss(self));
31 | sys = dss(S{:},self.E,self.Ts);
32 | end
33 |
34 | function sys = simplify(self)
35 | S = transpose(lft2ss(self));
36 | sys = LTIDSSmod(S{:},self.E,self.Ts);
37 | end
38 |
39 | function product = mtimes(self,other)
40 | if isnumeric(self) || isnumeric(other)
41 | product = mtimes@AbstractLFTmod(self,other);
42 | else
43 | product = mtimes@AnalyticModel(self,other);
44 | end
45 | end
46 | end
47 | end
48 |
49 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/SSmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function mod = SSmod(varargin)
18 | % Creates a model based on state-space data.
19 | % LCToolbox counterpart of MATLAB's \c ss().
20 |
21 | if isa(varargin{1},'Gridmod')
22 | [~,~,~,~,~,mod] = smile_techniqueOC_spline(varargin{:});
23 | else
24 | if nargin >= 4
25 | A = varargin{1};
26 | B = varargin{2};
27 | C = varargin{3};
28 | D = varargin{4};
29 | varargin(1:4) = [];
30 | elseif nargin >= 1
31 | D = varargin{1};
32 | A = zeros(0,0);
33 | B = zeros(0,size(D,2));
34 | C = zeros(size(D,1),0);
35 | varargin(1) = [];
36 | end
37 |
38 | E = eye(size(A));
39 | mod = DSSmod(A,B,C,D,E,varargin{:});
40 | end
41 | end
42 |
43 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/SUMmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function s = SUMmod(in1,in2)
18 | %SUMmod Sum relation between signals
19 | % Defines the algebraic sum of 2, resulting in a
20 | % new signal.
21 |
22 | N = length(in1);
23 | if length(in2) ~= N
24 | error('Inputs for SUM must be of equal length');
25 | end
26 |
27 | in = [in1;in2];
28 | out = Signal(N);
29 | A = zeros(0,0); B = zeros(0,2*N);
30 | C = zeros(N,0); D = [eye(N),eye(N)];
31 |
32 | s = SSmod(A,B,C,D,in,out);
33 | end
34 |
35 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/USSmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function umodel = USSmod(A,B,C,D)
18 | %UTFMOD Create LFTmod from an uncertain transfer function
19 | % Detailed explanation goes here
20 |
21 | p = inputParser;
22 | addRequired(p,'A',@(x) assert(isnumeric(x) || isa(x,'umat') || isa(x,'ureal'),'Your matrices should be numeric or of type ''umat'' or ''ureal''.'));
23 | addRequired(p,'B',@(x) assert(isnumeric(x) || isa(x,'umat') || isa(x,'ureal'),'Your matrices should be numeric or of type ''umat'' or ''ureal''.'));
24 | addRequired(p,'C',@(x) assert(isnumeric(x) || isa(x,'umat') || isa(x,'ureal'),'Your matrices should be numeric or of type ''umat'' or ''ureal''.'));
25 | addRequired(p,'D',@(x) assert(isnumeric(x) || isa(x,'umat') || isa(x,'ureal'),'Your matrices should be numeric or of type ''umat'' or ''ureal''.'));
26 | parse(p,A,B,C,D);
27 |
28 | A = p.Results.A;
29 | B = p.Results.B;
30 | C = p.Results.C;
31 | D = p.Results.D;
32 |
33 | ussmodel = uss(A,B,C,D);
34 | umodel = UModel(ussmodel);
35 |
36 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Models/UTFmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function umodel = UTFmod(num, den)
18 | %UTFMOD Create LFTmod from an uncertain transfer function
19 | % Detailed explanation goes here
20 |
21 | p = inputParser;
22 | addRequired(p,'num',@(x) assert(isnumeric(x) || isa(x,'umat') || isa(x,'ureal'),'Your numerator should be numeric or of type ''umat'' or ''ureal''.'));
23 | addRequired(p,'den',@(x) assert(isnumeric(x) || isa(x,'umat') || isa(x,'ureal'),'Your denominator should be numeric or of type ''umat'' or ''ureal''.'));
24 | parse(p,num,den);
25 |
26 | num = p.Results.num;
27 | den = p.Results.den;
28 |
29 | ussmodel = uss(tf(num,den));
30 | umodel = UModel(ussmodel);
31 |
32 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Models/UZPKmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function umodel = UZPKmod(z,p,k)
18 | %UZPKMOD Create LFTmod from an uncertain zpk model
19 | % Detailed explanation goes here
20 |
21 | pr = inputParser;
22 | addRequired(pr,'z',@(x) assert(isnumeric(x) || isa(x,'umat') || isa(x,'ureal'),'Your zeros should be numeric or of type ''umat'' or ''ureal''.'));
23 | addRequired(pr,'p',@(x) assert(isnumeric(x) || isa(x,'umat') || isa(x,'ureal'),'Your poles should be numeric or of type ''umat'' or ''ureal''.'));
24 | addRequired(pr,'k',@(x) assert((isnumeric(x) || isa(x,'umat') || isa(x,'ureal')) && length(x) == 1,'Your gain should be a scalar, either numeric or of type ''umat'' or ''ureal''.'));
25 | parse(pr,z,p,k);
26 |
27 | z = pr.Results.z;
28 | p = pr.Results.p;
29 | k = pr.Results.k;
30 |
31 | s = tf('s');
32 | num = 1; den = 1;
33 |
34 | for i = 1:length(z)
35 | num = num*(s-z(i));
36 | end
37 | for i = 1:length(p)
38 | den = den*(s-p(i));
39 | end
40 |
41 | ussmodel = uss(k*num/den);
42 | umodel = UModel(ussmodel);
43 |
44 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Models/ZPKmod.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function sys = ZPKmod(varargin)
18 | % Creates a model based on pole, zero and gain data.
19 | % LCToolbox counterpart of MATLAB's \c zpk().
20 |
21 | zpksys = zpk(varargin{:});
22 | [A,B,C,D,E,Ts] = dssdata(zpksys);
23 | sys = DSSmod(A,B,C,D,E,Ts);
24 |
25 | % % TODO: spline implementation
26 | % switch nargin
27 | % case 1
28 | % % static gain
29 | %
30 | % case 2
31 | % % ct zpk
32 | %
33 | % case 3
34 | % % dt zpk
35 | %
36 | % end
37 |
38 | end
39 |
40 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/helpers/AnalyticModel.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | classdef (InferiorClasses = {?zpk,?tf,?ss,?frd}) AnalyticModel < Model
18 | %ANALYTICMODEL Summary of this class goes here
19 | % Detailed explanation goes here
20 |
21 | methods
22 |
23 | function self = AnalyticModel()
24 | self@Model();
25 | end
26 |
27 | function varargout = subsref(self,s)
28 | % SUBSREF reimplement subsref for systems subindexing
29 | if strcmp(s(1).type,'()')
30 | siz = size(self);
31 | assert(~(isa(s(1).subs{1},'Signal') || isa(s(1).subs{2},'Signal')),'Cannot index a model using signals. Signals refer only to systems');
32 | if s(1).subs{1}==':';s(1).subs{1}=1:siz(1);end
33 | if s(1).subs{2}==':';s(1).subs{2}=1:siz(2);end
34 | assert(all(cellfun(@isnumeric,s(1).subs)),'only numeric index');
35 | assert(all(s(1).subs{1}<=siz(1)) && all(s(1).subs{2}<=siz(2)),'Index exceeds system dimensions.');
36 | varargout = {submodel(self,s(1).subs{1},s(1).subs{2})};
37 |
38 | if length(s)>1
39 | varargout = {builtin('subsref',varargout{1},s(2:end))};
40 | end
41 | else
42 | varargout = {builtin('subsref',self,s(:))};
43 | end
44 | end
45 |
46 | end
47 |
48 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Models/helpers/safeeval.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [e] = safeeval(func,values,args)
18 | %SAFEEVAL Summary of this function goes here
19 | % Detailed explanation goes here
20 |
21 | if isnumeric(func)
22 | e = func;
23 | else
24 | e = func.eval(values,args);
25 | end
26 | end
27 |
28 |
--------------------------------------------------------------------------------
/Modules/Modeling/Models/helpers/safegrideval.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [e] = safegrideval(func,grid,args)
18 | % Ensures safe evaluation of a model matrix on a grid.
19 | % Written for the Optispline toolbox.
20 | %
21 | % Parameters:
22 | % func : object to be evaluated, either \c double or \c Function
23 | % grid : grid : cell with grid{i} a vector (\c double) with the gridpoints for
24 | % scheduling parameter i
25 | % args : cell with args{i} the name (\c char) of scheduling parameter i @type cell
26 |
27 | grid = cellfun(@(x) x(:),grid,'un',0);
28 |
29 | if isnumeric(func)
30 | r = repmat(func,[1,1,cellfun(@length,grid)]);
31 | e = permute(r,[2+(1:length(grid)),1,2]);
32 | else
33 | e = func.grid_eval(grid,args);
34 | end
35 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Systems/IOSystem.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function self = IOSystem(varargin)
18 | % Creates a SystemOfModels or SystemOfSystems object, depending on the
19 | % input arguments. The end user is not supposed to construct such objects
20 | % himself but only through this function.
21 | %
22 | % Parameters:
23 | % varargin: may contain a mix of different Model objects, SystemOfModels
24 | % objects or SystemOfSystems objects. The last input argument, furthermore,
25 | % is allowed to be a cell that specifies how all models and/or systems are
26 | % connected to each other.
27 | %
28 | % Return values:
29 | % self : a SystemOfModels or a SystemOfSystems object @type AbstractSystem
30 |
31 | if nargin > 0
32 | if isa(varargin{1},'AbstractSystem')
33 | self = SystemOfSystems(varargin{:});
34 | else
35 | self = SystemOfModels(varargin{:});
36 | end
37 | end
--------------------------------------------------------------------------------
/Modules/Modeling/Systems/restore.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function restore( data )
18 | %RESTORE Summary of this function goes here
19 | % Detailed explanation goes here
20 |
21 | arrayfun(@(x)restore(x.var,x.removed,x.index),data);
22 |
23 | end
24 |
25 |
--------------------------------------------------------------------------------
/Modules/Modeling/Systems/util/extend_in.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function varargout = extend_in(in,varargin)
18 | if nargin > 2
19 | varargout = cellfun(@(x)extend_in(in,x),varargin,'UniformOutput',false);
20 | else
21 | self = varargin{1};
22 | M_ = self.M;
23 |
24 | [loca,locin] = ismember(self.in,in);
25 | B_ = zeros(size(M_,1),length(in));
26 | try
27 | B_(:,locin) = M_(:,self.nupper+self.nx+(1:self.nu));
28 | catch
29 | keyboard
30 | end
31 | M_ = [M_(:,1:(self.nupper+self.nx)), B_,...
32 | M_(:,self.nupper+self.nx+self.nu+(1:self.nlower))];
33 |
34 | varargout{1} = LFTsys(M_,self.Nu,self.Nl,self.E,self.Ts,in,self.out);
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/Modules/Modeling/Systems/util/extend_io.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function varargout = extend_io(in,out,varargin)
18 | t = cell(1,length(varargin));
19 | [t{:}] = extend_in(in,varargin{:});
20 | varargout = cell(1,nargout);
21 | [varargout{:}] = extend_out(out,t{:});
22 | end
23 |
24 |
--------------------------------------------------------------------------------
/Modules/Modeling/Systems/util/extend_out.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function varargout = extend_out(out,varargin)
18 | if nargin > 2
19 | varargout = cellfun(@(x)extend_out(out,x),varargin,'UniformOutput',false);
20 | else
21 | varargout{1} = transpose(extend_in(out,transpose(varargin{1})));
22 | % M_ = self.M;
23 | %
24 | % [loca,locout] = ismember(out,self.out);
25 | % locout(~loca) = [];
26 | % C_ = zeros(length(out),size(M_,2));
27 | % C_(:,locout) = M_(self.nupper+self.nx+(1:self.ny),:);
28 | % M_ = [M_(1:(self.nupper+self.nx),:); C_;...
29 | % M_(self.nupper+self.nx+self.ny+(1:self.nlower),:)];
30 | %
31 | % self = LFTsys(M_,self.Nu,self.Nl,self.E,self.Ts,in,self.out);
32 | end
33 | end
--------------------------------------------------------------------------------
/Util/Parameter.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function p = Parameter(varargin)
18 | check_optispline;
19 | import splines.*;
20 |
21 | p = SchedulingParameter(varargin);
22 | end
23 |
24 |
--------------------------------------------------------------------------------
/Util/augw2.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [P] = augw2(G,W1,W2,W3)
18 | %AUGW_IP matlab augw reimplementation for improper systems
19 | % AUGW_IP is the equivalent for matlabs built-in AUGW, dealing with
20 | % systems in the descriptor form, resulting in a proper or improper generalized
21 | % plant.
22 |
23 | Wout = [];
24 |
25 | % Setup problem
26 | G = fromstd(G);
27 | SysG = IOSystem(G);
28 |
29 | systems = {SysG};
30 |
31 | r = Signal(size(G,2)); % r = external reference to the plant (should have the dimensions of G(.,x))
32 | u = SysG.in; % u = controled input
33 | y = SysG.out; % y = controled output
34 | e = r - y;
35 |
36 | connections = {};
37 |
38 | % Add weights
39 | if(~isempty(W1))
40 | W1 = fromstd(W1);
41 | SysW1 = IOSystem(W1);
42 | systems{end+1} = SysW1;
43 | connections{end+1} = [SysW1.in == e];
44 | Wout = [Wout; SysW1.out];
45 | end
46 | if(~isempty(W2))
47 | W2 = fromstd(W2);
48 | SysW2 = IOSystem(W2);
49 | systems{end+1} = SysW2;
50 | connections{end+1} = [SysW2.in == u];
51 | Wout = [Wout; SysW2.out];
52 | end
53 | if(~isempty(W3))
54 | W3 = fromstd(W3);
55 | SysW3 = IOSystem(W3);
56 | systems{end+1} = SysW3;
57 | connections{end+1} = [SysW3.in == y];
58 | Wout = [Wout; SysW3.out];
59 | end
60 |
61 | % solve the generalized plant
62 | aug = IOSystem(systems{:},vertcat(connections{:}));
63 | P = aug([Wout;e],[r;u]).content(1);
64 | end
65 |
66 |
--------------------------------------------------------------------------------
/Util/butter2.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [num, den] = butter2(n, Wn, varargin)
18 | %BUTTER2 Compute continuous or discrete time butterworth filter
19 | % n = order
20 | % Wn = cut-off frequency [rad/s]
21 | % Ts (optional) = sample time
22 | % type = 'low' or 'high' ('stop and pass are undefined')
23 |
24 | type = 'low';
25 | analog = false;
26 |
27 | for k = 1:length(varargin)
28 | if length(varargin{k}) == 1
29 | analog = strcmp(varargin{k},'s');
30 | else
31 | type = varargin{k};
32 | end
33 | end
34 |
35 | if ~analog,
36 | fs = 2;
37 | u = 2*fs*tan(pi*Wn/fs);
38 | else
39 | u = Wn;
40 | end
41 |
42 | % continuous time butterworth filter
43 | if strcmp(type,'high')
44 | num = [1 zeros(1,n)];
45 | else
46 | num = u^n;
47 | end
48 |
49 | den = butterpoly(n,u);
50 |
51 | % Discretize if necessary
52 | if ~analog
53 | [num,den] = tfdata(c2d(tf(num,den),1/fs,'Tustin'),'v');
54 | end
55 | end
--------------------------------------------------------------------------------
/Util/butterpoly.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function poly = butterpoly(n,u)
18 | %BUTTERPOLY Make butterworth polynomial
19 | % Constructs the coefficients of a butterworth polynomial of degree n in
20 | % continuous time.
21 | % Args: n = degree
22 | % u = abs(roots)
23 |
24 | if mod(n,2)==1 %uneven
25 | poly = [1 u];
26 | for k = 1:((n-1)/2)
27 | if isnumeric(u)
28 | poly = conv(poly,[1 -2*u*cos((2*k+n-1)*pi/(2*n)) u^2]);
29 | else
30 | poly = convpar(poly,[1 -2*u*cos((2*k+n-1)*pi/(2*n)) u^2]);
31 | end
32 | end
33 | else
34 | poly = 1;
35 | for k = 1:(n/2)
36 | if isnumeric(u)
37 | poly = conv(poly,[1 -2*u*cos((2*k+n-1)*pi/(2*n)) u^2]);
38 | else
39 | poly = convpar(poly,[1 -2*u*cos((2*k+n-1)*pi/(2*n)) u^2]);
40 | end
41 | end
42 | end
43 |
44 | end
45 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 | function [y] = convpar(u,v)
47 | check_optispline;
48 | import splines.*;
49 | opti = OptiSplineYalmip();
50 | TB = TensorBasis({},{});
51 |
52 | nu = size(u,2);
53 | nv = size(v,2);
54 | n = nu+nv-1;
55 | %y = {};
56 | % y = zeros(1,n);
57 | %UNTITLED2 Summary of this function goes here
58 | % Detailed explanation goes here
59 | U = [u zeros(1,n-nu)];
60 | V = [v zeros(1,n-nv)];
61 | ys = {};
62 | for i = 1:n
63 | x = 0;
64 | for j = 1:i
65 | x = x + U(j)*V(i-j+1);
66 | end
67 | ys = {ys{:}, x};
68 | end
69 | y = [ys{:}];
70 | end
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/Util/check_label.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [match,m] = check_label(sys,io)
18 | %CHECK_LABEL Check the consistency input or output labels of a system
19 | switch io
20 | case 'i'
21 | list = sys.u;
22 | case 'o'
23 | list = sys.y;
24 | end
25 |
26 | p = regexp(list,'\w*(?=(\w*))', 'match');
27 |
28 | if(size(p,1)==length(list))
29 | m = p{1,1}{1,1};
30 | match = 1; k = 2;
31 | while((match==1)&&(k<=length(list)))
32 | match = match && strcmp(m,p{k,1}{1,1});
33 | k = k+1;
34 | end
35 | else
36 | match = 0; m = 0;
37 | end
38 |
39 | end
40 |
41 |
--------------------------------------------------------------------------------
/Util/check_optispline.m:
--------------------------------------------------------------------------------
1 | import splines.*
2 | try
3 | BSplineBasis([-1 0 1],1);
4 | catch
5 | error('OptiSpline was not found. Make sure to download the toolbox and to put it on your MATLAB path. Be careful: do NOT add the subfolders of the OptiSpline package to your path.');
6 | end
--------------------------------------------------------------------------------
/Util/clean_plant.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [sys] = clean_plant(sys,varargin)
18 | %CLEAN_PLANT Summary of this function goes here
19 | % Detailed explanation goes here
20 |
21 | if(nargin>1)
22 | tol = varargin{1};
23 | else
24 | tol = eps;
25 | end
26 |
27 | members = {'a','b','c','d','e'};
28 | for i = 1:length(members)
29 | field = sys.(members{i});
30 | field(abs(field) < tol) = 0;
31 | sys.(members{i}) = field;
32 | end
33 |
34 | end
35 |
36 |
--------------------------------------------------------------------------------
/Util/dampen.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [sys_damped] = dampen(sys, varargin)
18 | range = [0,+inf];
19 | damping = 1;
20 |
21 | if(nargin>1)
22 | if(length(varargin{1})>1)
23 | range = varargin{1};
24 | if(nargin>2)
25 | damping = varargin{2};
26 | end
27 | else
28 | damping = varargin{1};
29 | if(nargin>2)
30 | range = varargin{2};
31 | end
32 | end
33 | end
34 |
35 | [z,p,k] = zpkdata(sys,'v');
36 |
37 | iz = (abs(z)>range(1)) & (abs(z)range(1)) & (abs(p).
16 |
17 | function [Y] = db(X)
18 | %DB Convert to decibels
19 | % Alternative to matlab's db() from the signal processing toolbox.
20 |
21 | % We want to guarantee that the result is an integer
22 | % if X is a negative power of 10. To do so, we force
23 | % some rounding of precision by adding 300-300.
24 |
25 | Y = (20.*log10(abs(X))+300)-300;
26 | end
27 |
28 |
--------------------------------------------------------------------------------
/Util/dbtolinspline.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function spline_out = dbtolinspline(spline_in,noiknots,degree)
18 | %DBTOLINSPLINE Approximates 10^(spline_in/20) as a new B-spline in the same
19 | %arguments as spline_in
20 | % Detailed explanation goes here
21 |
22 | check_optispline;
23 | import splines.*;
24 |
25 | if nargin == 1
26 | noiknots = 3;
27 | degree = 3;
28 | elseif nargin == 3
29 | else error('dbtolinspline needs one or three input arguments.');
30 | end
31 |
32 | % create a new tensor basis
33 |
34 | domains = cellfun(@(x) x.domain.data, spline_in.tensor_basis.bases, 'un', 0);
35 | bases = cellfun(@(x) BSplineBasis(x, degree, noiknots),domains,'un',0);
36 | new_basis = TensorBasis(bases,cellstr(spline_in.tensor_basis.arguments)');
37 |
38 | % fit the new spline based on a linspace of 100 points in each
39 | % dimension
40 |
41 | grid = cellfun(@(x) linspace(x(1),x(2),100),domains,'un',0);
42 | args = cellstr(spline_in.tensor_basis.arguments)';
43 | val = spline_in.grid_eval(grid,args);
44 | val = 10.^(val/20);
45 |
46 | opti = OptiSpline();
47 | F = opti.Function(new_basis);
48 | if length(bases) == 1
49 | tmp = F.grid_eval(grid,args);
50 | diff = tmp(:,:,1) - val;
51 | else
52 | diff = squeeze(F.grid_eval(grid,args)) - val;
53 | end
54 | vars = diff.data;
55 | obj = norm(vars,2); % least squares
56 |
57 | opti.minimize(obj);% unconstrained: boundaries might not be the same anymore!
58 | opti.solver('ipopt');
59 | sol = opti.solve();
60 | F = sol.value(F);
61 |
62 | spline_out = F;
63 |
64 | end
65 |
66 |
--------------------------------------------------------------------------------
/Util/diag2.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [sys,Ts,Te] = diag2(sys)
18 | %DIAG Diagonalizes E (or A)
19 | % Returns an equivalent system with E (or A) equal to a (semi)-unity
20 | % matrix.
21 | %
22 | % INPUTS:
23 | % sys = system to be transformed
24 | %
25 | % OUTPUTS:
26 | % sys: the transformed system
27 | % Ts,Te: Enew = Te*Eold*Ts, Anew = Te*Aold*Ts, Bnew = Te*Bold, Cnew =
28 | % Cold*Ts
29 |
30 | Ts = eye(size(sys.a));
31 | Te = eye(size(sys.a));
32 |
33 | if ~isempty(sys.e)
34 | [U,S,V] = svd(sys.e);
35 | scal = diag(1./diag(S));
36 | scal(~isfinite(scal)) = 1;
37 |
38 | sys.e = scal*transpose(U)*sys.e*V;
39 | sys.a = scal*transpose(U)*sys.a*V;
40 | sys.b = scal*transpose(U)*sys.b;
41 | sys.c = sys.c*V;
42 |
43 | Ts = V;
44 | Te = transpose(U);
45 | else
46 | sys.e = eye(size(sys.a));
47 | end
48 |
49 | end
50 |
51 |
--------------------------------------------------------------------------------
/Util/diagE_ip.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [A,B,C,E,Tl,Tr] = diagE_ip(A,B,C,E)
18 | %DIAGE_IP
19 | % Put plant in diagonal form. This results in a matrix of the form:
20 | % E = [I 0;0 0]. Straightforward use can be diagonalizing E, but it can also
21 | % be used to diagonalize A, by switching inputs A and E.
22 | % inputs: system matrices A,B,C,E
23 | % outputs: transformed At,Bt,Ct,Et where E is in the diagonal form and the
24 | % transformation matrices Tl and Tr so that Tl*A*Tr = At, Tl*B = Bt, C*Tr
25 | % = Ct, Tl*E*Tr = Et
26 |
27 | % n = size(A,1);
28 | %
29 | % if(~isempty(E))
30 | % R = robust_rref([E eye(n)]);
31 | % E = R(1:n,1:n);
32 | % Tl = R(:,(n+1):(2*n));
33 | % A = Tl*A;
34 | % B = Tl*B;
35 | %
36 | % R = robust_rref([E' eye(n)]);
37 | % E = R(1:n,1:n);
38 | % Tr = R(:,(n+1):(2*n))';
39 | % A = A*Tr;
40 | % C = C*Tr;
41 | % else
42 | % E = eye(n);
43 | % Tl = eye(n);
44 | % Tr = eye(n);
45 | % end
46 |
47 | sys = dss(A,B,C,zeros(size(C,1),size(B,2)),E);
48 | [sys,Ts,Te] = diag2(sys);
49 |
50 | A = sys.a;
51 | B = sys.b;
52 | C = sys.c;
53 | E = sys.e;
54 | Tl = Te;
55 | Tr = Ts;
56 |
57 | end
58 |
59 |
--------------------------------------------------------------------------------
/Util/entrynorm.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function output = entrynorm(S,varargin)
18 | %ENTRYNORM Computes an entrywise norm
19 | % Computes the system norm entrywise. All usual norm options are
20 | % available (basicly choosing the norm: 2 or inf)
21 |
22 | [m,n] = size(S);
23 | output = zeros(m,n);
24 |
25 | warning off;
26 | for i = 1:m
27 | for j = 1:n
28 | output(i,j) = norm(S(i,j),varargin{:});
29 | end
30 | end
31 | warning on;
32 |
33 | end
34 |
35 |
--------------------------------------------------------------------------------
/Util/ismembertols.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [IA,LOCB] = ismembertols(A,B,tol)
18 | %ISMEMBERTOLS Summary of this function goes here
19 | % Detailed explanation goes here
20 |
21 | if nargin < 3
22 | if eps < 1e-10
23 | tol = 1e-12; %double precision machine
24 | else
25 | tol = 1e-6;
26 | end
27 | end
28 |
29 | IA = false(1,length(A));
30 | LOCB = zeros(1,length(A));
31 |
32 | ib = 1;
33 | for ia = 1:length(A)
34 | while B(ib) < (A(ia) - tol)
35 | ib = ib+1;
36 | if ib>length(B), break; end
37 | end
38 | if ib>length(B), break; end
39 | if abs(B(ib)-A(ia)) < tol
40 | IA(ia) = true;
41 | LOCB(ia) = ib;
42 | end
43 | end
--------------------------------------------------------------------------------
/Util/linestyles.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [colors,markers] = linestyles()
18 | %LINESTYLES
19 | % Get 5 default colors and markers to make up plots
20 |
21 | colors = [0,0,1;...
22 | 1,0,0;...
23 | 0,0,0;...
24 | 0,1,0;...
25 | 0.5,0,0.5];
26 |
27 | markers = {'o';'d';'x';'s';'*'};
28 |
29 | end
30 |
31 |
--------------------------------------------------------------------------------
/Util/matrix_expand.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [code] = matrix_expand(X,v,varargin)
18 | %MATRIX_EXPAND expands a matrix product to C code
19 | % Detailed explanation goes here
20 |
21 | options = struct('optZ',1e-10,...
22 | 'optO',1e-10);
23 | if(nargin>2)
24 | options = mergestruct(varargin{1},options);
25 | end
26 |
27 | N = size(X,1);
28 | code = cell(N,1);
29 | for k=1:size(X,1)
30 | % expand cell
31 | code{k,1} = row_expand(X(k,:),v,options);
32 | end
33 |
34 | end
35 |
36 | function [line] = row_expand(R,v,options)
37 | %ROW_EXPAND expand row to corresponding C code
38 | % Detailed explanation goes here
39 |
40 | line = [];
41 | for k=1:length(R)
42 | % expand cell
43 | if((options.optZ>0)&&(abs(R(k))0)&&(abs(R(k)-1)0)&&(abs(R(k)+1).
16 |
17 | function [s] = mergestruct(varargin)
18 | %MERGESTRUCT merge 2 or more structures
19 | % Merges 2 or more structures into 1 structure where the first structure
20 | % has priority on the second, meaning that fields with the same name will
21 | % be taken from the first and not from the second. When there are more
22 | % than 2 structures, the 2nd has priority over the 3rd and so on.
23 |
24 | s = struct();
25 |
26 | for k = 1:length(varargin)
27 | if ~isempty(varargin{k})
28 | s0 = varargin{k};
29 | fields0 = fieldnames(s0);
30 | fields = fieldnames(s);
31 |
32 | % check which fields needed merge and which are new
33 | [lia,~] = ismember(fields0,fields);
34 |
35 | for(j = 1:length(fields0)) % iterate over fields that are set and change them to the new value
36 | if(lia(j)) % merge
37 | if(isstruct(s.(fields0{j,1})))
38 | s.(fields0{j,1}) = mergestruct(s.(fields0{j,1}),s0.(fields0{j,1})); % merge the structured fields recursively
39 | end
40 | else % add
41 | s.(fields0{j,1}) = s0.(fields0{j,1});
42 | end
43 | end
44 | end
45 | end
46 | end
47 |
48 |
--------------------------------------------------------------------------------
/Util/minrealr.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [sys] = minrealr(sys,varargin)
18 | %MINREALR Relative minreal
19 | % Cancel out poles and zeros based on relative distance rather than
20 | % absolute distance. This is currently implemented for siso only
21 |
22 | if(~all(size(sys)==1))
23 | % for k = 1:size(sys,1)
24 | % for l = 1:size(sys,2)
25 | % sys(k,l) = minrealr(sys(k,l),varargin{:});
26 | % end
27 | % end
28 | else
29 | [z,p,k] = zpkdata(sys,'v');
30 | tol = 1e-3;
31 | if(nargin>1)
32 | tol = varargin{1};
33 | end
34 |
35 | remove_z = false(size(z));
36 | remove_p = false(size(p));
37 |
38 | for(j=length(z):-1:1)
39 | for(i = length(p):-1:1)
40 | az = abs(z(j)); ap = abs(p(i));
41 | if(2*(abs(az-ap))/(az+ap) < tol)
42 | % disp('removed pole/zero');
43 | % disp('pole'); disp(p(i));
44 | % disp('zero'); disp(z(j));
45 | z(j) = []; p(i) = [];
46 | break;
47 | end
48 | end
49 | end
50 |
51 | sys = zpk(z,p,k,sys.Ts);
52 | end
53 | end
54 |
55 |
--------------------------------------------------------------------------------
/Util/obsvf_ip.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [A,B,C,D,E,Tl,Tr,K] = obsvf_ip(A,B,C,D,E,varargin)
18 | %OBSVF_IP Transform improper system in observable form
19 | % Transform the system in the observability form. Works for both proper
20 | % and improper systems.
21 |
22 | [A,B,C,E,Tl,Tr] = diagE_ip(A,B,C,E);
23 | n = size(A,1);
24 | m = size(C,1);
25 | l = size(B,2);
26 |
27 | %% Take care of improper states
28 | i = 0; j = 0;
29 | P = [A B;C D]';
30 | Cswap = 1:m;
31 | while(all(E(n-i,:)==0))
32 | if(~all(P(n-i,n+(1:m))==0))
33 | if(P(n-i,n+m-j)==0)
34 | swap = find(P(n-i,n+(1:(m-j)))~=0,1);
35 | if(~isempty(swap))
36 | P(:,[(n+swap) (n+m-j)]) = P(:,[(n+m-j) (n+swap)]);
37 | Cswap([(swap) (m-j)]) = Cswap([(m-j) (swap)]);
38 | end
39 | end
40 | for(k=1:(n-i-1))
41 | if(P(n-i,n+m-j)~=0)
42 | P(k,:) = P(k,:) - (P(k,n+m-j)*P(n-i,:)/P(n-i,n+m-j));
43 | end
44 | end
45 | j = j+1;
46 | end
47 | i = i+1;
48 | end
49 | P = P';
50 | A = P(1:n,1:n);
51 | B = P(1:n,n+(1:l));
52 | C = P(n+(1:m),1:n);
53 | D = P(n+(1:m),n+(1:l));
54 |
55 | %% Staircase form
56 | if(nargin>5)
57 | [A,B,C,T,K] = obsvf(A,B,C,varargin{1});
58 | else
59 | [A,B,C,T,K] = obsvf(A,B,C);
60 | end
61 | E = T*E*(T');
62 | C = C(Cswap,:);
63 | D = D(Cswap,:);
64 |
65 | % TODO: Include swaps in transform
66 | Tl = T*Tl;
67 | Tr = Tr*(T');
68 | end
69 |
70 |
--------------------------------------------------------------------------------
/Util/range.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function minmaxdiff = range(x,dim)
18 | %RANGE
19 |
20 | if nargin < 2
21 | minmaxdiff = max(x) - min(x);
22 | else
23 | minmaxdiff = max(x,[],dim) - min(x,[],dim);
24 | end
25 |
--------------------------------------------------------------------------------
/Util/removehigh.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [sys_remove] = removehigh(sys,varargin)
18 | %REMOVEHIGH Summary of this function goes here
19 | % Detailed explanation goes here
20 | if(nargin>1)
21 | if(length(varargin{1}) == 1)
22 | xmin = [varargin{1};+inf];
23 | else
24 | xmin = varargin{1};
25 | end
26 | else
27 | xmin = [1e5;inf];
28 | end
29 |
30 | flag = false;
31 | if ~isa(sys,'numlti')
32 | stdsys = std(sys);
33 | flag = true;
34 | else
35 | stdsys = sys;
36 | end
37 |
38 | [z,p,k] = zpkdata(stdsys);
39 |
40 | p_rm = cellfun(@(x) remove(x,xmin), p, 'UniformOutput', false);
41 | z_rm = cellfun(@(x) remove(x,xmin), z, 'UniformOutput', false);
42 |
43 | sys_remove = zpk(z_rm,p_rm,k);
44 | sys_remove = sys_remove.*(abs(evalfr(stdsys,j*1e-2))./abs(evalfr(sys_remove,j*1e-2)));
45 | sys_remove = correctPhase(sys_remove,stdsys);
46 |
47 | if flag
48 | sys_remove = fromstd(sys_remove);
49 | sys_remove.name = sys.name;
50 | end
51 |
52 | end
53 |
54 | function x = remove(x,varargin)
55 | if(nargin>1)
56 | if(length(varargin{1}) == 1)
57 | xmin = [varargin{1};+inf];
58 | else
59 | xmin = varargin{1};
60 | end
61 | else
62 | xmin = [1e5;+inf];
63 | end
64 | x((abs(x)>xmin(1)) & (abs(x).
16 |
17 | function [sys_remove] = removelow(sys,varargin)
18 | %REMOVELOW Summary of this function goes here
19 | % Detailed explanation goes here
20 | if(nargin>1)
21 | xmax = varargin{1};
22 | else
23 | xmax = 1e-2;
24 | end
25 |
26 | [z,p,k] = zpkdata(sys);
27 |
28 | p_rm = cellfun(@(x) remove(x,xmax), p, 'UniformOutput', false);
29 | z_rm = cellfun(@(x) remove(x,xmax), z, 'UniformOutput', false);
30 |
31 | sys_remove = zpk(z_rm,p_rm,k);
32 | sys_remove = sys_remove.*(abs(evalfr(sys,j*1e5))./abs(evalfr(sys_remove,j*1e5)));
33 | sys_remove = correctPhase(sys_remove,sys);
34 |
35 | end
36 |
37 | function x = remove(x,varargin)
38 | if(nargin>1)
39 | xmax = varargin{1};
40 | else
41 | xmax = 1e-2;
42 | end
43 | x(abs(x).
16 |
17 | function [sys_remove] = removeres(sys,w,tol)
18 | %REMOVERES Removes the resonanses from a given system
19 | % Detailed explanation goes here
20 |
21 | [z,p,k] = zpkdata(sys);
22 |
23 | p_rm = cellfun(@(x) remove(x,w,tol), p, 'UniformOutput', false);
24 | z_rm = cellfun(@(x) remove(x,w,tol), z, 'UniformOutput', false);
25 |
26 | sys_remove = zpk(z_rm,p_rm,k);
27 | sys_remove = sys_remove.*(abs(evalfr(sys,0)./abs(evalfr(sys_remove,0))));
28 | sys_remove = correctPhase(sys_remove,sys);
29 |
30 | end
31 |
32 | function x = remove(x,w,tol)
33 | x((abs(real(x)) w)) = [];
34 | end
35 |
36 | function [sys_remove] = correctPhase(sys_remove,sys)
37 | phase = angle(evalfr(sys_remove,0));
38 | phaseRef = angle(evalfr(sys,0));
39 | correction = arrayfun(@(x,y) (abs(x-y) < pi/2), angle(evalfr(sys_remove,0)), angle(evalfr(sys,0)));
40 | correction = double(correction);
41 | correction(correction == 0) = -1;
42 |
43 | sys_remove = sys_remove.*correction;
44 | end
45 |
46 |
--------------------------------------------------------------------------------
/Util/robust_rref.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [RR] = robust_rref(M)
18 | %ROBUST_RREF Summary of this function goes here
19 | % Detailed explanation goes here
20 |
21 | cm = cond(M);
22 | if(cm>1e10)
23 | warning(['M is badly conditioned: ' num2str(cm)])
24 | end
25 |
26 | [R,ja] = rref(M,1e-16);
27 | r = length(ja);
28 |
29 | % tol = max(size(M)) * eps(norm(M));
30 |
31 | jb = 1:size(M,2);
32 | jb(ja) = [];
33 |
34 | rankcheck = rank(M,1e-16) - r;
35 | if(rankcheck ~= 0)
36 | warning(['rank error: rank(M) = ' num2str(rank(M)) ', length(r) = ' num2str(r)]);
37 | end
38 |
39 | rankcheck = rank(M(1:r,ja)) - r;
40 | % tol = r * eps(norm(M(1:r,ja)));
41 |
42 | if(rankcheck ~= 0)
43 | warning(['rank error: rankcheck = ' num2str(rankcheck)]);
44 | end
45 |
46 | S = M(1:r,ja)\M(1:r,jb);
47 | % S = linsolve(M(1:r,ja),M(1:r,jb));
48 |
49 | RR = zeros(size(M));
50 | RR(1:r,ja) = eye(r,r);
51 | RR(1:r,jb) = S;
52 |
53 | d = R - RR;
54 | if(max(abs(d(:)))>1e-14)
55 | warning(['maximum tolerance surpassed' num2str(max(abs(d(:))))])
56 | end
57 |
58 | end
59 |
60 |
--------------------------------------------------------------------------------
/Util/rrefE.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [sys,T] = rrefE(sys)
18 | %RREFE Put the system dynamics in a canonical form
19 | % Returns an equivalent system with E in a reduced row echelon form
20 | %
21 | % INPUTS:
22 | % sys = system to be transformed
23 | %
24 | % OUTPUTS:
25 | % sys: the transformed system
26 | % T: Enew = T*Eold, Anew = T*Aold, Bnew = T*Bold
27 |
28 |
29 | [A,B,C,D,E] = dssdata(sys);
30 | T = eye(size(A));
31 |
32 | in = [E A B T];
33 | out = rref(in);
34 |
35 | e = size(E,2);
36 | b = size(B,2);
37 |
38 | sys.E = out(:,1:e);
39 | sys.A = out(:,e+1:2*e);
40 | sys.B = out(:,2*e+1:2*e+b);
41 | T = out(:,end-e+1:end);
42 |
43 | end
44 |
45 |
--------------------------------------------------------------------------------
/Util/shiftlow.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [sys_shift] = shiftlow(sys,varargin)
18 | %SHIFTLOW Shifts low frequency poles to the origin
19 | % Detailed explanation goes here
20 | if(nargin>1)
21 | pmin = varargin{1};
22 | else
23 | pmin = 1e-2;
24 | end
25 |
26 | flag = false;
27 | if ~isa(sys,'numlti')
28 | sys = std(sys);
29 | flag = true;
30 | end
31 |
32 | if ~all(size(sys)==1)
33 | for i = 1:size(sys,1)
34 | for k = 1:size(sys,2)
35 | sys(i,k) = shiftlow(sys(i,k),pmin);
36 | end
37 | end
38 | sys_shift = sys;
39 | else
40 | [z,p,k] = zpkdata(sys,'v');
41 |
42 | p_shift = arrayfun(@(x) shift(x,pmin), p);
43 | z_shift = arrayfun(@(x) shift(x,pmin), z);
44 |
45 | [~,Ip] = sort(abs(p_shift),'ascend');
46 | p_shift = p_shift(Ip);
47 | [~,Iz] = sort(abs(z_shift),'ascend');
48 | z_shift = z_shift(Iz);
49 |
50 | while(z_shift(1) == 0)
51 | p_shift(1) = [];
52 | z_shift(1) = [];
53 | end
54 |
55 | sys_shift = zpk(z_shift,p_shift,k);
56 | sys_shift = sys_shift.*(abs(evalfr(sys,j*1e5))./abs(evalfr(sys_shift,j*1e5)));
57 |
58 | % if(angle(evalfr(sys_shift,j*1e5) - angle(evalfr(sys,j*1e5))
59 |
60 | end
61 |
62 | if flag
63 | sys_shift = fromstd(sys_shift);
64 | end
65 |
66 | end
67 |
68 | function p = shift(p,varargin)
69 | if(nargin>1)
70 | pmin = varargin{1};
71 | else
72 | pmin = 1e-2;
73 | end
74 | p(abs(p).
16 |
17 | function [Orec, Crec] = ss_get_OC(sys, varargin)
18 | %SS_GET_OC Get observability and controlability matrix of LTI SS system
19 | % Detailed explanation goes here
20 |
21 | if(~isempty(varargin))
22 | ip = varargin{1};
23 | else
24 | if(isempty(sys.e)||(rank(sys.e,1e-6)==size(sys.a,1)))
25 | ip = 'p';
26 | else
27 | ip = 'i';
28 | end
29 | end
30 |
31 | switch ip
32 | case 'p'
33 | Orec = obsv(sys);
34 | Crec =
35 |
36 | case 'i'
37 | P = sys;
38 | Orec = zeros(size(P.A));
39 | Oeig = zeros(size(P.A));
40 | [Vae,Dae] = eig(P.A\P.E);
41 | Dae = diag(Dae);
42 | Vaeinv = pinv(Vae)%\eye(size(Vae));
43 | for k=0:(size(P.A,1)-1)
44 | Orec(k+1,:) = P.C*((P.A\P.E)^k);
45 | Oeig(k+1,:) = P.C*(Vaeinv*(diag(Dae.^k))*Vae);
46 | end
47 | % rorec = rank(Orec,1e-6)
48 | % roeig = rank(Oeig,1e-6)
49 |
50 | Crec = zeros(size(P.A));
51 | Ceig = zeros(size(P.A));
52 | Ainv = P.a\eye(size(P.a));
53 | [Va,Da] = eig(Ainv);
54 | Da = diag(Da);
55 | Vainv = pinv(Va);%\eye(size(Va));
56 | for k=0:(size(P.A,1)-1)
57 | Crec(:,k+1) = (Ainv^k)*P.B;
58 | Ceig(:,k+1) = Vainv*diag(Da.^(k))*Va*(P.B);
59 | end
60 | % rcrec = rank(Crec,1e-6)
61 | % rceig = rank(Ceig,1e-6)
62 |
63 | % r=min(ro,rc)
64 |
65 |
66 | end
67 |
68 |
69 |
70 | end
71 |
72 |
--------------------------------------------------------------------------------
/Util/ssprescale_test.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | clear all
18 | close all
19 | clc
20 |
21 | A = [-100 0 0;50000000 -100 100000;100 0 -0.002];
22 | fprintf('Original condition number of A: %e (rcond = %e)\n',cond(A),rcond(A));
23 | At = A;
24 |
25 | for k=1:40
26 | As = (At+At')/2;
27 |
28 | [P,D] = eig(As); Dq = diag(diag(D).^(1/4));
29 |
30 | T = P*Dq*(P'); Tinv = P*pinv(Dq)*(P');
31 | At = Tinv*At*T;
32 |
33 | fprintf('Current condition number of A: %e (rcond = %e)\n',cond(At),rcond(At));
34 | end
--------------------------------------------------------------------------------
/Util/sstransform.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [sys] = sstransform(sys,L,R)
18 | %SSTRANSFORM
19 | % Transform the system using left transform matrix L and right
20 | % transform R. The system will be of the form:
21 | % L*E*R*dot(x) = L*A*R*x + L*B*u;
22 | % y = C*R*x + D*u;
23 |
24 | if((all(size(L)==size(R)))&&(all(size(L)==size(sys.a))))
25 | sys.e = L*sys.e*R;
26 | sys.a = L*sys.a*R;
27 | sys.b = L*sys.b;
28 | sys.c = sys.c*R;
29 | else
30 | error('L and/or R are of incompatible size.');
31 | end
32 |
33 | end
34 |
35 |
--------------------------------------------------------------------------------
/Util/test_perfbode.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | clear
18 | close all
19 | clc
20 |
21 | H = tf({[1 0],[1];[2 0],[1 1]},{[2 1],[2 1];[3 5],[5 4]})
22 |
23 | perfbode(H,[])
--------------------------------------------------------------------------------
/Util/vector_expand.m:
--------------------------------------------------------------------------------
1 | % This file is part of LCToolbox.
2 | % (c) Copyright 2018 - MECO Research Team, KU Leuven.
3 | %
4 | % LCToolbox is free software: you can redistribute it and/or modify
5 | % it under the terms of the GNU Lesser General Public License as published
6 | % by the Free Software Foundation, either version 3 of the License, or
7 | % (at your option) any later version.
8 | %
9 | % LCToolbox is distributed in the hope that it will be useful,
10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | % GNU Lesser General Public License for more details.
13 | %
14 | % You should have received a copy of the GNU Lesser General Public License
15 | % along with LCToolbox. If not, see .
16 |
17 | function [code] = vector_expand(N,v)
18 | %VECTOR_EXPAND Expands a vector to its entries
19 | % Detailed explanation goes here
20 |
21 | code = cell(N,1);
22 | for k=1:N
23 | code{k,1} = [v '[' num2str(k-1) ']'];
24 | end
25 |
26 | end
27 |
28 |
--------------------------------------------------------------------------------