{"id":8171,"date":"2023-10-23T07:39:33","date_gmt":"2023-10-23T06:39:33","guid":{"rendered":"https:\/\/dronesonen.usn.no\/?p=8171"},"modified":"2023-10-23T07:39:33","modified_gmt":"2023-10-23T06:39:33","slug":"keeping-up-with-the-microbros-week-9","status":"publish","type":"post","link":"https:\/\/dronesonen.usn.no\/?p=8171","title":{"rendered":"Keeping Up With the MicroBros \u2013 Week 9"},"content":{"rendered":"\n<p>Welcome to yet another humble blog post from the MicroBros <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f4aa.png\" alt=\":muscle:\" width=\"20\" height=\"20\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f60e.png\" alt=\":sunglasses:\" width=\"20\" height=\"20\"> ! This week we actually got a new 3D-printed <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f5a8.png\" alt=\":printer:\" width=\"20\" height=\"20\"> frame from Richard <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f647-200d-2642-fe0f.png\" alt=\":man_bowing:\" width=\"20\" height=\"20\">. It lowers the width of the robot getting us even closer to be able to traverse the maze <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f401.png\" alt=\":mouse2:\" width=\"20\" height=\"20\"> !<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Jonathan-\ud83e\uddd9\u200d\u2642\ufe0f\">Jonathan <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f9d9-200d-2642-fe0f.png\" alt=\":man_mage:\" width=\"20\" height=\"20\"><\/h2>\n\n\n\n<p>PERSONALLY IT\u2019S BEEN THE WEEK OF MATH. <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f192.png\" alt=\":cool:\" width=\"20\" height=\"20\"><\/p>\n\n\n\n<p>However, attempts have been made to apply the concepts of last week\u2019s blog post into code <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f914.png\" alt=\":thinking:\" width=\"20\" height=\"20\"><\/p>\n\n\n\n<p>Specifically &#8211; adjusting the yaw orientation of the mouse to be perpendicular to a wall in front of it.<\/p>\n\n\n\n<p>But it ain\u2019t been free of hurdles! <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f635-200d-1f4ab.png\" alt=\":face_with_spiral_eyes:\" width=\"20\" height=\"20\"><\/p>\n\n\n\n<p><strong>Hurdle 1)<\/strong> Writing code that fits into the project\u2019s framework:<br>As we all know by now, our entire framework in C++ is basically hand-made by Mats. While that being very amazing, writing basic code for the system requires extra brain work.<\/p>\n\n\n\n<p><strong>Hurdle 2) <\/strong>A problem I had, which Mats discusses in his part of the blog post, is that the HC-SR04 driver he wrote assumed we use <em>one<\/em> echo pin for <em>all<\/em> HC-SR04 sensors. While cool in theory for saving pins, this introduced some problems for us like requiring a breadboard (extra cables). It also introduced a problem with saving the different sensor values separately. A quick and elegant rework was done by Mats to fix this, and I was able to utilize the driver.<\/p>\n\n\n\n<p>Now, let\u2019s talk about code implementation of the yaw orientation to face perpendicular to a wall. The way we\u2019re solving this currently is by using a PID controller combined with two distance sensors in the front. What the PID controller does in our case is attempt to regulate a value towards a target, by controlling the motors. Here\u2019s how I\u2019ve coded it:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"812\" height=\"298\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-14.png\" alt=\"\" class=\"wp-image-8172\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-14.png 812w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-14-300x110.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-14-768x282.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><figcaption class=\"wp-element-caption\">PID regulate function<\/figcaption><\/figure>\n\n\n\n<p>Here\u2019s an example of regulate being used:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"171\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-15.png\" alt=\"\" class=\"wp-image-8173\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-15.png 592w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-15-300x87.png 300w\" sizes=\"auto, (max-width: 592px) 100vw, 592px\" \/><figcaption class=\"wp-element-caption\">Function that regulates towards perpendicular orientation.<br>Note: fl, fr = front left and front right distances<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Mats-\ud83e\uddd1\u200d\ud83d\udcbb\">Mats <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f9d1-200d-1f4bb.png\" alt=\":technologist:\" width=\"20\" height=\"20\"><\/h2>\n\n\n\n<p>While it has been a busy week I have still been able to make progress!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Fixing-the-HC-SR04-driver\">Fixing the HC-SR04 driver<\/h3>\n\n\n\n<p>On Monday Jonathan told me he had issues with the HC-SR04 driver after I had helped out refactoring it to have separate echo pins. Investigating it I found I had an incorrect explicit move that screwed up the vector holding the sensor configuration, whoops!<\/p>\n\n\n\n<p>Well, I also noticed the timer abstraction I wrote lacked immediate execution meaning timer callbacks just got scheduled which I also changed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Refactoring-the-entire-Simulator-codebase\">Refactoring the entire Simulator codebase<\/h3>\n\n\n\n<p>Well, I may have done a mass refactor of the Simulator this week.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"472\" height=\"38\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-16.png\" alt=\"\" class=\"wp-image-8174\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-16.png 472w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-16-300x24.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/figure>\n\n\n\n<p>So in short the entire Simulator codebase was not meant to do much more than just visualizing the execution of an algorithm in the maze, and all new UI just ended up inside of the same massive class and event loop meaning everything became harder to implement over time.<\/p>\n\n\n\n<p>I\u2019ve split application logic into services which can be accessed through <code>application-&gt;GetService&lt;Service&gt;();<\/code>and it uses the typeid to register and get them from an unordered map, meaning one can register services without adding it to any data structure! In a way this has a lot of overlap with dependency injection.<\/p>\n\n\n\n<p>Also I\u2019ve separated the UI windows into their own contained implementations that use a register pattern identical to the one I made for algorithms.<\/p>\n\n\n\n<p>Also I\u2019ve added an abstract base class for all the interactions the UI does with a \u201cMouse\u201d. For now it is just simulated, but writing a remote mouse class and interacting with BLE should <em>just work<\/em>!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Iver-\ud83d\udc74\">Iver <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f474.png\" alt=\":older_man:\" width=\"20\" height=\"20\"><\/h2>\n\n\n\n<p>This week I have been soldering the sensors to a prototype board. As I barely have any soldering skills this took some time. But after a few hours in the basement I think i got the hang of it.<\/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-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-1-1024x768.jpg\" alt=\"\" class=\"wp-image-8175\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-1-1024x768.jpg 1024w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-1-300x225.jpg 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-1-768x576.jpg 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-1-1536x1152.jpg 1536w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-1.jpg 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-2-768x1024.jpg\" alt=\"\" class=\"wp-image-8176\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-2-768x1024.jpg 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-2-225x300.jpg 225w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-2-1152x1536.jpg 1152w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-2-1536x2048.jpg 1536w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-2.jpg 1600w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\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-3-768x1024.jpg\" alt=\"\" class=\"wp-image-8177\" width=\"364\" height=\"485\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-3-768x1024.jpg 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-3-225x300.jpg 225w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-3-1152x1536.jpg 1152w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-3-1536x2048.jpg 1536w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2023\/10\/Untitled-3.jpg 1600w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/><\/figure>\n\n\n\n<p>This had to be done to make the sensors small enough for the new car. The sensors I made are for the sides of the car, and therefore had to be so small that they could fit between the wheels.<\/p>\n\n\n\n<p>Writing this I still have to make a few changes until I am fully happy with them. So after the kids have gone to bed I will get some of the components closer to the board and soldier them a little more firmly in place. I will also see what I can do about filtering, as that is what I was doing before we where given the new car.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Next-week-on-Keeping-Up-With-the-MicroBros-\ud83e\udec2\">Next week on Keeping Up With the MicroBros <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1fac2.png\" alt=\":people_hugging:\" width=\"20\" height=\"20\"><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Maybe we\u2019ll be driving inside the maze for once <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f697.png\" alt=\":red_car:\" width=\"20\" height=\"20\"><\/li>\n\n\n\n<li>Beep boop Remote debugging <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f916.png\" alt=\":robot:\" width=\"20\" height=\"20\"> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f4bb.png\" alt=\":computer:\" width=\"20\" height=\"20\"> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f4e1.png\" alt=\":satellite:\" width=\"20\" height=\"20\"><\/li>\n\n\n\n<li>Math. <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pf-emoji-service--cdn.us-east-1.prod.public.atl-paas.net\/standard\/caa27a19-fc09-4452-b2b4-a301552fd69c\/32x32\/1f393.png\" alt=\":mortar_board:\" width=\"20\" height=\"20\"><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to yet another humble blog post from the MicroBros ! This week we actually got a new 3D-printed frame from Richard . It lowers the width of the robot getting us even closer to be able to traverse the maze ! Jonathan PERSONALLY IT\u2019S BEEN THE WEEK OF MATH. However, attempts have been made [&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-8171","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/8171","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=8171"}],"version-history":[{"count":1,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/8171\/revisions"}],"predecessor-version":[{"id":8178,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/8171\/revisions\/8178"}],"wp:attachment":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}