How to display graph data by vehicle center of gravity in the Data Inspector in Simulink?
1 次查看(过去 30 天)
显示 更早的评论
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.
But I don't know how...
In the Vehicle Steering Gain at Different Speeds example above, the command to represent the data inspector based on speed would look like the command below.
for idx = 1:numExperiments
% Create sdi run object
simoutRun(idx)=Simulink.sdi.Run.create;
simoutRun(idx).Name=['Velocity = ', num2str(vmax(idx))];
add(simoutRun(idx),'vars',simout(idx));
end
sigcolor=[0 1 0;0 0 1;1 0 1];
for idx = 1:numExperiments
% Extract the lateral acceleration, position, and steering
msignal(idx)=getSignalsByName(simoutRun(idx), 'xdot_mph');
msignal(idx).LineColor =sigcolor((idx),:);
ssignal(idx)=getSignalsByName(simoutRun(idx), 'SteerAngle');
ssignal(idx).LineColor =sigcolor((idx),:);
asignal(idx)=getSignalsByName(simoutRun(idx), 'Lateral acceleration');
asignal(idx).LineColor =sigcolor((idx),:);
xsignal(idx)=getSignalsByName(simoutRun(idx), 'Passenger Vehicle:1.Body.InertFrm.Cg.Disp.X');
xsignal(idx).LineColor =sigcolor((idx),:);
ysignal(idx)=getSignalsByName(simoutRun(idx), 'Passenger Vehicle:1.Body.InertFrm.Cg.Disp.Y');
ysignal(idx).LineColor =sigcolor((idx),:);
end
Simulink.sdi.view
Simulink.sdi.setSubPlotLayout(5,1);
for idx = 1:numExperiments
% Plot the lateral position, steering angle, and lateral acceleration
plotOnSubPlot(msignal(idx),1,1,true);
plotOnSubPlot(ssignal(idx),2,1,true);
plotOnSubPlot(asignal(idx),3,1,true);
plotOnSubPlot(xsignal(idx),4,1,true);
plotOnSubPlot(ysignal(idx),5,1,true);
end
Translated with www.DeepL.com/Translator (free version)
7 个评论
Deepu
2024-4-24
It seems like you're trying to adjust the center of gravity (CG) of a vehicle in a simulation and compare the results with different CG positions. To fix the issue you mentioned, where the HeightCG value is being recognized as a velocity value, you need to ensure that the HeightCG value is correctly assigned.
Assuming that the HeightCG value represents the vertical position of the CG, you should ensure that it's not inadvertently interpreted as a velocity value. You can do this by properly defining the HeightCG variable as a position value rather than a velocity value.
Here's how you can modify the code to correctly set the HeightCG value:
mdl = 'ISReferenceApplication';
sim(mdl);
% Define the maximum speeds and CG positions
FrontAxlePositionfromCG = 1.818; % 20% forward
RearAxlePositionfromCG = 1.8048; % 20% backward
HeightCG = 0.1608; % Original CG height
DownAxlePositionfromCG = 0.1286; % 20% down
% Define the maximum speeds
vmax = [FrontAxlePositionfromCG, RearAxlePositionfromCG, HeightCG, DownAxlePositionfromCG];
numExperiments = length(vmax);
% Create simulation inputs for each experiment
in = cell(numExperiments, 1);
for idx = 1:numExperiments
in{idx} = Simulink.SimulationInput(mdl);
% Set the block parameters for each experiment
if idx == 1 % Original CG position
xdot_r_value = num2str(50); % Fixed speed
else
xdot_r_value = num2str(vmax(idx));
end
in{idx} = in{idx}.setBlockParameter([mdl '/Slowly Increasing Steer'], ...
'xdot_r', xdot_r_value);
end
% Run simulations for all experiments
tic;
simout = parsim(in, 'ShowSimulationManager', 'on');
toc;
% Visualize results...
In this modified code:
- I've included the DownAxlePositionfromCG variable to represent a 20% downward shift in the CG position.
- I've adjusted the vmax array to include all CG position values.
- During simulation input creation, I set the xdot_r parameter to the appropriate velocity value based on the experiment's CG position.
Make sure to verify that the HeightCG variable is indeed representing the correct CG position in your simulation model. Adjust the values and variables as needed to match your specific simulation setup.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!