{"id":3877,"date":"2014-07-10T15:41:51","date_gmt":"2014-07-10T20:41:51","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=3877"},"modified":"2017-01-02T20:43:21","modified_gmt":"2017-01-03T01:43:21","slug":"from-solidworks-to-simmechanics","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2014\/07\/10\/from-solidworks-to-simmechanics\/","title":{"rendered":"From SolidWorks to SimMechanics"},"content":{"rendered":"<!--introduction-->\r\n\r\n<p>This week we see how to export a CAD assembly from <a href=\"http:\/\/www.solidworks.com\/\">SolidWorks<\/a> to <a href=\"https:\/\/www.mathworks.com\/products\/simmechanics\/\">SimMechanics<\/a>. 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.<\/p>\r\n\r\n<!--\/introduction-->\r\n\r\n<p><strong>The SolidWorks Assembly<\/strong><\/p>\r\n\r\n<p>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 <a href=\"http:\/\/help.solidworks.com\/2013\/English\/SolidWorks\/sldworks\/c_Mates_Overview_Assemblies.htm\">mates<\/a> between them. For example to create a revolute joint between two parts in SolidWorks, we can constrain their axes and make them coincident:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/mates.png\" alt=\"SolidWorks Assembly\" \/><\/p>\r\n\r\n<p>I recommend looking at <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/smlink\/ref\/mates-and-joints.html\">the Mates and Joints documentation page<\/a> for more details on how SolidWorks mates are translated into SimMechanics Joints. For our example, here is how the final assembly looks:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/pendulumFull.png\" alt=\"SolidWorks Pendulum Assembly\" \/><\/p>\r\n\r\n<p><strong>Exporting the SolidWorks assembly to SimMechanics<\/strong><\/p>\r\n\r\n<p>This process requires the use of SimMechanics Link. Once SimMechanics Link is downloaded successfully, you need to <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/smlink\/ug\/installing-and-linking-simmechanics-link-software.html\">Install and Register it with SolidWorks<\/a>.<\/p>\r\n\r\n<p><em>*Note: SimMechanics Link can also be used to interface with PTC Creo and the Autodesk Inventor.<\/em><\/p>\r\n\r\n<p>After registering SimMechanics Link, a new menu is available in SolidWorks. We can now export the assembly:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/exporttoSimMech.png\" alt=\"Exporting CAD Assembly\" \/><\/p>\r\n\r\n<p>This generates an XML file for the assembly, well as <a href=\"http:\/\/en.wikipedia.org\/wiki\/STL_(file_format)\">STL files<\/a> 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.<\/p>\r\n\r\n<p><strong>Create SimMechanics model<\/strong><\/p>\r\n\r\n<p>Once the XML file is exported from SolidWorks, we can import it in Simulink using <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sm\/ref\/smimport.html\"><tt>smimport<\/tt><\/a>:<\/p>\r\n\r\n<p><code>smimport(<span class=\"string\">'DoublePendulum.xml'<\/span>)<\/code><\/p>\r\n\r\n<p>and we have a model:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/SMLinkModel1.png\" alt=\"Imported CAD Assembly\" \/><\/p>\r\n\r\n<p><strong>Do what you came here for!<\/strong><\/p>\r\n\r\n<p>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 <a href=\"https:\/\/www.mathworks.com\/help\/slcontrol\/ug\/introduction-to-automatic-pid-tuning.html\">automated PID Tuning capability<\/a> of <a href=\"https:\/\/www.mathworks.com\/products\/simcontrol\/\">Simulink Control Design<\/a><\/p>\r\n\r\n<p>I modify the base joint to measure its position and apply a torque, and connect the PID block:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/SMLinkModel2.png\" alt=\"Modified Imported CAD Assembly\" \/><\/p>\r\n\r\n<p>After going through the auto tuning procedure, we can see the resulting motion:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/DoublePendulum.gif\" alt=\"Modified Imported CAD Assembly Motion\" \/><\/p>\r\n\r\n<p><strong>What if you\u2019re not using SolidWorks?<\/strong><\/p>\r\n\r\n<p>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 <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/47070-cad-to-matlab-to-simscape-multibody\">CAD to MATLAB to SimMechanics<\/a> by my colleague <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29641\">Steve Miller<\/a>. 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.<\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Here is one more animation from the Stewart Platform example, just to highlight that pretty complex assemblies can be imported.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/stewart.gif\" alt=\"Stewart Platform\" \/><\/p>\r\n\r\n<p>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 <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=3877&amp;#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/stewart.gif\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction-->\r\n\r\n<p>This week we see how to export a CAD assembly from <a href=\"http:\/\/www.solidworks.com\/\">SolidWorks<\/a> to <a href=\"https:\/\/www.mathworks.com\/products\/simmechanics\/\">SimMechanics<\/a>. 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.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2014\/07\/10\/from-solidworks-to-simmechanics\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[39],"tags":[395,396,393,394,392],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3877"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=3877"}],"version-history":[{"count":31,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3877\/revisions"}],"predecessor-version":[{"id":6211,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3877\/revisions\/6211"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=3877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=3877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=3877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}