Inputs in my multibody model are road unevennes as function of distance the model is working fine for time simulation but when I linearize the system, then i get error saying no inputs or outputs defined.As In the picture:
https://drive.google.com/file/d/0B8AmxzbhEQ_FczFuaDNhQjlqVUE/view?usp=sharing
I defined combitable as a input and parameter then I get the error:
Translation of TRyViertalMbsa:
Component type specifier CombiTimeTable is a block, this cannot be combined with the prefix input .
Component declared as CombiTimeTable combiTimeTable in Modelica.Blocks.Sources
Conflicting causality for combiTimeTable (input ) and its element y(output )
How can I define inputs and outputs for the state spac system?
I think the problem is that you are asking Dymola to linearize the model including the boundary values (the input time series). What you really want is to linearize the model only and let Dymola perturbate the inputs in order to determine the linear model. See example model:
https://drive.google.com/file/d/0B8ojPn4YxnI9a1FFa0ozY2tlT1U/view?usp=sharing
So, you must replace the two CombiTimeTable with two input connectors (Modelica.Blocks.Interfaces.RealInput).
Also, you would probably want to add one or more output connectors (Modelica.Blocks.Interfaces.RealInput) via mechanical sensors - angle, position or whatever.
Operating points
If you want to linearize your model around a specific operating point different from zero, you should add these (constant) values to the inputs and subtract them from your outputs. I don't know if there is a smarter way to handle the operating points in Dymola's linearization function.
Best regards
Rene Just Nielsen
Related
How can you represent electric circuits like the one I have linked in Matlab? If the nodes were connected by transfer functions instead of capacitors, inductors and resistors this could be done by a matrix. Is there some similar method to represent electric circuits to find the relationships between the currents and voltages?
Circuit diagram:
Sure, I do this sort of thing all the time. There's no way getting around the fact that you'll have to do some math, though.
Use tf() to define your complex impedances (ie. 1/sC, sL, and R). Maybe write some short functions:
circuit_series(Z1,Z2) = Z1+Z2
circuit_parallel(Z1,Z2) = Z1*Z2/(Z1+Z2)
voltage_divider(Z1,Z2) = Z2/(Z1+Z2).
Use MATLAB to sum up the total complex impedance seen by vi. You'll have to solve for the voltages at the intermediate nodes with the voltage divider equation before you can get to vo. Once you have the transfer function vo/vi, you can do fun things such as given an arbitrary vi waveform over time, compute the resulting vo waveform (assuming some initial conditions!).
Hopefully, I will be able to explain my question well.
I am working on Nonlinear model predictive control implementation.
I have got 3 files:
1). a simulink slx file which is basically a nonlinear pendulum model.
2). A function file, to get the cost function from the simulink model.
3). MPC code.
code snippet of cost function
**simOut=sim('NonlinearPendulum','StopTime', num2str(Np*Ts));**
%Linearly interpolates X to obtain sampled output states at time instants.
T=simOut.get('Tsim');
X=simOut.get('xsim');
xt=interp1(T,X,linspace(0,Np*Ts,Np+1))';
U=U(1:Nu);
%Quadratic cost function
R=0.01;
J=sum(sum((xt-repmat(r,[1 Np+1])).*(xt-repmat(r,[1 Np+1]))))+R*(U-ur)*...
(U-ur)';
Now I take this cost function and optimize it using fmincon to generate a sequence of inputs to be applied to the model, using my MPC code.
A code snippet of my MPC code.
%Constraints -1<=u(t)<=1;
Acons=[eye(Nu,Nu);-eye(Nu,Nu)];
Bcons=[ones(Nu,1);ones(Nu,1)];
options = optimoptions(#fmincon,'Algorithm','active-set','MaxIter',100);
warning off
for a1=1:nf
X=[]; %Prediction output
T=[]; %Prediction time
Xsam=[];
Tsam=[];
%Nonlinear MPC controller
Ubreak=linspace(0,(Np-1)*Ts,Np); %Break points for 1D lookup, used to avoid
% several calls/compilations of simulink model in fmincon.
**J=#(v) pendulumCostFunction(v,x0,ur,r(:,a1),Np,Nu,Ts);**
U=fmincon(J,U0,Acons,Bcons,[],[],[],[],[],options);
%U=fmincon(J,U0,Acons,Bcons);
U0=U;
UUsam=[UUsam;U(1)];%Apply only the first selected input
%Apply the selected input to plant.
Ubreak=[0 Ts]; %Break points for 1D lookup
U=[UUsam(end) UUsam(end)];
**simOut=sim('NonlinearPendulum','StopTime', num2str(Ts));**
In both the codes, I have marked the times we call our simulink model. Now, issue is that to run this whole simulation for just 5 seconds it takes around 7-8 minutes on my windows machine, MATLAB R2014B.
Is there a way to optimize this? As, I am planning to extend this algorithm to 9th order system unlike 2nd order pendulum model.
If, anyone has suggestion on using simulink coder to generate C code:
I have tried that, and the problem I face is that I don't know what to do with the several files generated. Please be as detailed as possible.
From the code snippets, it appears that you are solving a linear time invariant model with a quadratic objective. Here is some MATLAB (and Python) code for an overhead crane pendulum and inverted pendulum, both with state space linear models and quadratic objectives.
One of the ways to make it run faster is to avoid a Simulink interface and a shooting method for solving the MPC. A simultaneous method with orthogonal collocation on finite elements is faster and also enables higher index DAE model forms if you'd like to use a nonlinear model.
I believe I am doing something fundamentally wrong when trying to import and test a transfer function in Simulink which was created within the System Identification Toolbox (SIT).
To give a simple example of what I am doing.
I have an input which is an offset sinusoidal wave from 12 seconds to 25 seconds with an amplitude of 1 and a frequency of 1.5rad/s which gives a measured output.
I have used SIT to create a simple 2 pole 1 zero transfer function which gives the following agreement:
I have then tried to import this transfer function into Simulink for investigation in the following configuration which has a sinusoidal input of frequency 1.5rad/s and a starting t=12. The LTI system block refers to the transfer function variable within the workspace:
When I run this simulation for 13 seconds the input to the block is as expected but the post transfer function signal shows little agreement with what would be expected and is an order of magnitude out.
pre:
post:
Could someone give any insight into where I am going wrong and why the output from the tf in simulink shows little resemblance to the model output displayed in the SIT. I have a basic grasp of control theory but I am struggling to make sense of this.
This could be due to different initial conditions used in SimuLink and the SI Toolbox, the latter should estimate initial conditions with the model, while Simulink does nothing special with initial conditions unless you specify them yourself.
To me it seems that your original signals are in periodic regime, since your output looks almost like a sine wave as well. In periodic regime, initial conditions have little effect. You can verify my assumption by simulating your model for a longer amount of time: if at the end, your signal reaches the right amplitude and phase lag as in your data, you will know that the initial conditions were wrong.
In any case, you can get the estimated initial state from the toolbox, I think using the InitialState property of the resulting object.
Another thing that might go wrong, is the time discretization that you use in Simulink in case you estimated a continuous time model (one in the Laplace variable s, not in z or q).
edit: In that case I would recommend you check what Simulink uses to discretize your CT model, by using c2d in MATLAB and a setup like the one below in Simulink. In MATLAB you can also "simulate" the response to a CT model using lsim, where you have to specify a discretization method.
This set-up allows you to load in a CT model and a discretized variant (in this case a state-space representation). By comparing the signals, you can see whether the discretization method you use is the same one that SimuLink uses (this depends on the integration method you set in the settings).
I have set up a model using SimMechanics. It outputs data at the times where the solver steps to. Is there any possibility to have some kind of dense output such that it is possible to interpolate these data to get the solution at arbitrary points without losing the high order of the integrator?
In Matlab this is easily possible using the function deval after the integration of one of the built-in ODE integrators.
In SimMechanics I can select these integrators, too. Is there some kind of analouge way to deval?
Yes, it's possible, although it's a Simulink functionality, not specific to SimMechanics. In the Configuration Parameters of the model, you can set the model to Produce Specified Output Only (see http://www.mathworks.co.uk/help/simulink/gui/data-import-export-pane.html#bq9_fhw-1), under Data Import/Export. This way, only the outputs you specify will be produced regardless of the time steps taken by the solver.
I have a model in Simulink describing the behaviour of a system depending on time dependent inputs and model parameters, that can be described as f(a,t).
I have to optimise the model parameters (a) so that the maximum value of the function (f) over a determined time period (T) is below a cetrain value (f0). The problem can be described as to find
MAX(a) SUCH THAT MAX[f(a,t)] < f0 FOR EACH t BELONGING TO T
I have already solved the problem with a MATLAB script, but I want to know if it is possible to do it directly in SIMULINK
Thanks
You need the Simulink Design Optimizer toolbox.