필터 지우기
필터 지우기

How to display graph data by vehicle center of gravity in the Data Inspector in Simulink?

조회 수: 3 (최근 30일)
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.
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
상우
상우 2024년 4월 24일
편집: 상우 2024년 4월 24일
I understand what you are saying, but I see above that the direction we have been going is going in the opposite direction of what I want to do. My goal is to compare the results of shifting the center of gravity of the vehicle by 20% forward, 20% backward, and 20% down, respectively, with the original data without shifting the center of gravity, while keeping the speed itself fixed at 50.
Above is a picture of the vehicle movement in the third simulation, which shows a velocity of -0, indicating that the vehicle is moving backwards, which is likely due to the 0.1608 entered as the last HeightCG value being recognized as a velocity value.
If I were to finally solve the challenge, the result I would expect to see would look like the following photo.
I think this is where the fix should start:
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
Thank you!!
Deepu
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개)

카테고리

Help CenterFile Exchange에서 Get Started with Vehicle Dynamics Blockset에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by