{"id":5831,"date":"2015-02-13T09:00:21","date_gmt":"2015-02-13T14:00:21","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5831"},"modified":"2017-05-04T11:08:39","modified_gmt":"2017-05-04T15:08:39","slug":"whats-the-reaction-when-we-touch","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2015\/02\/13\/whats-the-reaction-when-we-touch\/","title":{"rendered":"What\u2019s the reaction when we touch?"},"content":{"rendered":"<div class=\"content\">\r\n\r\n&nbsp;\r\n\r\n<b>Contact Modeling in SimMechanics<\/b><br><br>\r\n\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\">Greg's<\/a> pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/49374-rolling-ball-on-plane\">Rolling Ball on Plane<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/1196817-janne-salomaki\">Janne Salom\u00e4ki<\/a>.\r\n<br>\r\nJanne put together a nice example of modeling the interaction of a ball contacting a plane, rolling on the plane, and then\r\nfalling off the plane.\r\n<br>\r\n\r\n<video width=\"600\" height=\"400\" controls=\"controls\">\r\n<source src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/ballOnPlaneWriteup\/ballRollingOnSurface.mp4\" type=\"video\/mp4\">\r\n<\/video>\r\n<br>\r\nJanne uses SimMechanics to model the geometry and motion of the ball and the plane. And then applies C-code S-Function to model\r\nthe interaction between the ball and the plane. Contact modeling isn\u2019t something SimMechanics can do, so I\u2019m excited to see\r\nan example that shows the basic concept. I also saw an opportunity to compare using C-code and MATLAB Code to solve this particular\r\nproblem.\r\n\r\n&nbsp;\r\n<h3>Contents<\/h3>\r\n<div>\r\n<ul>\r\n\t<li><a href=\"#1\">What is SimMechanics?<\/a><\/li>\r\n\t<li><a href=\"#2\">What is an S-function?<\/a><\/li>\r\n\t<li><a href=\"#3\">Are there other ways to do this?<\/a><\/li>\r\n\t<li><a href=\"#4\">How do they compare?<\/a><\/li>\r\n\t<li><a href=\"#5\">What do I like about this entry?<\/a><\/li>\r\n\t<li><a href=\"#6\">Do you need contact modeling in SimMechanics?<\/a><\/li>\r\n<\/ul>\r\n<\/div>\r\n<h3>What is SimMechanics?<a name=\"1\"><\/a><\/h3>\r\n<a href=\"https:\/\/www.mathworks.com\/products\/simmechanics\">SimMechanics<\/a> enables six degree of freedom (6DOF) modeling of rigid bodies in Simulink. A nice benefit is it comes with an animation feature\r\nwhere you can visualize the motion of the bodies.\r\n\r\nBodies are defined in terms of mass, inertia tensor, and location for the center of mass. Connections to other bodies are\r\ndefined by coordinate systems applied to the body, and placing constraints on the type of motion permitted between two coordinate\r\nsystems. For example, a <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sm\/ref\/revolutejoint.html\">revolute joint<\/a> only has one degree of freedom, while a <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sm\/ref\/gimbaljoint.html\">gimbal joint<\/a> has three degrees of freedom.\r\n\r\n<a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/6dofJoint.png\"><img decoding=\"async\" loading=\"lazy\" width=\"860\" height=\"777\" class=\"alignnone size-full wp-image-5835\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/6dofJoint.png\" alt=\"6dofJoint\" \/><\/a>\r\n<br>\r\nIn this particular case, the <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sm\/ref\/6dofjoint.html\">joint<\/a> between the ball and the plane has six degrees of freedom, which means there is no restriction on the relative motion between\r\nthese two bodies. Using this joint enables <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sm\/ug\/motion-sensing.html\">measurement<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sm\/ug\/joint-actuation.html\">actuation<\/a> of the relative motions between the two bodies, which is essential for modeling the contact interaction.\r\n<h3>What is an S-function?<a name=\"2\"><\/a><\/h3>\r\nAn <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/sfg\/what-is-an-s-function.html\">S-Function<\/a> is a \u201csystem function\u201d. It is a way to create customized blocks in Simulink that can extend its functionality. People use\r\nS-Functions to for all sorts of capabilities:\r\n<div>\r\n<ul>\r\n\t<li>Interface Simulink models with other software running on your computer<\/li>\r\n\t<li>Compile an optimized block algorithm to improve performance<\/li>\r\n\t<li>Protect intellectual property<\/li>\r\n\t<li><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/legacy-code-integration.html\">Integrate existing code<\/a> into a Simulink model<\/li>\r\n<\/ul>\r\n<\/div>\r\nWhile S-functions can be a little tricky, especially if you are unfamiliar with the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/block-feature-implementation.html\">API<\/a>, they interact more or less directly with the Simulink solver engine, which enables development of a wide variety of block\r\ntypes and capabilities.\r\n\r\nJanne uses the C-code S-function to implement the mathematical model for the interaction between the ball and the plane.\r\n<h3>Are there other ways to do this?<a name=\"3\"><\/a><\/h3>\r\nThere are other ways to develop the interaction model. You could of course use basic Simulink blocks, and develop the equations\r\nusing Add blocks, Gain blocks, etc.\r\n\r\nAnother option is to write the interaction as MATLAB-Code in the MATLAB Function block. This would enable you to test the\r\nalgorithm in the flexible MATLAB environment. The MATLAB Function block is not designed to support mathematical integration.\r\nSo it is often best to pass out the derivatives of the states as outputs, route them through an integrator block, and pass\r\nthe result back as inputs to the MATLAB Function block.\r\n\r\n<a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/matlabFunctionBlock.png\"><img decoding=\"async\" loading=\"lazy\" width=\"870\" height=\"570\" class=\"alignnone size-full wp-image-5837\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/matlabFunctionBlock.png\" alt=\"matlabFunctionBlock\" \/><\/a>\r\n<h3>How do they compare?<a name=\"4\"><\/a><\/h3>\r\n<table cellspacing=\"0\" cellpadding=\"0\">\r\n<tbody>\r\n<tr class=\"c1\">\r\n<th class=\"c6\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">C-code S-Function<\/span><\/p>\r\n<\/th>\r\n<th class=\"c4\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">MATLAB Function<\/span><\/p>\r\n<\/th>\r\n<th class=\"c7\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">MATLAB Function<\/span><\/p>\r\n<p class=\"c0\"><span class=\"c2\">(Debugging\r\nDisabled)<\/span><\/p>\r\n<\/th>\r\n<\/tr>\r\n<tr class=\"c1\">\r\n<td class=\"c6\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">2.15 sec<\/span><\/p>\r\n<\/td>\r\n<td class=\"c4\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">2.67 sec<\/span><\/p>\r\n<\/td>\r\n<td class=\"c7\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">2.30 sec<\/span><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"c1\">\r\n<td class=\"c6\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">~<\/span><\/p>\r\n<\/td>\r\n<td class=\"c4\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">+24%<\/span><\/p>\r\n<\/td>\r\n<td class=\"c7\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">+6.8%<\/span><\/p>\r\n<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\nI thought I would try some basic benchmarking to compare some different implementations.\r\n\r\nIt\u2019s interesting to me that the MATLAB Function block is only about 7% slower. Remember that by default, the MATLAB Function\r\nblock converts the MATLAB Code to C-code and then compiles it to essentially an S-Function.\r\n<br><br>\r\n<b>MATLAB Debugging Disabled<\/b>\r\n<br><br>\r\n<a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/debugSettings.png\"><img decoding=\"async\" loading=\"lazy\" width=\"1198\" height=\"387\" class=\"alignnone size-full wp-image-5836\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/debugSettings.png\" alt=\"debugSettings\" \/><\/a>\r\n\r\nLeaving the debugging on certainly provides for a much bigger performance hit, but it also means you can step through the\r\ncode using the MATLAB Debugger. This is a bit more difficult to do when you need to <a href=\"https:\/\/blogs.mathworks.com\/seth\/2012\/12\/06\/debugging-cc-s-functions\">debug the C-code S-Function<\/a>.\r\n\r\nI\u2019ll leave it to you to decide if the convenience of the MATLAB Code is worth the hit in performance.\r\n<h3>What do I like about this entry?<a name=\"5\"><\/a><\/h3>\r\nFirst, it is a neat, clean, and clear model. Both the model and the code for the S-function are done in a nice straight\r\nforward manner. I like the use of the macros in the C-code S-function to make the code easier to read by hiding some of the\r\nweird API language. What I find so fascinating is that SimMechanics handles all of the appropriate coordinate transformations,\r\nso the algorithm for the contact model is relatively simple without a lot of math to figure out the body relationships.\r\n\r\nI realize this approach might not scale well to a more general implementation of contact modeling, but I think it\u2019s a beautiful\r\nand creative example of investigating rigid body dynamics.\r\n<br><br>\r\n<h3>Do you need contact modeling in SimMechanics?<a name=\"6\"><\/a><\/h3><br>\r\nLet us know how you would use it. Do you create S-Functions? What\u2019s one thing you like about them? What\u2019s one thing you dislike\r\nabout them? You can leave your comments <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5831#respond\">here<\/a>.\r\n\r\n<script language=\"JavaScript\">\/\/ <![CDATA[\r\n\r\n\r\n    function grabCode_8f5b7300747b4559b8ff5bed8240c5b5() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='8f5b7300747b4559b8ff5bed8240c5b5 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 8f5b7300747b4559b8ff5bed8240c5b5';\r\n\r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n\r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Greg Wolff';\r\n        copyright = 'Copyright 2015 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\r\n\r\n\r\n\\n');\r\n\r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\"><a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\r\nPublished with MATLAB\u00ae 8.4\r\n\r\n<\/div>\r\n<!--\r\n8f5b7300747b4559b8ff5bed8240c5b5 ##### SOURCE BEGIN #####\r\n%% What\u00e2\u20ac\u2122s the reaction when we touch?\r\n%\r\n% <html>\r\n%\r\n<style type=\"text\/css\">\r\n%   ol{margin:0;padding:0}\r\n%     .c6{border-bottom-width:1pt;border-top-style:solid;width:122.2pt;border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#000000;border-top-width:1pt;border-bottom-style:solid;vertical-align:top;border-top-color:#000000;border-left-color:#000000;border-right-color:#000000;border-left-style:solid;border-right-width:1pt;border-left-width:1pt}\r\n%     .c7{border-bottom-width:1pt;border-top-style:solid;width:135pt;border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#000000;border-top-width:1pt;border-bottom-style:solid;vertical-align:top;border-top-color:#000000;border-left-color:#000000;border-right-color:#000000;border-left-style:solid;border-right-width:1pt;border-left-width:1pt}\r\n%     .c4{border-bottom-width:1pt;border-top-style:solid;width:127.5pt;border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#000000;border-top-width:1pt;border-bottom-style:solid;vertical-align:top;border-top-color:#000000;border-left-color:#000000;border-right-color:#000000;border-left-style:solid;border-right-width:1pt;border-left-width:1pt}\r\n%     .c2{vertical-align:baseline;color:#000000;font-size:11pt;font-style:normal;font-family:\"Arial\";text-decoration:none;font-weight:normal}\r\n%     .c0{line-height:1.0;padding-top:0pt;text-align:center;direction:ltr;padding-bottom:0pt}\r\n%     .c3{widows:2;orphans:2;height:11pt;direction:ltr}\r\n%     .c5{max-width:468pt;background-color:#ffffff;padding:72pt 72pt 72pt 72pt}\r\n%     .c8{margin-right:auto;border-collapse:collapse;margin-left:33.8pt}\r\n%     .c1{height:0pt}\r\n% <\/style>% <\/html>\r\n%\r\n% *Contact Modeling in SimMechanics*\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620 Greg's> pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/49374-rolling-ball-on-plane Rolling Ball on Plane> by <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/1196817-janne-salomaki Janne Salom\u00c3\u00a4ki>.\r\n%\r\n% Janne put together a nice example of modeling the interaction of a ball contacting a plane, rolling on the plane, and then falling off the plane.\r\n%\r\n% <html>\r\n%    <object id=\"csSWF\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"1000\" height=\"520\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=9,0,115,0\">%<param name=\"src\" value=\"ballRollingOnSurface.mp4\">%<param name=\"bgcolor\" value=\"#1a1a1a\">%<param name=\"quality\" value=\"best\">%<param name=\"allowScriptAccess\" value=\"always\">%<param name=\"allowFullScreen\" value=\"true\">%<param name=\"scale\" value=\"showall\">%<param name=\"flashVars\" value=\"autostart=false#&amp;thumb=FirstFrame.png&amp;thumbscale=45&amp;color=0x1A1A1A,0x1A1A1A\">%<embed name=\"csSWF\" src=\"ballRollingOnSurface.mp4\" width=\"1000\" height=\"520\" bgcolor=\"#1a1a1a\" quality=\"best\" allowscriptaccess=\"always\" allowfullscreen=\"true\" scale=\"showall\" flashvars=\"autostart=false&amp;thumb=FirstFrame.png&amp;thumbscale=45&amp;color=0x1A1A1A,0x1A1A1A\" pluginspage=\"http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash\">%<\/object>\r\n% <\/html>\r\n%\r\n% Janne uses SimMechanics to model the geometry and motion of the ball and the plane. And then applies C-code S-Function to model the interaction between the ball and the plane.\r\n% Contact modeling isn\u00e2\u20ac\u2122t something SimMechanics can do, so I\u00e2\u20ac\u2122m excited to see an example that shows the basic concept. I also saw an opportunity to compare using C-code and MATLAB Code to solve this particular problem.\r\n%\r\n%% What is SimMechanics?\r\n% <https:\/\/www.mathworks.com\/products\/simmechanics  SimMechanics> enables six degree of freedom (6DOF) modeling of rigid bodies in Simulink. A nice benefit is it comes with an animation feature where you can visualize the motion of the bodies.\r\n%\r\n% Bodies are defined in terms of mass, inertia tensor, and location for the center of mass. Connections to other bodies are defined by coordinate systems applied to the body, and placing constraints on the type of motion permitted between two coordinate systems.  For example, a <https:\/\/www.mathworks.com\/help\/physmod\/sm\/ref\/revolutejoint.html revolute joint> only has one degree of freedom, while a <https:\/\/www.mathworks.com\/help\/physmod\/sm\/ref\/gimbaljoint.html gimbal joint> has three degrees of freedom.\r\n%\r\n% <html>\r\n%   <img decoding=\"async\" src=\"6dofJoint.png\" width=\"300\">\r\n% <\/html>\r\n%\r\n% In this particular case, the <https:\/\/www.mathworks.com\/help\/physmod\/sm\/ref\/6dofjoint.html joint> between the ball and the plane has six degrees of freedom, which means there is no restriction on the relative motion between these two bodies. Using this joint enables <https:\/\/www.mathworks.com\/help\/physmod\/sm\/ug\/motion-sensing.html measurement> and <https:\/\/www.mathworks.com\/help\/physmod\/sm\/ug\/joint-actuation.html actuation> of the relative motions between the two bodies, which is essential for modeling the contact interaction.\r\n%\r\n%% What is an S-function?\r\n% An <https:\/\/www.mathworks.com\/help\/simulink\/sfg\/what-is-an-s-function.html S-Function> is a \u00e2\u20ac\u0153system function\u00e2\u20ac\ufffd. It is a way to create customized blocks in Simulink that can extend its functionality.\r\n% People use S-Functions to for all sorts of capabilities:\r\n%\r\n% * Interface Simulink models with other software running on your computer\r\n% * Compile an optimized block algorithm to improve performance\r\n% * Protect intellectual property\r\n% * <https:\/\/www.mathworks.com\/help\/simulink\/legacy-code-integration.html Integrate existing code> into a Simulink model\r\n%\r\n% While S-functions can be a little tricky, especially if you are unfamiliar with the <https:\/\/www.mathworks.com\/help\/simulink\/block-feature-implementation.html API>, they interact more or less directly with the Simulink solver engine, which enables development of a wide variety of block types and capabilities.\r\n%\r\n%\r\n% Janne uses the C-code S-function to implement the mathematical model for the interaction between the ball and the plane.\r\n%\r\n%% Are there other ways to do this?\r\n% There are other ways to develop the interaction model. You could of course use basic Simulink blocks, and develop the equations using Add blocks, Gain blocks, etc.\r\n%\r\n% Another option is to write the interaction as MATLAB-Code in the MATLAB Function block. This would enable you to test the algorithm in the flexible MATLAB environment.\r\n% The MATLAB Function block is not designed to support mathematical integration. So it is often best to pass out the derivatives of the states as outputs, route them through an integrator block, and pass the result back as inputs to the MATLAB Function block.\r\n%\r\n% <html>\r\n%   <img decoding=\"async\" src=\"matlabFunctionBlock.png\" width=\"600\">\r\n% <\/html>\r\n%\r\n%% How do they compare?\r\n%\r\n% <html>\r\n%\r\n<table cellpadding=\"0\" cellspacing=\"0\" margin-right=\"auto\" border-collapse=\"collapse\" margin-left=\"33.8pt\">\r\n%\r\n<tbody>\r\n%\r\n<tr class=\"c1\">\r\n%\r\n<th class=\"c6\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">C-code S-Function<\/span><\/p>\r\n<\/th>\r\n%\r\n<th class=\"c4\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">MATLAB Function<\/span><\/p>\r\n<\/th>\r\n%\r\n<th class=\"c7\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">MATLAB Function<\/span><\/p>\r\n<p class=\"c0\"><span class=\"c2\">(Debugging Disabled)<\/span><\/p>\r\n<\/th>\r\n%<\/tr>\r\n%\r\n<tr class=\"c1\">\r\n%\r\n<td class=\"c6\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">2.15 sec<\/span><\/p>\r\n<\/td>\r\n%\r\n<td class=\"c4\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">2.67 sec<\/span><\/p>\r\n<\/td>\r\n%\r\n<td class=\"c7\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">2.30 sec<\/span><\/p>\r\n<\/td>\r\n%<\/tr>\r\n%\r\n<tr class=\"c1\">\r\n%\r\n<td class=\"c6\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">~<\/span><\/p>\r\n<\/td>\r\n%\r\n<td class=\"c4\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">+24%<\/span><\/p>\r\n<\/td>\r\n%\r\n<td class=\"c7\" colspan=\"1\" rowspan=\"1\">\r\n<p class=\"c0\"><span class=\"c2\">+6.8%<\/span><\/p>\r\n<\/td>\r\n%<\/tr>\r\n%<\/tbody>\r\n%<\/table>\r\n% <\/html>\r\n%\r\n% I thought I would try some basic benchmarking to compare some different implementations.\r\n%\r\n% It\u00e2\u20ac\u2122s interesting to me that the MATLAB Function block is only about 7% slower.  Remember that by default, the MATLAB Function block converts the MATLAB Code to C-code and then compiles it to essentially an S-Function.\r\n%\r\n% *MATLAB Debugging Disabled*\r\n%\r\n% <html>\r\n%   <img decoding=\"async\" src=\"debugSettings.png\" width=\"600\">\r\n% <\/html>\r\n%\r\n% Leaving the debugging on certainly provides for a much bigger performance hit, but it also means you can step through the code using the MATLAB Debugger.  This is a bit more difficult to do when you need to <https:\/\/blogs.mathworks.com\/seth\/2012\/12\/06\/debugging-cc-s-functions debug the C-code S-Function>.\r\n%\r\n% I\u00e2\u20ac\u2122ll leave it to you to decide if the convenience of the MATLAB Code is worth the hit in performance.\r\n%\r\n%% What do I like about this entry?\r\n% First, it is a neat, clean, and clear model. Both the model and the code for the S-function are pretty done is a nice straight forward manner.  I like the use of the macros in the C-code S-function to make the code easier to read by hiding some of the weird API language.\r\n% What I find so fascinating is that SimMechanics handles all of the appropriate coordinate transformations, so the algorithm for the contact model is relatively simple without a lot of math to figure out the body relationships.\r\n%\r\n% I realize this approach might not scale well to a more general implementation of contact modeling, but I think it\u00e2\u20ac\u2122s a beautiful and creative example of investigating rigid body dynamics.\r\n\r\n%% Do you need contact modeling in SimMechanics?\r\n% Let us know how you would use it.  Do you create S-Functions? What\u00e2\u20ac\u2122s one thing you like about them? What\u00e2\u20ac\u2122s one thing you dislike about them?\r\n% You can leave your comments <https:\/\/blogs.mathworks.com\/pick\/?p=?????#respond here>.\r\n%\r\n\r\n##### SOURCE END ##### 8f5b7300747b4559b8ff5bed8240c5b5\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/6dofJoint-1.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\n\r\n&nbsp;\r\n\r\nContact Modeling in SimMechanics\r\n\r\nGreg's pick this week is Rolling Ball on Plane by Janne Salom\u00e4ki.\r\n\r\nJanne put together a nice example of modeling the interaction of a ball... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2015\/02\/13\/whats-the-reaction-when-we-touch\/\">read more >><\/a><\/p>","protected":false},"author":36,"featured_media":8572,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,24],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5831"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=5831"}],"version-history":[{"count":20,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5831\/revisions"}],"predecessor-version":[{"id":5856,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5831\/revisions\/5856"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/8572"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}