Documentation

smimport

Generate a Simscape Multibody model from an XML import file

Syntax

  • [H,dataFileName] = smimport(xmlFileName)
    example
  • [H,dataFileName] = smimport(xmlFileName,Name,Value)
    example

Description

example

[H,dataFileName] = smimport(xmlFileName) generates a Simscape™ Multibody™ model and supporting data file from an XML import file. H is the model handle and dataFileName is the name of the supporting data file. By default, the model and data file are named after the XML import file.

xmlFileName is the name of the XML import file. The file extension is optional. You can append the full or relative file path to the file name. In the absence of a file path, the function searches for the file name on the MATLAB® path. If the XML import file name violates MATLAB naming rules, the model and data file take on modified versions of the XML file name.

The XML import file details the structure and properties of the multibody model you are importing. To be valid. the file must conform to the published Simscape Multibody XML schema. If you use a supported CAD application, you can generate a valid XML import file using the Simscape Multibody Link CAD plug-in.

The plug-in exports assemblies in two formats, one for Simscape Multibody models, the other for Simscape Multibody First Generation models. The smimport function accepts only XML import files generate for Simscape Multibody models. For Simscape Multibody First Generation models, use mech_import instead.

The data file provides the numerical values of the block parameters in the form of a MATLAB data structure. Blocks in the imported model reference the MATLAB structure fields through the model workspace. The default structure name is smiData.

example

[H,dataFileName] = smimport(xmlFileName,Name,Value) adds options for specifying the import mode and various file names. Set ImportMode to dataFile in order to generate a new data file for a previously imported model. Specify PriorDataFile to catch unexpected changes to the XML import file, such as part name changes or the addition and deletion of parts.

Input Arguments

collapse all

XML import file name. The XML import file provides Simscape Multibody software a detailed description of the multibody model to generate. The file extension and path are optional parts of the argument. In the absence of a file path, the function searches for the file name on the current MATLAB path. The file name must conform to the MATLAB naming conventions.

Example: 'robotto'

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Option to generate a new model or update existing model data. Set ImportMode to modelAndDataFile to generate a new model and data file. Set ImportMode to dataFile to generate a new data file for a previously imported model. The function does not update the block diagram itself. If you do not specify ImportMode, the function runs in modelAndDataFile mode.

Example: 'dataFile'

Name of the Simscape Multibody model to generate. The model is saved in SLX format. This argument is not valid when ImportMode is set to dataFile. If you do not specify ModelName, the model file is named after the XML import file. If the XML import file name is inconsistent with MATLAB naming conventions, a modified version is used instead.

Example: 'robotto'

Name of the supporting parameter data file. The data file is an M file with the block parameter values referenced in the imported Simscape Multibody model. If you do not specify DataFileName, the data file is named after the XML import file. If the XML import file name is inconsistent with MATLAB naming conventions, a modified version is used instead.

Example: 'robottos_new_data'

Name of the last parameter data file associated with a previously imported model. The prior data file helps to identify changes requiring special attention, such as new physical units, added and deleted components, and model topology changes. This argument is valid only when ImportMode is set to dataFile.

Example: 'robottos_original_data'

Name of the MATLAB data structure provided in the parameter data file. This structure contains the numerical values of all block parameters in the imported Simscape Multibody model. If you do not specify VariableName, the data structure is named smiData.

Example: 'robottosData'

Output Arguments

collapse all

Model handle returned as a double. Use the model handle to get or set model parameters, for example, using the get_param and set_param functions.

Name of the parameter data file. The data file is an M file with the block parameter values referenced in the imported Simscape Multibody model.

Examples

Import Robot Model

Generate a robotic arm model from the sm_robot.xml import file included in your Simscape Multibody installation. At the MATLAB command prompt, enter the following code.

smimport('sm_robot');

Import Robot Model Using Custom File Names

Generate a robotic arm model from the sm_robot.xml import file included in your Simscape Multibody installation. Specify the model name as robotto and the data file name as robottos_data_file. At the MATLAB command prompt, enter the following code.

smimport('sm_robot','ModelName','robotto',...
'DataFileName','robottos_data_file');

Regenerate Data File for Previously Imported Model

Regenerate the data file for the previously imported robotic arm model. Specify the data file name as robottos_new_data_file to avoid overwriting the original data file. At the MATLAB command prompt, enter the following code.

smimport('sm_robot','ImportMode','dataFile','DataFileName',...
'robottos_new_data_file','PriorDataFile','robottos_data_file');

Point the previously generated model to the new data file and reinitialize the model workspace using the following MATLAB code.

hws = get_param(bdroot,'modelworkspace');
hws.DataSource = 'MATLAB File';
hws.FileName = 'robotFileData';
hws.reload;

You can perform the same task using Model Explorer. In the Model Workspace pane for the imported model, update the File Name parameter. Then, click the Reinitialize from Source button.

See Also

|

Was this topic helpful?