How to display graph data by vehicle center of gravity in the Data Inspector in Simulink?
Hi I am working my way through the Vehicle Steering Gain at Different Speeds example.
In that example,
vmax = [45, 50, 55];
numExperiments = length(vmax);
to show the values from speeds 45 to 55 in the data inspector. I would like to replace the declared speed values with the vehicle’s center of gravity (VEH.FrontAxlePositionfromCG, VEH.RearAxlePositionfromCG, VEH.HeightCG) specified in parentheses and show them in the data inspector.
So, I entered the example code by changing it to the code below.
mdl = ‘ISReferenceApplication’;
sim(mdl);
mdl = ‘ISReferenceApplication’;
ph=get_param(‘ISReferenceApplication/Slowly Increasing Steer’,’PortHandles’);
set_param(ph.Outport(1),’DataLogging’,’on’);
ph=get_param(‘ISReferenceApplication/Passenger Vehicle’,’PortHandles’);
set_param(ph.Outport(1),’DataLogging’,’on’);
set_param([mdl ‘/Visualization/ISO 15037-1:2006′],’Measurement’,’Enable’);
FrontAxlePositionfromCG = 1.818; % Specify the actual value for FrontAxlePositionfromCG
RearAxlePositionfromCG = 1.8048; % Specify the actual value for RearAxlePositionfromCG
HeightCG = 0.1608; % Specify the actual value for HeightCG
% Define the maximum speeds
vmax = [FrontAxlePositionfromCG, RearAxlePositionfromCG, HeightCG];
numExperiments = length(vmax);
% (forgot part)
for idx = numExperiments:-1:1
in(idx) = Simulink.SimulationInput(mdl);
in(idx) = in(idx).setBlockParameter([mdl ‘/Slowly Increasing Steer’], …
‘xdot_r’, num2str(vmax(idx)));
end
save_system(mdl)
tic;
simout = parsim(in,’ShowSimulationManager’,’on’);
toc;
% Create SDI run objects
simoutRun = cell(numExperiments, 1);
for idx = 1:numExperiments
simoutRun{idx} = Simulink.sdi.Run.create;
simoutRun{idx}.Name = [‘CG: FrontAxle = ‘, num2str(FrontAxlePositionfromCG(idx)), …
‘, RearAxle = ‘, num2str(RearAxlePositionfromCG(idx)), …
‘, Height = ‘, num2str(HeightCG(idx))];
end
% Display signals in SDI
Simulink.sdi.view;
Simulink.sdi.setSubPlotLayout(5,1);
% Plot signals
for idx = 1:numExperiments
% Extract signals
msignal = getSignalsByName(simoutRun{idx}, ‘xdot_mph’);
ssignal = getSignalsByName(simoutRun{idx}, ‘SteerAngle’);
asignal = getSignalsByName(simoutRun{idx}, ‘Lateral acceleration’);
xsignal = getSignalsByName(simoutRun{idx}, ‘Passenger Vehicle:1.Body.InertFrm.Cg.Disp.X’);
ysignal = getSignalsByName(simoutRun{idx}, ‘Passenger Vehicle:1.Body.InertFrm.Cg.Disp.Y’);
% Define signal colors
sigcolor = [0 1 0; 0 0 1; 1 0 1];
% Set line colors
msignal.LineColor = sigcolor(idx,:);
ssignal.LineColor = sigcolor(idx,:);
asignal.LineColor = sigcolor(idx,:);
xsignal.LineColor = sigcolor(idx,:);
ysignal.LineColor = sigcolor(idx,:);
% Plot signals
plotOnSubPlot(msignal, 1, 1, true);
plotOnSubPlot(ssignal, 2, 1, true);
plotOnSubPlot(asignal, 3, 1, true);
plotOnSubPlot(xsignal, 4, 1, true);
plotOnSubPlot(ysignal, 5, 1, true);
end
When I enter that code, I’m getting an error code like the one below. My guess is that the error log is generated because the index created and the number of elements in the column do not match.
Index exceeds the number of array elements. Index must not exceed 1.
How can I fix it…?Hi I am working my way through the Vehicle Steering Gain at Different Speeds example.
In that example,
vmax = [45, 50, 55];
numExperiments = length(vmax);
to show the values from speeds 45 to 55 in the data inspector. I would like to replace the declared speed values with the vehicle’s center of gravity (VEH.FrontAxlePositionfromCG, VEH.RearAxlePositionfromCG, VEH.HeightCG) specified in parentheses and show them in the data inspector.
So, I entered the example code by changing it to the code below.
mdl = ‘ISReferenceApplication’;
sim(mdl);
mdl = ‘ISReferenceApplication’;
ph=get_param(‘ISReferenceApplication/Slowly Increasing Steer’,’PortHandles’);
set_param(ph.Outport(1),’DataLogging’,’on’);
ph=get_param(‘ISReferenceApplication/Passenger Vehicle’,’PortHandles’);
set_param(ph.Outport(1),’DataLogging’,’on’);
set_param([mdl ‘/Visualization/ISO 15037-1:2006′],’Measurement’,’Enable’);
FrontAxlePositionfromCG = 1.818; % Specify the actual value for FrontAxlePositionfromCG
RearAxlePositionfromCG = 1.8048; % Specify the actual value for RearAxlePositionfromCG
HeightCG = 0.1608; % Specify the actual value for HeightCG
% Define the maximum speeds
vmax = [FrontAxlePositionfromCG, RearAxlePositionfromCG, HeightCG];
numExperiments = length(vmax);
% (forgot part)
for idx = numExperiments:-1:1
in(idx) = Simulink.SimulationInput(mdl);
in(idx) = in(idx).setBlockParameter([mdl ‘/Slowly Increasing Steer’], …
‘xdot_r’, num2str(vmax(idx)));
end
save_system(mdl)
tic;
simout = parsim(in,’ShowSimulationManager’,’on’);
toc;
% Create SDI run objects
simoutRun = cell(numExperiments, 1);
for idx = 1:numExperiments
simoutRun{idx} = Simulink.sdi.Run.create;
simoutRun{idx}.Name = [‘CG: FrontAxle = ‘, num2str(FrontAxlePositionfromCG(idx)), …
‘, RearAxle = ‘, num2str(RearAxlePositionfromCG(idx)), …
‘, Height = ‘, num2str(HeightCG(idx))];
end
% Display signals in SDI
Simulink.sdi.view;
Simulink.sdi.setSubPlotLayout(5,1);
% Plot signals
for idx = 1:numExperiments
% Extract signals
msignal = getSignalsByName(simoutRun{idx}, ‘xdot_mph’);
ssignal = getSignalsByName(simoutRun{idx}, ‘SteerAngle’);
asignal = getSignalsByName(simoutRun{idx}, ‘Lateral acceleration’);
xsignal = getSignalsByName(simoutRun{idx}, ‘Passenger Vehicle:1.Body.InertFrm.Cg.Disp.X’);
ysignal = getSignalsByName(simoutRun{idx}, ‘Passenger Vehicle:1.Body.InertFrm.Cg.Disp.Y’);
% Define signal colors
sigcolor = [0 1 0; 0 0 1; 1 0 1];
% Set line colors
msignal.LineColor = sigcolor(idx,:);
ssignal.LineColor = sigcolor(idx,:);
asignal.LineColor = sigcolor(idx,:);
xsignal.LineColor = sigcolor(idx,:);
ysignal.LineColor = sigcolor(idx,:);
% Plot signals
plotOnSubPlot(msignal, 1, 1, true);
plotOnSubPlot(ssignal, 2, 1, true);
plotOnSubPlot(asignal, 3, 1, true);
plotOnSubPlot(xsignal, 4, 1, true);
plotOnSubPlot(ysignal, 5, 1, true);
end
When I enter that code, I’m getting an error code like the one below. My guess is that the error log is generated because the index created and the number of elements in the column do not match.
Index exceeds the number of array elements. Index must not exceed 1.
How can I fix it…? Hi I am working my way through the Vehicle Steering Gain at Different Speeds example.
In that example,
vmax = [45, 50, 55];
numExperiments = length(vmax);
to show the values from speeds 45 to 55 in the data inspector. I would like to replace the declared speed values with the vehicle’s center of gravity (VEH.FrontAxlePositionfromCG, VEH.RearAxlePositionfromCG, VEH.HeightCG) specified in parentheses and show them in the data inspector.
So, I entered the example code by changing it to the code below.
mdl = ‘ISReferenceApplication’;
sim(mdl);
mdl = ‘ISReferenceApplication’;
ph=get_param(‘ISReferenceApplication/Slowly Increasing Steer’,’PortHandles’);
set_param(ph.Outport(1),’DataLogging’,’on’);
ph=get_param(‘ISReferenceApplication/Passenger Vehicle’,’PortHandles’);
set_param(ph.Outport(1),’DataLogging’,’on’);
set_param([mdl ‘/Visualization/ISO 15037-1:2006′],’Measurement’,’Enable’);
FrontAxlePositionfromCG = 1.818; % Specify the actual value for FrontAxlePositionfromCG
RearAxlePositionfromCG = 1.8048; % Specify the actual value for RearAxlePositionfromCG
HeightCG = 0.1608; % Specify the actual value for HeightCG
% Define the maximum speeds
vmax = [FrontAxlePositionfromCG, RearAxlePositionfromCG, HeightCG];
numExperiments = length(vmax);
% (forgot part)
for idx = numExperiments:-1:1
in(idx) = Simulink.SimulationInput(mdl);
in(idx) = in(idx).setBlockParameter([mdl ‘/Slowly Increasing Steer’], …
‘xdot_r’, num2str(vmax(idx)));
end
save_system(mdl)
tic;
simout = parsim(in,’ShowSimulationManager’,’on’);
toc;
% Create SDI run objects
simoutRun = cell(numExperiments, 1);
for idx = 1:numExperiments
simoutRun{idx} = Simulink.sdi.Run.create;
simoutRun{idx}.Name = [‘CG: FrontAxle = ‘, num2str(FrontAxlePositionfromCG(idx)), …
‘, RearAxle = ‘, num2str(RearAxlePositionfromCG(idx)), …
‘, Height = ‘, num2str(HeightCG(idx))];
end
% Display signals in SDI
Simulink.sdi.view;
Simulink.sdi.setSubPlotLayout(5,1);
% Plot signals
for idx = 1:numExperiments
% Extract signals
msignal = getSignalsByName(simoutRun{idx}, ‘xdot_mph’);
ssignal = getSignalsByName(simoutRun{idx}, ‘SteerAngle’);
asignal = getSignalsByName(simoutRun{idx}, ‘Lateral acceleration’);
xsignal = getSignalsByName(simoutRun{idx}, ‘Passenger Vehicle:1.Body.InertFrm.Cg.Disp.X’);
ysignal = getSignalsByName(simoutRun{idx}, ‘Passenger Vehicle:1.Body.InertFrm.Cg.Disp.Y’);
% Define signal colors
sigcolor = [0 1 0; 0 0 1; 1 0 1];
% Set line colors
msignal.LineColor = sigcolor(idx,:);
ssignal.LineColor = sigcolor(idx,:);
asignal.LineColor = sigcolor(idx,:);
xsignal.LineColor = sigcolor(idx,:);
ysignal.LineColor = sigcolor(idx,:);
% Plot signals
plotOnSubPlot(msignal, 1, 1, true);
plotOnSubPlot(ssignal, 2, 1, true);
plotOnSubPlot(asignal, 3, 1, true);
plotOnSubPlot(xsignal, 4, 1, true);
plotOnSubPlot(ysignal, 5, 1, true);
end
When I enter that code, I’m getting an error code like the one below. My guess is that the error log is generated because the index created and the number of elements in the column do not match.
Index exceeds the number of array elements. Index must not exceed 1.
How can I fix it…? vehicle steering gain at different speeds, simulink MATLAB Answers — New Questions