How to modify Mass in EvReferenceApplication to be "Mass + adder"?

2 visualizaciones (últimos 30 días)
Mark
Mark el 13 de Nov. de 2023
Editada: Akshat Dalal el 26 de Dic. de 2023
I'm trying to use the EvReferenceApplication mostly as-is, as a starting point for evaluating the impact of adding things to the vehicle.
Using Mass as an example, what I would like to do is maintain a separate "MassAdder" variable that accumulates all of the weights I'm adding. When the Vehicle Simulation is run, I would like it to use "Mass + MassAdder" wherever it currently uses "Mass" as a parameter.
This is more of an editor/scripting/workspace question.
Is there an easy way to modify EvReferenceApplication to make this substitution?
Thanks!

Respuestas (1)

Akshat Dalal
Akshat Dalal el 24 de Dic. de 2023
Editada: Akshat Dalal el 26 de Dic. de 2023
Hi Mark,
I understand that you want to modify the 'EvReferenceApplication' to accumulate all the individual weights into a single variable 'MassAdder' and then replace the individual weights with the sum of that weight and 'MassAdder'.
This is possible and you could do it using the following approach:
  • Create variables 'Mass1', 'Mass2', 'Mass3', etc., in the MATLAB base workspace, each assigned to the value of an individual weight. Then, configure your model to use these variables instead of hardcoded weight values or other variables.
  • Initialize 'MassAdder' with 0 and then find all variables in base workspace of the form 'Mass1', 'Mass2', 'Mass3', etc., and accumulate them in 'MassAdder'. You could use the following script to do so:
MassAdder = 0;
Masses = who('-regexp', 'param');
for i = 1:length(Masses)
Mass = evalin("base", Masses{i});
MassAdder = MassAdder + Mass;
end
  • Find all blocks in the model which reference the individual mass variables and then replace these with the variable 'Mass1 + MassAdder'. You could find and modify the blocks by tweaking the following script:
% Set the name of your model
modelName = 'EvReferenceApplication'; % Replace with your model name
% Load the model into memory (without opening the UI)
load_system(modelName);
% Find all blocks in the model
allBlocks = find_system(modelName, 'Type', 'Block');
% Loop through all blocks and check their parameters
for i = 1:length(allBlocks)
block = allBlocks{i};
blockHandle = get_param(block, 'Handle');
blockVal = get(blockHandle); % Use this to check and modify the block parameters if
% they use Mass values. You could also use get_param/set_param on the block.
end
Hope this helps!

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by