{"id":3351,"date":"2014-03-07T11:44:18","date_gmt":"2014-03-07T16:44:18","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=3351"},"modified":"2017-12-08T11:27:19","modified_gmt":"2017-12-08T16:27:19","slug":"the-simulink-curling-simulator-we-did-it","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2014\/03\/07\/the-simulink-curling-simulator-we-did-it\/","title":{"rendered":"The Simulink Curling Simulator&#8230; we did it!"},"content":{"rendered":"<p>After I published my post on <a href=\"https:\/\/blogs.mathworks.com\/seth\/2014\/02\/05\/win-olympic-gold-with-simmechanics-modeling-figure-skating-and-angular-momentum\">simulating figure skating in Simulink<\/a>, my colleague <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/400549\">Corey Lagunowich<\/a> and I discussed what other Olympic sports would be fun to  model in Simulink. We settled on one of his favorites: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Curling\">curling<\/a>.<\/p>\r\n\r\n<p>We got completely hooked on this challenge and before we knew it, we had a fully detailed simulator allowing you to play complete curling games!<\/p>\r\n\r\n<p>We thought you might be interested, so we decided to share our <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45761-the-curling-game\">Curling Simulator<\/a> on <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/\">MATLAB Central File Exchange<\/a>. In this post we describe how we modeled the dynamics of the moving stones in Simulink.<\/p>\r\n\r\n<p><strong>The Big Picture<\/strong><\/p>\r\n\r\n<p>Our submission primarily consists of a <a href=\"https:\/\/www.mathworks.com\/discovery\/matlab-apps.html\">MATLAB App<\/a> and a Simulink model.<\/p>\r\n\r\n<p>In the App, you decide where you want to aim, how fast you want to throw the stone, and what spin you want to put on it. When you click the <strong>Go<\/strong> button, the MATLAB App starts the Simulink model using the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/sim.html\"><tt>sim<\/tt><\/a> command. While it runs, the Simulink model uses a <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/sfg\/writing-level-2-matlab-s-functions.html\">Level-2 MATLAB S-function<\/a> to redraw the position and orientation of every stone in play.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/curlingSteps.gif\" alt=\"Overview of the curling game\" \/><\/p>\r\n\r\n<p>In this post we are not going into the details of the interactions between the App and the model\u2026 maybe in a future post.<\/p>\r\n\r\n<p>The Simulink implementation of the game dynamics is centered around one <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/secondorderintegrator.html\">Second-Order Integrator<\/a> block. The size of the signal is proportional to the number of stones on the ice.<\/p>\r\n\r\n\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/curling_top_model.png\" alt=\"Top level of the curling simulation model\" \/><\/p>\r\n\r\n<p>Inside the <tt>Curling Model<\/tt> subsystem, we have two main components working in parallel: a contact model and a friction model.<\/p>\r\n\r\n<p><strong>The Friction Model<\/strong><\/p>\r\n\r\n<p>When he started developing a model for the friction, Corey quickly discovered that there is a lot of interest in the scientific community in curling. Understanding the movement of the stones on the ice has important implications in the field of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Tribology\">tribology<\/a>.<\/p>\r\n\r\n<p>Based on what he learned, Corey parameterized <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/ndlookuptable.html\">lookup tables<\/a> to calculate the force exerted by friction on the stone as a function of the stone's speed, angular velocity and the friction coefficient (which is function of how much you sweep\u2026. Be sure you try the sweep button in the App!).<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/curling_lut.png\" alt=\"Lookup Tables computing the friction forces\" \/><\/p>\r\n\r\n<p>There are a lot of things about the behavior of spinning objects on ice that are counter-intuitive at first. For example, the faster you spin a curling stone, the less it actually curls. But if you don\u2019t spin the stone at all, it erratically zig-zags down the ice. Researchers have yet to come to a consensus on the exact mechanisms for all of this behavior (you can read more about it in <a title=\"http:\/\/news.nationalgeographic.com\/news\/2006\/02\/0223_060223_curling.html (link no longer works)\">this article on National Geographics News<\/a> or <a href=\"http:\/\/phys.org\/news\/2013-05-mechanism-stone-revealed.html\">this article on phys.org<\/a>).<\/p>\r\n\r\n<p>Let's see the behavior in our simulator of two consecutive stones, one with low spin, and one with high spin<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/showCurlSpin.gif\" alt=\"Effect of Spin on stones motion\" \/><\/p>\r\n\r\n<p>Watching a simulated stone curl realistically across our virtual ice was pretty exciting, but we couldn\u2019t stop there. We expanded the model to simulate all 16 regulation stones at once. Doing that was actually pretty easy\u2026 all we had to do was drop the friction model for one stone into a <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/foreachsubsystem.html\">For Each Subsystem<\/a>.<\/p>\r\n\r\n<p><strong>The Contact Model<\/strong><\/p>\r\n\r\n<p>But what about simulating collisions? The contact model, we first computes the distance between each pair of stones. If we detect a contact, we compute new initial velocities and reset the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/secondorderintegrator.html\">Second-Order Integrator<\/a> (This logic is similar to the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/examples\/simulation-of-a-bouncing-ball.html\">bouncing ball demo<\/a>).<\/p>\r\n\r\n<p>To manage all the possible combinations of stones hitting each other, I used two nested <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/foriteratorsubsystem.html\">For Iterator Subsystems<\/a> (not to be confused with the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/foreachsubsystem.html\">For Each Subsystem<\/a>) and an <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/enabled-subsystems.html\">Enabled Subsystem<\/a>. That way, the model computes new velocities only for the pair of stones in contact.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/curling_contact_mdl.png\" alt=\"Contact model implemented using nested For Iterator Subsystems\" \/><\/p>\r\n\r\n<p>To compute the transfer of momentum, I found the perfect example in my Meriam and Kraige Engineering Mechanics Dynamics book I had bought during my first undergrad semester.<\/p>\r\n\r\n<p>In the App, I was pretty impressed when I first saw the stones colliding together:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/curlingContact.gif\" alt=\"Curling Stones colliding\" \/><\/p>\r\n\r\n<p><strong>Now it\u2019s your turn<\/strong><\/p>\r\n\r\n<p>Head on over to MATLAB Central, download the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45761-the-curling-game\">Curling Simulator<\/a>, and use Simulink to hone your curling strategy! The 2018 Olympic qualifiers start sooner than you think!<\/p>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/curlingContact.gif\" onError=\"this.style.display ='none';\" \/><\/div><p>After I published my post on simulating figure skating in Simulink, my colleague Corey Lagunowich and I discussed what other Olympic sports would be fun to  model in Simulink. We settled on one of... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2014\/03\/07\/the-simulink-curling-simulator-we-did-it\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[71,30],"tags":[366,368,367],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3351"}],"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=3351"}],"version-history":[{"count":27,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3351\/revisions"}],"predecessor-version":[{"id":6922,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3351\/revisions\/6922"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=3351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=3351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=3351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}