{"id":175,"date":"2012-02-01T11:02:35","date_gmt":"2012-02-01T16:02:35","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=175"},"modified":"2012-02-01T11:35:42","modified_gmt":"2012-02-01T16:35:42","slug":"applying-motion-to-simmechanics-models","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2012\/02\/01\/applying-motion-to-simmechanics-models\/","title":{"rendered":"Applying Motion to SimMechanics Models"},"content":{"rendered":"<p>One of the features I like about <a href=\"https:\/\/www.mathworks.com\/products\/simmechanics\/\">SimMechanics<\/a> is the ability to specify the motion of a system without having to think about the forces involved.  This can simplify testing a model so you don't have to design a controller if all you are doing is testing the plant model for correctness.  Today I want to talk about a common problem people run into.<\/p>\r\n\r\n<p><strong>The Problem<\/strong><\/p>\r\n\r\n<p>I have the following SimMechanics model. This model is supposed to simulate a big crane... you know the ones with a big ball at the end of a cable used to destroy buildings.<\/p>\r\n\r\n<p><img decoding=\"async\" alt=\"SimMechanics model of a crane\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q1\/craneModel1.png\"\/><\/p>\r\n\r\n<p>When applying a sine wave trajectory (position) to the base, I expect the ball to swing, however it does not!<\/p>\r\n\r\n<p><img decoding=\"async\" alt=\"SimMechanics animation of a crane\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q1\/PositionOnly.gif\"\/><\/p>\r\n\r\n<p><strong>The Explanation<\/strong><\/p>\r\n\r\n<p>As you probably noticed, the base is actuated with a <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/physmod\/mech\/ref\/jointactuator.html\">Joint Actuator<\/a>, setup to <em>Actuate with motion<\/em>. In this configuration, three components must be fed to the block: Position, Velocity and Acceleration.<\/p>\r\n\r\n<p>Obviously, the velocity and acceleration corresponding to a sine wave trajectory are not 0!<\/p>\r\n\r\n<p><strong>The Solution: First Try<\/strong><\/p>\r\n\r\n<p>To get valid results with SimMechanics, it is important to provide valid inputs.<\/p>\r\n\r\n<p>To do that, the first thing that probably goes through your mind is to use <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/simulink\/slref\/derivative.html\">Derivative<\/a> blocks, like this:<\/p> \r\n\r\n<p><img decoding=\"async\" alt=\"Using Derivative blocks\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q1\/usingDerivative.png\"\/><\/p>\r\n\r\n<p>This works if the position signal is smooth, however in many cases this can cause problems.<\/p> \r\n\r\n<p>Why? If you have a discontinuity in the position signal, this will cause a sudden change in the velocity signal and an infinite acceleration. Infinite accelerations are not realistic and cause derivative errors in the solver.<\/p> \r\n\r\n<p><strong>A Better Solution<\/strong><\/p>\r\n\r\n<p>What I recommend is to implement a filtered derivative using a <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/simulink\/slref\/transferfcn.html\">Transfer Function<\/a> block.<\/p>\r\n\r\n<p><img decoding=\"async\" alt=\"Using Derivative blocks\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q1\/filteredDerivative.png\"\/><\/p>\r\n\r\n<p>Now we can see that our crane behaves as expected.<\/p>\r\n\r\n<p><img decoding=\"async\" alt=\"SimMechanics animation of a crane\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q1\/FullActuation.gif\"\/><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>If you are interested, you can find the model <a href=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q1\/crane.mdl\">here<\/a>.<\/p>\r\n\r\n<p>Look at the documentation section titled <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/physmod\/mech\/ug\/f2-117031.html#brmk3n6-1\">Stabilizing Numerical Derivatives in Actuation Signals<\/a> for more details and let us know what you think by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=174&amp;#comment\">comment here<\/a>.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>One of the features I like about SimMechanics is the ability to specify the motion of a system without having to think about the forces involved.  This can simplify testing a model so you don't have... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2012\/02\/01\/applying-motion-to-simmechanics-models\/\">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,10],"tags":[252,251,79],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/175"}],"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=175"}],"version-history":[{"count":18,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":348,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/175\/revisions\/348"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}