Analysis for Average Wear of Tires in Automobile
This example shows how to use an analysis function to calculate the average wear of the tires in your automotive system architecture model. You can specify Wear
as an instance-specific parameter for each usage of the mWheel.slx
model reference linked to a component in System Composer™.
Open Vehicle Model
Open the automotive system architecture mAuto.slx
.
systemcomposer.openModel("mAuto");
This architecture model of a simple car contains two top-level components, which represent two axles. Each axle has a nested architecture and two wheels.
Write Analysis Function
You can perform the analysis on an instance model using an analysis function. For more information about different analysis functions, see Analysis Function Constructs.
This analysis function calculates the average wear of all the tires in the automobile.
function calculateAverages(instance,varargin) % Analysis function calculating the average wear of tires in a vehicle % Pass the number of tires as an input to the analysis function if numel(varargin) > 0 numTires = eval(varargin{1}); end % Get the architecture instance as a place to accumulate the total wear using a % stereotype property if instance.isArchitecture archInst = instance; else % Get the architecture instance from the path of the node currently being % iterated instName = strsplit(instance.QualifiedName,'/'); archInst = systemcomposer.analysis.lookup(string(instName{1})); end if instance.isComponent && any(instance.getParameterNames.matches("Wear")) % Get the stored stereotype property value on the architecture instance accumulatedValue = archInst.getValue('AxleProfile.Metrics.total_wear'); % Get the evaluated parameter value from the instance currentValue = instance.getEvaluatedParameterValue("Wear"); % Update the accumulated value newValue = accumulatedValue + currentValue; % Update the stereotype property value on the architecture instance archInst.setValue('AxleProfile.Metrics.total_wear',num2str(newValue)); if newValue > 0 fprintf(sprintf("Average wear of tires: %f\n", ... newValue/numTires)); end end end
Instantiate Architecture Model with Analysis Function
To calculate the average wear of the tires in your architecture model, instantiate the model to create a snapshot, or instance model from which to perform calculations. To launch the Instantiate Architecture Model tool, from the System Composer toolstrip, select Modeling > View > Analysis Model. Select the AxleProfile
profile. Doing so enables you to display your analysis result in a property value later. Use the folder to navigate to and insert the function calculateAverages.m
in the Analysis function box. Input 4
in the Function arguments box to indicate that the model has four wheels. Then, click Instantiate.
Analyze Instance Model Calculate Average Wear
After you instantiate your architecture model, the Analysis Viewer tool launches. Click Analyze to analyze your instance model using the provided analysis function calculateAverages
.
The total_wear
cell on the architecture instance level for mAuto
is highlighted in yellow because total_wear
is a calculated value of all the instance properties of each wheel component instance on the instance model. The total_wear
value 0.0595
represents the total wear of all the tires on the car. In the MATLAB® Command Window, the last printout also shows the average wear of the tires on the car.
Average wear of tires: 0.014875
Average wear is a metric to measure overall tire durability and an indication for when to replace the tires. The average wear of the tires is about 0.0149
.
See Also
Tools
Objects
Functions
instantiate
|deleteInstance
|update
|refresh
|save
|getEvaluatedParameterValue
|getParameterNames