{"id":1079,"date":"2024-12-26T01:20:12","date_gmt":"2024-12-26T00:20:12","guid":{"rendered":"https:\/\/sharedinventions.com\/?p=1079"},"modified":"2024-12-26T01:20:13","modified_gmt":"2024-12-26T00:20:13","slug":"playing-with-ramp-library","status":"publish","type":"post","link":"https:\/\/sharedinventions.com\/?p=1079","title":{"rendered":"Playing with Ramp library"},"content":{"rendered":"\n<p>I was aiming for a smooth transition for one of my Arduino projects, the first tool for that is the ramp library. While the library itself is quite nice, I miss some more comprehensive documentation of it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Working principle<\/h2>\n\n\n\n<p>Ramp is meant to be used with motors, like servos, to ease up the start and stop, and having less stress on the parts, make more pleasant movements.<\/p>\n\n\n\n<p>With ramp, you specify a target value to reach, and the time should take to get there. Ramp will calculate the actual value you should be in while the time is passing by.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Problems<\/h2>\n\n\n\n<p>The first problem in my reading, that ramp should not know the time on it&#8217;s own, it would be better if it was passed to it, e.g. &#8220;calculate the current position to me, if the current time is 120ms!&#8221;.  Or maybe just send ramp the current percentage of the journey, as we might not use the calculation on time basis. This would give a more clear way of the job. Finally I found the &#8220;no-automation&#8221; mode, that I will explain later.<\/p>\n\n\n\n<p>The second problem is, that all motors (contraptions) has their acceleration limit. The motor might not be able to keep up with the expected (calculated) values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bug<\/h2>\n\n\n\n<p>I have created a test program for that, it goes from 0 to 255 within 5000 milliseconds in 100ms steps and repeat this with LOOPFORWARD. Thus, we should have 50 steps.<\/p>\n\n\n\n<p>The first interesting observation was just here, as we made 50 steps for the first loop, but 49 steps any further iterations. After some digging, I figured out, that this is a bug with LOOPFORWARD and I have created an issue with that: https:\/\/github.com\/siteswapjuggler\/RAMP\/issues\/26<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Interpolation modes<\/h2>\n\n\n\n<p>The first question starting on ramps might be, which interpolation mode to use. I have generated a visualization with a test program and utilizing LibreOffice Calc. The graph below shows one raising session for all interpolation modes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-forward.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-forward-1024x576.png\" alt=\"\" class=\"wp-image-1086\" srcset=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-forward-1024x576.png 1024w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-forward-300x169.png 300w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-forward-768x432.png 768w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-forward-660x371.png 660w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-forward.png 1193w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Forward interpolations<\/figcaption><\/figure>\n\n\n\n<p>Here you can see another graph, this time both IN and OUT are interpolated with one full cycle of FORTHANDBACK.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-backandforward.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-backandforward-1024x576.png\" alt=\"\" class=\"wp-image-1087\" srcset=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-backandforward-1024x576.png 1024w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-backandforward-300x169.png 300w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-backandforward-768x432.png 768w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-backandforward-660x371.png 660w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2024\/12\/ramp-backandforward.png 1283w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Note, that some interpolations do overshoot, this is intended to be so, but you must take care on that, if you want to use them. E.g. if you are using 8 bit unsigned integer (aka. char) to store the value, it will overflow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Grain<\/h2>\n\n\n\n<p>Now, grain is a phrase not very well described. Grain is a time span in milliseconds. The idea behind it (in automated mode) is to spare calculating the value if &#8220;grain time&#8221; was not passed since last call.<\/p>\n\n\n\n<p>While grain itself is proper, it has drawbacks. As you can also see in the graphs, sometime the change of the value is quite fine, it would require smaller grain-time to achieve a nicer curve. But that would require the grain to be altered dynamically. Further more the grain should be altered by the interpolation, that would complicate things.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Non-Automated mode<\/h2>\n\n\n\n<p>Again, This mode is not very well documented. The idea here is to not let Ramp to figure out the time difference, but Ramp will assume &#8220;grain time&#8221; was passed since last <code>update()<\/code> call.<\/p>\n\n\n\n<p>This is very useful if you already utilized some time-keeping in your project.<\/p>\n\n\n\n<p>There is only one thing to keep in mind using non-automated mode: <code>go()<\/code> is already step no.0 and further <code>update()<\/code> calls will always assume grain time was passed since the last step. (Meaning first <code>update()<\/code> call will assume grain time was passed since <code>go()<\/code> was called.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was aiming for a smooth transition for one of my Arduino projects, the first tool for that is the ramp library. While the library itself is quite nice, I miss some more comprehensive documentation of it. Working principle Ramp is meant to be used with motors, like servos, to ease up the start and\u2026 <span class=\"read-more\"><a href=\"https:\/\/sharedinventions.com\/?p=1079\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":1086,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-misc"],"_links":{"self":[{"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/posts\/1079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1079"}],"version-history":[{"count":7,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/posts\/1079\/revisions"}],"predecessor-version":[{"id":1088,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/posts\/1079\/revisions\/1088"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/media\/1086"}],"wp:attachment":[{"href":"https:\/\/sharedinventions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}