|On this page…|
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.
The following figure shows the original CAD assembly inside the SolidWorks® CAD platform.
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.
At the MATLAB® command line, enter the following command to change the current working directory to the subdirectory that contains the robot example files:
At the MATLAB command line, enter ls or dir to list all files in the \robot directory.
Check that the directory contains XML file sm_robot.xml and a set of STL files.
Once you have verified that all required files exist, proceed to import the assembly.
At the MATLAB command line, enter smimport('sm_robot.xml').
Confirm that SimMechanics opens a new model with name sm_robot.
In the Simulink® Editor window that contains the model, select File > Save As.
In the Save As dialog box, enter the desired file name and select a convenient directory in which store the model file.
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.
In the Mechanics Explorer toolbar, set View Convention to Y up (XY Front).
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.
Confirm that a Mechanics Explorer window opens with a static display of the robot assembly.
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.