Torque Simulink model to script file

1 view (last 30 days)
Mohsina Zafar
Mohsina Zafar on 4 Jul 2019
I am trying to code a Simulink model. I am using 2 sec simulation time and my input has values against the time 0:0.1:2
The output I am getting does not seem right. For 1st time instance, input size is 1x3 and I want the output size to be 1x3 (but it is giving 21x3 size output). For the 2nd instance, 2nd input should be used and 1st output should be used for feedback.
I want the code to work just as standalone Simulink model does.
Code:
load('Motor_Param.mat')
t = 0:0.1:10; % start at initial time equal to zero continue to 10
T_o = [0.05*(10-t);0.04*(10-t);0.03*(10-t)]'; % note transpose, columns of T_o are channels
T_d = zeros(size(T_o));
T_e = T_d-T_o;
% define PID controller parameters
Kp = 100; % proportional gain
Ki = 0; % integral gain
Kd = 10; % derivative gain
Tf = 100; % filter time constant
c = pid(Kp,Ki,Kd,Tf); % individual pid controller
C = [c 0 0;0 c 0;0 0 c]; % identical pid controllers for each channel
% simulate response of pid controller to error signal
T_u = lsim(C,T_e,t);
T_u=[[1:101]' T_u]
a = sim('Motor_Control','SimulationMode','normal');
out = a.get('T_l')
out.Data
slx and .mat files are attached.

Answers (0)

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!