Import Robot Arm Model

In this example, you import a CAD assembly with name robot into SimMechanics™. SimMechanics provides the smimport command so that you can import a CAD assembly. The command is the only SimMechanics tool you need to import a CAD assembly. The CAD import procedure is the same for all CAD platforms.

    Note:   This example uses an XML file and a set of STL files that are present in your SimMechanics installation. You can export the XML and STL files directly from a supported CAD platform, but the names of the files may differ from the example.

The following figure shows the original CAD assembly inside the SolidWorks® CAD platform.

Check Import Files

Before you import the sm_robot CAD assembly, check that the import files exist. The import files include one SimMechanics Import XML file and a set of STL files that specify the geometry of all CAD parts.

  1. At the MATLAB® command line, enter the following command to change the current working directory to the subdirectory that contains the robot example files:

    cd(fullfile(matlabroot,'toolbox','physmod','sm','smdemos',...
    'import','robot'))
  2. At the MATLAB command line, enter ls or dir to list all files in the \robot directory.

  3. Check that the directory contains XML file sm_robot.xml and a set of STL files.

Import Robot Assembly

Once you have verified that all required files exist, proceed to import the assembly.

  1. At the MATLAB command line, enter smimport('sm_robot.xml').

  2. Confirm that SimMechanics opens a new model with name sm_robot.

      Note:   SimMechanics automatically generates the new model without extra input on your part. Review the model and check for errors and inconsistencies in the block diagram.

  3. In the Simulink® Editor window that contains the model, select File > Save As.

  4. In the Save As dialog box, enter the desired file name and select a convenient directory in which store the model file.

Visualize and Simulate Robot Assembly

  1. In the Simulink Editor window that contains the robot model, select Simulation > Update Diagram or press Ctrl+D.

      Note:   When you update the diagram, SimMechanics automatically updates the model display in Mechanics Explorer. SimMechanics relies on the set of STL files to represent the 3-D geometry of each CAD part. If the files are not available, SimMechanics still generates the model, but Mechanics Explorer cannot display the assembly.

  2. In the Mechanics Explorer toolbar, set View Convention to Y up (XY Front).

      Note:   Most CAD systems use a Y up default view convention. The convention differs from the Mechanics Explorer default setting, Z up. Selecting the Y up view convention causes Mechanics Explorer to display the assembly with the same orientation used in the CAD platforms.

  3. In the toolbar, click the icon for the desired viewpoint.

      Note:   Selecting the Y up view convention does not affect the Mechanics Explorer display until you click a view point. You have the choice between seven standard viewpoints: front, back, top, down, left, right, and isometric. Once you select a view point, you can rotate, pan, and zoom to adjust the display of your model.

  4. Confirm that a Mechanics Explorer window opens with a static display of the robot assembly.

  5. In the Simulink Editor window for the model, select Simulation > Run or press Ctrl+T to simulate the model.

    Tip   The model lacks actuation inputs. When you simulate the model, the robot arm moves strictly due to gravity effects. You can change the gravity specification in the Mechanism Configuration block.

    You can add actuation inputs to the model. Add a block from the Forces & Torques library to actuate a rigid body. Select an actuation mode in the model joint blocks to actuate a joint.

See Also

Related Examples

More About

Was this topic helpful?