{"id":47,"date":"2009-02-26T17:35:23","date_gmt":"2009-02-26T17:35:23","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2009\/02\/26\/modeling-mechanical-systems-the-double-pendulum\/"},"modified":"2017-01-02T15:57:51","modified_gmt":"2017-01-02T20:57:51","slug":"modeling-mechanical-systems-the-double-pendulum","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2009\/02\/26\/modeling-mechanical-systems-the-double-pendulum\/","title":{"rendered":"Modeling Mechanical Systems: The Double Pendulum"},"content":{"rendered":"<p>Do you ever have to model mechanical systems?\u00a0 Mechanical\r\nsystems consist of bodies, joints, and force elements like springs.\u00a0 In this post,\r\nI will show you how to model a double pendulum with base Simulink and using <a\r\nhref=\"https:\/\/www.mathworks.com\/products\/simmechanics\/\">SimMechanics<\/a>.<\/p>\r\n\r\n<p><em><strong>Update - 9\/14\/2015:<\/strong> This blog post uses SimMechanics First Generation. Examples implementing double-pendulum using SimMechanics Second Generation can be found <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sm\/ug\/model-double-pendulum.html\">here.<\/em><\/p>\r\n\r\n<p><strong>Pendulum: Equations of Motion<\/strong><\/p>\r\n\r\n<p>Most of the models I work with are representations of data\r\nflow and algorithms.\u00a0 If you want a model of a mechanical system, you need the\r\nequations of motion so you can build the system from base Simulink blocks. Of\r\ncourse, if you don\u2019t know the equations for a pendulum, you must derive them.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q1\/pendEQNS.png\" alt=\"Pendulum equations\"><\/p>\r\n\r\n<p>If you start with that equation, and follow the process\r\ndescribed in a previous post about <a\r\nhref=\"https:\/\/blogs.mathworks.com\/seth\/2008\/05\/23\/how-to-draw-odes-in-simulink\/\">how\r\nto draw ODEs<\/a>, the model of a pendulum looks like this:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q1\/pendModelBaseBlocks.png\" alt=\"Simulink model of a single pendulum\"><\/p>\r\n\r\n<p>This model is a graphical representation of mathematical\r\noperations and algorithm elements.\u00a0 Simulink solves the differential equation\r\nby evaluating the individual blocks according to the sorted order to compute\r\nderivatives for the states.\u00a0 The solver uses numeric integration to compute the\r\nevolution of states through time.<\/p>\r\n\r\n<p><strong>Drawing the Mechanical System<\/strong><\/p>\r\n\r\n<p>SimMechanics provides an alternative to deriving equations\r\nand implementing them with base blocks.\u00a0 Instead of representing a mathematical\r\nmodel of the system, we develop a representation that describes the key\r\ncomponents of the mechanical system.\u00a0 The base units in SimMechanics are\r\nphysical elements instead of algorithm elements. To build a SimMechanics model,\r\nyou must break down the mechanical system into the building blocks that describe\r\nit.\u00a0 When you think about the pendulum, it a body connected to a joint, and\r\nthat joint is connected to some kind of base, we will call that the ground.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q1\/pendMECH.png\" alt=\"Drawing of a pendulum from mechanical elements\"><\/p>\r\n\r\n<p>The base elements in the SimMechanics library have special\r\nnames that precisely describe what they are.\u00a0 I didn\u2019t know this until I\r\nstarted using SimMechanics, but the joint in my pendulum example is called a\r\nRevolute.\u00a0 To build this system, we grab the appropriate blocks and connect\r\nthem together (kind of like playing with legos!).\u00a0 The ports on the\r\nSimMechanics blocks are connector ports, and the \u201csignals\u201d running between them\r\nare connector lines.\u00a0 These lines do not represent data flow, they represent\r\nmechanical connections between elements.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q1\/pendModelSimMech.png\" alt=\"Simulink model using SimMechanics blocks of a single pendulum\"><\/p>\r\n\r\n<p>These special connection lines and connection ports cannot\r\nconnect directly to Simulink signals and ports.\u00a0 Sensors allow you to tap into\r\na mechanical component and measure its physical properties.\u00a0 In my pendulum\r\nmodel above, I have measured the angular position (ap) and angular velocity\r\n(av) of the revolute joint.<\/p>\r\n\r\n<p>When you simulate a SimMechanics model, the process is a\r\nlittle different from regular Simulink data flow.\u00a0 At initialization,\r\nSimMechanics analyzes the mechanical system to determine the topology and\r\ngeometry of the machine.\u00a0 At run-time, the external forces and torques are\r\napplied to the machine, integrated, and the machine state is updates.\u00a0 Because\r\nthe model may contain constraints, the solver checks for the agreement of all\r\nthe elements of the machine within acceptable tolerances.\u00a0 The \u201cblocks\u201d that\r\nmake up the machine do not run one at a time in the simulation loop like\r\nregular Simulink blocks.<\/p>\r\n\r\n<p><strong>The Double Pendulum: Equations of Motion<\/strong><\/p>\r\n\r\n<p>Let\u2019s compare the modeling process for a double pendulum\r\nbetween base Simulink blocks and using SimMechanics.\u00a0 I don\u2019t know the\r\nequations of motion for a double pendulum off the top of my head, so we can\r\nderive them.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q1\/dbpendEQNS.png\" alt=\"Derivation of the equations of a double pendulum\"><\/p>\r\n\r\n<p>Aside from the cramp in my hand from attempting to make my\r\nwriting legible, the implementation in base blocks is a little more difficult.\u00a0\r\nThere are physical connections between the state variables, and if implemented\r\nas written above, you get algebraic loops.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q1\/dblpendModelBaseBlocks.png\" alt=\"Simulink model of a double pendulum built from base blocks, includeing an algebraic loop\"><\/p>\r\n\r\n<p><strong>Drawing the Double Pendulum<\/strong><\/p>\r\n\r\n<p>To make a double pendulum using SimMechanics I just\r\nduplicate the first joint and body to make a second arm connected at the end of\r\nthe first.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q1\/dblpendMECH.png\" alt=\"Drawing of a double pendulum as the mechanical elements\"><\/p>\r\n\r\n<p>In literally seconds, I converted the pendulum model to a\r\ndouble pendulum model.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q1\/dblPendModelSimMech.png\" alt=\"Simulink model of a double pendulum built with SimMechanics blocks\"><\/p>\r\n\r\n<p><strong>Now It\u2019s Your Turn<\/strong><\/p>\r\n\r\n<p>How would you model a three-jointed pendulum?\u00a0 How about N-joints?\u00a0\r\nLeave a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=47&amp;#comment\">comment\r\nhere<\/a> and let us know if you would derive the equations, or reach for\r\nSimMechanics.<\/p>","protected":false},"excerpt":{"rendered":"<p>Do you ever have to model mechanical systems?\u00a0 Mechanical\r\nsystems consist of bodies, joints, and force elements like springs.\u00a0 In this post,\r\nI will show you how to model a double pendulum with base... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2009\/02\/26\/modeling-mechanical-systems-the-double-pendulum\/\">read more >><\/a><\/p>","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[30,29,39,10],"tags":[80,79,441],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/47"}],"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\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":6189,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/47\/revisions\/6189"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}