-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simout2timetable does not work for multiple output ports
- Loading branch information
Showing
5 changed files
with
107 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function tt= constructTimeTable(time,data) | ||
%CONSTRUCTTIMETABLE internal method for dispatching timetable construction | ||
|
||
arguments | ||
time {mustBeNumeric} | ||
data | ||
end | ||
|
||
if isa(data, "Simulink.SimulationData.Dataset") | ||
tt = constructTimeTableFromDataset(data); | ||
else | ||
tt = constructTimeTableFromNumericTimeVector(time, data); | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function tt = constructTimeTableFromDataset(data) | ||
%CONSTRUCTTIMETABLEFROMDATASET internal method for constructing a timetable | ||
%from a Simulink dataset | ||
|
||
arguments | ||
data Simulink.SimulationData.Dataset | ||
end | ||
|
||
tt = arrayfun(@(n) sig2tt(data{n}),1:data.numElements, "UniformOutput",false); | ||
|
||
end | ||
|
||
function tt = sig2tt(sig) | ||
tt = constructTimeTableFromNumericTimeVector(sig.Values.Time,sig.Values.Data); | ||
if sig.Name == "" % unammed signal | ||
% extract the name from the signal port and index | ||
tt.Properties.VariableNames = {sig.PortType + "_" + sig.PortIndex}; | ||
else | ||
tt.Properties.VariableNames = {sig.Name}; | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
classdef tBasic_ilc < matlab.unittest.TestCase | ||
|
||
properties | ||
Model = "mBasic_ilc" | ||
end | ||
|
||
methods (TestMethodSetup) | ||
function loadmodel(testCase) | ||
load_system(testCase.Model) | ||
end | ||
end | ||
|
||
methods | ||
function closemodel(testCase) | ||
evalin("base", "clear sys_dt T_end Ts") | ||
close_system(testCase.Model, 0) | ||
end | ||
end | ||
|
||
methods (Test) | ||
function verifyErrorFreeConstruction(testCase) | ||
%% System | ||
m = 5; %kg | ||
Ts = 0.1e-3; % 0.1 ms | ||
s = tf('s'); | ||
sys_ct = 1/(m*s^2); | ||
sys_dt = c2d(sys_ct,Ts); | ||
assignin("base", "sys_dt", sys_dt) | ||
|
||
%% Controller | ||
%z = tf('z',Ts); | ||
Kp = 571; | ||
Kd = 51.1; | ||
%C = Kp+Kd*(z-1)/Ts; | ||
|
||
set_param(testCase.Model + "/" + "Gain", "Gain", string(m)) | ||
set_param(testCase.Model + "/" + "PID Controller", "P", string(Kp)) | ||
set_param(testCase.Model + "/" + "PID Controller", "D", string(Kd)) | ||
|
||
%% Simulation | ||
T_end = 1; | ||
assignin("base", "T_end", T_end) | ||
assignin("base", "Ts", Ts) | ||
|
||
t = 0:Ts:T_end; | ||
[ref, vel, acc, ~] = quinticpolytraj([0 0.1 0.1 0],[0 0.25*T_end 0.75*T_end T_end], t); | ||
% plot(t,ref,t,vel,t,acc) | ||
in = Simulink.SimulationInput(testCase.Model); | ||
in = in.setExternalInput([t',ref',vel',acc']); | ||
simout = sim(in); | ||
testCase.verifyWarningFree(@() simout2timetable(simout)); | ||
end | ||
end | ||
end |