{"id":16452,"date":"2023-02-20T09:00:09","date_gmt":"2023-02-20T14:00:09","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=16452"},"modified":"2023-02-21T19:22:10","modified_gmt":"2023-02-22T00:22:10","slug":"bouncing-rod-simulator","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2023\/02\/20\/bouncing-rod-simulator\/","title":{"rendered":"Bouncing Rod Simulator"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871\"><span>Jiro<\/span><\/a><span>'s Pick this week is <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/57857\"><span>Bouncing Rod Simulator<\/span><\/a><span> by <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3778932\"><span>Matthew Sheen<\/span><\/a><span>.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>As a mechanical engineer, I love simulating physical phenomena. When you have equations of motion, you can easily simulate them in MATLAB using <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/math\/choose-an-ode-solver.html\"><span>ODE solvers<\/span><\/a><span>. Of course, you can also simulate dynamic systems with Simulink or with our physical modeling tools. With ODE solvers, you can detect events to simulate things like a <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/math\/ode-event-location.html#bu7wjcg\"><span>bouncing ball<\/span><\/a><span>. (By the way, here's an example of a <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulation-of-a-bouncing-ball.html\"><span>bouncing ball<\/span><\/a><span> simulated using Simulink).<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>When I saw this simulation of a bouncing rod by Matthew, it brought me a smile. This is a nice extension to the bouncing ball simulator:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>The rod moves in 2 dimensions. Positional states include <\/span><span texencoding=\"\\left[x, y, \\dot{x}, \\dot{y}\\right]\" style=\"vertical-align:-5px\">$ \\left[x, y, \\dot{x}, \\dot{y}\\right] $<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>The rod can also rotate. Rotational states include <\/span><span texencoding=\"\\left[\\theta, \\dot{\\theta}\\right]\" style=\"vertical-align:-5px\">$ \\left[\\theta, \\dot{\\theta}\\right] $<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Collision (contact) with the ground can happen in multiple cases: top tip of the rod hitting the ground, bottom tip of the rod hitting the ground, or the rod hitting the ground (mostly) parallel to the ground. Based on the situation, the new states for the rod are calculated.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>There are two different modes of operation: flight and sliding. Typically the rod is in flight mode. When the rod reaches a certain state, it eventually switches to sliding mode.<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/pick\/files\/potw_bouncing_rod_1-1.png\" width = \"464\" height = \"362\" alt = \"\" style = \"vertical-align: baseline; width: 464px; height: 362px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Once the simulation finishes, it shows the animation of the dynamics.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/pick\/files\/potw_bouncing_rod_2.gif\" width = \"800\" height = \"800\" alt = \"bouncing_rod_animation.gif\" style = \"vertical-align: baseline; width: 800px; height: 800px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>This is a great example to understand the concept of ODE solvers and the event-handling capability of the solvers. This serves the purpose of teaching those concepts. There are, however, a couple of additional effects that could be added to this simulation to make it even more true to the physics.<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Add friction - you can see this especially once the rod goes into sliding mode. The rod keeps sliding forever. Adding frictional forces to <\/span><span style=' font-family: monospace;'>slidingPhase.m<\/span><span> can accomplish this.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Improve the switching logic for sliding - currently, the rod switches to sliding mode when it detects that the center of mass (COM) is close to the ground. This logic indicates that when the COM is close to zero, the rod is nearly parallel to the ground. This may be a reasonable logic for most cases. However, it doesn't accurately represent a case where the rod falls down flat on the ground with vertical speed. In reality, the rod will bounce up due to impact, but the simulation switches to sliding in this case. Here's an example of a case where the rod falls parallel to the ground. One approach would be to look at not just the COM but also the vertical speed of the rod. Another approach is to calculate the states after collision, and switch to sliding mode only if the vertical speed is below a threshold.<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/pick\/files\/potw_bouncing_rod_3.gif\" width = \"500\" height = \"500\" alt = \"flat_fall.gif\" style = \"vertical-align: baseline; width: 500px; height: 500px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>These are improvement ideas, but they don't take away any of the value this entry provides to people wanting to simulate dynamic systems with event handling.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Comments<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Very well done, Matthew! Give this a try and let us know what you think <\/span><a href = \"https:\/\/blogs.mathworks.com\/pick\/?p=16452#respond\"><span>here<\/span><\/a><span> or leave a <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/57857\"><span>comment<\/span><\/a><span> for Matthew.<\/span><\/div>\r\n<\/div><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/potw_bouncing_rod_2.gif\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Jiro's Pick this week is Bouncing Rod Simulator by Matthew Sheen.As a mechanical engineer, I love simulating physical phenomena. When you have equations of motion, you can easily simulate them in... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2023\/02\/20\/bouncing-rod-simulator\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":16491,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/16452"}],"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\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=16452"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/16452\/revisions"}],"predecessor-version":[{"id":16503,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/16452\/revisions\/16503"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/16491"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=16452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=16452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=16452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}