# From SolidWorks to SimMechanics15

Posted by Guy Rouleau,

This week we see how to export a CAD assembly from SolidWorks to SimMechanics. Once a mechanism is translated into a SimMechanics model, we can interface it with Simulink to perform a wide range of analysis or design tasks not available in most CAD software.

The SolidWorks Assembly

Let's start by creating an assembly of a double pendulum in SolidWorks. It consists of 2 identical links and 2 identical pins. These components are assembled by defining mates between them. For example to create a revolute joint between two parts in SolidWorks, we can constrain their axes and make them coincident:

I recommend looking at the Mates and Joints documentation page for more details on how SolidWorks mates are translated into SimMechanics Joints. For our example, here is how the final assembly looks:

Exporting the SolidWorks assembly to SimMechanics

This process requires the use of SimMechanics Link. Once SimMechanics Link is downloaded successfully, you need to Install and Register it with SolidWorks.

*Note: SimMechanics Link can also be used to interface with PTC Creo and the Autodesk Inventor.

After registering SimMechanics Link, a new menu is available in SolidWorks. We can now export the assembly:

This generates an XML file for the assembly, well as STL files for the geometry. The XML file contains assembly structure and part parameters required to generate an equivalent SimMechanics model, such as reference frames, mass and inertia, color, and location of part STL files.

Create SimMechanics model

Once the XML file is exported from SolidWorks, we can import it in Simulink using smimport:

smimport('DoublePendulum.xml')

and we have a model:

Do what you came here for!

At this point, you can combine any feature available in Simulink with your mechanism. For example, we can design a controller for the base joint using the automated PID Tuning capability of Simulink Control Design

I modify the base joint to measure its position and apply a torque, and connect the PID block:

After going through the auto tuning procedure, we can see the resulting motion:

What if you’re not using SolidWorks?

As mentionned previously, SimMechanics Link can also be used to interface with PTC Creo and Autodesk Inventor. If you are designing mechanical systems using a different CAD tool, I recommend looking at the MATLAB Central submission CAD to MATLAB to SimMechanics by my colleague Steve Miller. Using the technique in this submission it might be possible to write your own adapter to import assemblies from other CAD software without too much work.

Now it's your turn

Here is one more animation from the Stewart Platform example, just to highlight that pretty complex assemblies can be imported.

Are you already importing CAD assemblies to SimMechanics? If yes, let us know what kind of analysis or design task you do with the assembly once in Simulink by leaving a comment here.

Eric replied on : 1 of 15

Very cool :) Is it possible to enable anti-aliasing in the Mechanics Explorer? Also, is it possible to drive the original model inside the CAD software from SimMechanics/Simulink?

Abdullah replied on : 2 of 15

Hi Guys, I fallow your blog allways and your blog is so usefull.
I want to ask something about biped robots. I want to export a biped robot solidworks to simmechanics. But I dont know what contacts must be given between foots and ground. and any other example I want to drive a wheel without slipping. If any model is fixed to ground it is easy but if it is not fixed like walking robot or rolling wheel how can we model them?
There are so many publications about these but none of them explain the contacts or they are just on pdf not any example files.
Thank you

Guy Rouleau replied on : 3 of 15

@Abdullah, Contact dynamics is a complex problem that can be solved in many ways, thepending on the level of accuracy you need. For examples, you can give a look at this post where I modeled a one-legged robot. The files cna be downloaded form MATLAB Central:

http://blogs.mathworks.com/seth/2009/03/06/models-inspired-by-real-life

You can also look at my SimMechsnics rover, which implement a simple tire contact model:

http://www.mathworks.com/matlabcentral/fileexchange/23861-simmechanics%E2%84%A2-rover

I think my colleague Hitoshi Takeshita also has a good submission with a tire contact model:

http://www.mathworks.com/matlabcentral/fileexchange/22411-model-based-design-for-electrical-automobile-chassis-control

Guy Rouleau replied on : 4 of 15

@Eric: We are looking into anti-aliasing for the Mechanics Explorer, but this is not available as of R2014a. About the possibility to drive a CAD software from Simulink, this is probably something that could be done with a bit of work, but we do not have a “one-click” solution.

Abdullah replied on : 5 of 15

@Guy , Thank you so much for your usefull reply.. I will check the models that you said.

Christophe Lauwerys replied on : 7 of 15

Is it possible to model 3D body contacts (+ reaction forces) between different geometrical parts in SimScape?
Thanks
Christophe

Sagar Manohar Pohekar replied on : 9 of 15

Your blog is really helpful for me thank you for posting such interesting things
Dear Sir,
I am new to simulink and I’m buliding Hydraulic Excavator cad model in CREO 2.0 and wants to simulate the same using simulink along with interfacing with hydraulic circuit design (using simhydraulics) to get real time simulation will you help me to get proper documentation and reference because it’s my Masters Project I am doing my dissertation from India M.Tech in cad cam
Yours Sincierly,
Sagar M. Pohekar
SVNIT,
Surat,
Gujrat,
India
pincode 395007

SAMMARI replied on : 10 of 15

Hello Sir,Hello everyone,

I have an issue with CAD translation from SolidWorks to SimMechanics (I am using the first generation), when I translate my 3DOF arm’s CAD and after matching actuators and inverse kinematic’s code I run the simulation and the response is wrong. However I tried with a 3dof simplified model (from Solidworks also) and it works and the response was very good, so I think that the problem is in the assembly “step” am sure that there is a detail that I missed, a geometric detail (like reference mates origin orientation …) any idea please

I am available for any additional information.

Bests regards.

Guy Rouleau replied on : 11 of 15

@SAMMARI: It is very difficult to diagnose what is wrong with this description. I recommend contacting technical support with your files so we can reproduce the issue:

http://www.mathworks.com/support/contact_us/

SAMMARI replied on : 12 of 15

@Guy Rouleau: thank you for your reply.

M.M.Reihanfard replied on : 13 of 15

I need simmechanic for R2014a

Tharindu replied on : 14 of 15

I made small robot and drew in solidwork, then I saved it xml file and import to matlab. I want to add pid for motors, but I don’t know matlab how to find the motor specification. I didn’t give any specification in solidworks for motors. How its work? Can you help me?

Wedi replied on : 15 of 15

Can someone here help to finde way to realise a wire to join between the pulley and the effector .
i cant use cable between pulley and effector.
thank you

What is 3 + 7?

Preview: hide