{"id":8063,"date":"2023-10-15T21:58:23","date_gmt":"2023-10-15T20:58:23","guid":{"rendered":"https:\/\/dronesonen.usn.no\/?p=8063"},"modified":"2023-10-15T21:58:23","modified_gmt":"2023-10-15T20:58:23","slug":"keeping-up-with-the-microbros-week-8","status":"publish","type":"post","link":"https:\/\/dronesonen.usn.no\/?p=8063","title":{"rendered":"Keeping Up With the MicroBros &#8211; Week 8"},"content":{"rendered":"\n<p>Hey there, beautiful human beings! \ud83d\udc96\u2728Another week has passed and it has now been an entire month since we lost a member, so we must be doing something right! \ud83c\udf89<\/p>\n\n\n\n<p>While we still need to downsize the robot so it can actually fit the maze there are still plenty of other progress in preparation for this.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Jonathan \ud83e\uddd9\u200d\u2642\ufe0f<\/h2>\n\n\n\n<p>This week I\u2019m exploring alternatives to the localization feature I\u2019ve previously had a look at. I suspect there are simpler ways to track the position of the mouse, that involve fewer sensors and are more intuitive. My problems to solve are the following:<\/p>\n\n\n\n<p><strong>Determine the coordinates of the mouse inside the maze.<\/strong><br>Let <em>f<\/em>, <em>l<\/em>, and <em>r<\/em> be the distances measured from the mouse to the nearest walls in the front, left-hand and right-hand directions respectively. These will be measured with ultrasonic sensors. Incremental changes in these variables will be denoted <em>df<\/em>, <em>dl<\/em> and <em>dr<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-8.png\" alt=\"\" class=\"wp-image-8068\" width=\"399\" height=\"336\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-8.png 840w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-8-300x253.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-8-768x646.png 768w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><figcaption class=\"wp-element-caption\">System visualized with variables <em>f, r <\/em>and <em>l.<\/em><\/figcaption><\/figure>\n\n\n\n<p>Before we can trust these distance values, we must know either know the angle the system is heading and include this in our calculations, or just use regulation techniques to make sure the system is perpendicular to the front wall, and parallel to the side walls.<br>There are two ways I want to consider in regards to regulating the system towards being perpendicular to the front wall. The first way is to have two distance sensors facing the same direction and rotate the system until the difference between the two readings are 0.<\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"903\" height=\"726\" src=\"http:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-9.png\" alt=\"\" class=\"wp-image-8069\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-9.png 903w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-9-300x241.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-9-768x617.png 768w\" sizes=\"auto, (max-width: 903px) 100vw, 903px\" \/><figcaption class=\"wp-element-caption\">Using two distance sensors in the front. Not perpendicular if not equal.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"820\" src=\"http:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-7-1024x820.png\" alt=\"\" class=\"wp-image-8067\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-7-1024x820.png 1024w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-7-300x240.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-7-768x615.png 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-7.png 1284w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Finding a distance minima indicates perpendicular orientation. Uses only one distance sensor in front.<\/figcaption><\/figure>\n<\/div>\n\n\n\n<p>We can also attempt to find a perpendicular orientation the front wall by using our left and right distance sensors by assuming that these distances should not change when performing a forwards or backwards movement of the system. Any changes in the values will indicate a non-perpendicular orientation and can thus be regulated towards 0. Combining these methods with the front-facing sensors can provide extra redundancy or replace the front method altogether. \ud83c\udfaf<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-10-1024x831.png\" alt=\"\" class=\"wp-image-8070\" width=\"459\" height=\"372\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-10-1024x831.png 1024w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-10-300x243.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-10-768x623.png 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-10.png 1104w\" sizes=\"auto, (max-width: 459px) 100vw, 459px\" \/><figcaption class=\"wp-element-caption\">Changes in side-distances over time indicates non-perpendicular orientation.<\/figcaption><\/figure>\n\n\n\n<p>The approach we can take to make sure the system is always in the middle of a \u201ctile\u201d is simply by regulating the left and right distances until their difference is 0. However, when an unbalanced amount of tiles appear on either side, we must utilize modulo division to stay centered in our tile and not regulate towards an unwanted center. \ud83c\udff9 <\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-4-1024x655.png\" alt=\"\" class=\"wp-image-8072\" width=\"498\" height=\"318\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-4-1024x655.png 1024w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-4-300x192.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-4-768x491.png 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-4.png 1475w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><figcaption class=\"wp-element-caption\">Regulating towards center alignment using side sensors and modulo division.<\/figcaption><\/figure>\n\n\n\n<p>Now, when we are safe to assume the orientation and centralization of the system, we can attempt to determine its position. \ud83d\udc4a<\/p>\n\n\n\n<p>Remember <em>df<\/em>, <em>dl, <\/em>and <em>dr?<\/em> Let\u2019s combine them with the orientation of the system \u03b8 to track the system\u2019s changes in position in the following way.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-6.png\" alt=\"\" class=\"wp-image-8074\" width=\"486\" height=\"275\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-6.png 1019w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-6-300x170.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-6-768x436.png 768w\" sizes=\"auto, (max-width: 486px) 100vw, 486px\" \/><figcaption class=\"wp-element-caption\">Formula for change in position based on distance sensors <em>f<\/em> and <em>l<\/em>.<\/figcaption><\/figure>\n\n\n\n<p><strong>Determine placement of walls in the maze.<\/strong><\/p>\n\n\n\n<p>If we assume the position of the system and its orientation, any obstructions detected by our ultrasonic sensors can be interpreted as walls and thus placed into our virtual maze.<br>This method is performed in two steps: 1) Determine the tile in which the wall exists, and 2) determine the direction of the wall inside its tile (top, right, left, down).<br>The below image shows how we can calculate the tile numbers based on distance readings and floor division.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-11-667x1024.png\" alt=\"\" class=\"wp-image-8075\" width=\"403\" height=\"618\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-11-667x1024.png 667w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-11-195x300.png 195w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-11.png 698w\" sizes=\"auto, (max-width: 403px) 100vw, 403px\" \/><figcaption class=\"wp-element-caption\">Determining tile in the y-direction based on distance and floor division.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Mats \ud83e\uddd1\u200d\ud83d\udcbb<\/h2>\n\n\n\n<p>Monday this week went to watching Jan Dyre\u2019s presentation about signal processing. In addition these are things I have done throughout the week:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Implement callback-based timers \u23f2\ufe0f<\/h3>\n\n\n\n<p>CODAL already has ways to interact with the system timer, but it is event based and needs to be provided an integer that will be sent with to a common event handler and not the more normal high-level callback per timer one, many of us are used to.<\/p>\n\n\n\n<p>However implementing this on top was easy and something I did when implementing output smoothing for the motor driver, here is the code!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"718\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-12-1024x718.png\" alt=\"\" class=\"wp-image-8076\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-12-1024x718.png 1024w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-12-300x210.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-12-768x539.png 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-12.png 1387w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>It is not perfect, and you can easily run out of id\u2019s for timers when creating one-shot ones rapidly, at the moment this is not an issue, but it is something to watch out and rectify if they ever become used somewhere in the code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Implementing output smoothing for the DFR0548 driver \ud83d\udede<\/h3>\n\n\n\n<p>So in short, switching the direction of a motor while running has a high chance of triggering over-current protection. So I wrote some code that will smooth this transition if the values are for opposite directions and this seems to have helped.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Writing a C++ driver for the HC-SR04 \ud83d\udccf<\/h3>\n\n\n\n<p>On Monday Jonathan asked me if I could make a C++ driver for the ultrasonic sensor this week, something I did. I decided to write it in a way to support multiple sensors with a shared echo pin.<\/p>\n\n\n\n<p>Using the CODAL event system that uses interrupts internally I was able to move on from blocking on the waiting for the falling edge on CPU to just using the CODAL pulse event, meaning the driver only sleeps the 10us needed for the trigger signal!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-13-1024x608.png\" alt=\"\" class=\"wp-image-8077\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-13-1024x608.png 1024w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-13-300x178.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-13-768x456.png 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-13-1536x913.png 1536w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-13.png 1656w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Implementing flood fill \ud83c\udf0a\ud83d\udeb0<\/h3>\n\n\n\n<p>Building on the research done by Iver previously I decided to implement flood fill in our Core library meaning it can be used in the Firmware and tested in the Simulator.<\/p>\n\n\n\n<p>I implementing it by adding another vector with values for every tile, I default initialize the ones with a goal to 0 and add them to a stack, and then all the others one to the max value.<\/p>\n\n\n\n<p>After that I iterate the stack until empty and add 1 to the value and check if any of the adjacent tiles have a higher value and are not blocked by a wall, if so update the value and add to stack.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/2023-10-10_19-58-19.mp4\"><\/video><\/figure>\n\n\n\n<p>There are still things that can be done. One is better direction prioritization, when there are multiple ways you can go towards the goal, right now forward is always prioritized.<\/p>\n\n\n\n<p>Also instead of just having map tiles away from goal there can be some kind of weights keeping track of turns and costs of movement to give more accurate information time wise, but these are not a high priority for now!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Iver \ud83d\udc74<\/h2>\n\n\n\n<p>After to more trying than should be necessary I have got the IR sensor to work as it should. But I have gotten it to work at last. Now all we need is to calibrate the sensors and run them thru a filter to remove interference from other light sources, and we should be good to go!<\/p>\n\n\n\n<p>Testing the IR sensor<\/p>\n\n\n\n<figure class=\"wp-block-video aligncenter\"><video controls src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/IR-Sensor-Test.mp4\"><\/video><figcaption class=\"wp-element-caption\">Testing the IR sensor<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Next week on Keeping Up With the MicroBros \ud83e\udec2<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>Maybe<\/em> we\u2019ll get to rebuild the robot so it fits the maze<\/li>\n\n\n\n<li>Potentially some refactoring when it comes to the Simulator<\/li>\n\n\n\n<li>An even worse opening to the weekly blog post<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Hey there, beautiful human beings! \ud83d\udc96\u2728Another week has passed and it has now been an entire month since we lost a member, so we must be doing something right! \ud83c\udf89 While we still need to downsize the robot so it can actually fit the maze there are still plenty of other progress in preparation for [&hellip;]<\/p>\n","protected":false},"author":95,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8063","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/8063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/users\/95"}],"replies":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8063"}],"version-history":[{"count":2,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/8063\/revisions"}],"predecessor-version":[{"id":8080,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/8063\/revisions\/8080"}],"wp:attachment":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}