{"id":12551,"date":"2025-11-07T18:26:27","date_gmt":"2025-11-07T17:26:27","guid":{"rendered":"https:\/\/dronesonen.usn.no\/?p=12551"},"modified":"2025-11-21T13:24:27","modified_gmt":"2025-11-21T12:24:27","slug":"aroweek-11","status":"publish","type":"post","link":"https:\/\/dronesonen.usn.no\/?p=12551","title":{"rendered":"AROWEEK 11"},"content":{"rendered":"\n<p><strong>Bram van den&nbsp;Nieuwendijk<\/strong>&nbsp;<\/p>\n\n\n\n<p>This week, I began by 3D printing several parts and doing some laser cutting to continue building the prototype. The bottom section of the prototype is now ready for testing as soon as the wheels (currently being 3D printed) are completed. The rotation mechanism for the top part in the x-direction is also ready to be tested. Additionally, I sent more parts to Richard for 3D printing so I can start assembling the y-direction rotation mechanism. Hopefully, these parts will be ready next week, allowing me to begin testing the full prototype. Once the prototype performs successfully, I plan to replace the laser-cut components with 3D-printed ones.&nbsp;&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"546\" height=\"543\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-45.png\" alt=\"\" class=\"wp-image-12553\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-45.png 546w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-45-300x298.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-45-150x150.png 150w\" sizes=\"auto, (max-width: 546px) 100vw, 546px\" \/><\/figure>\n\n\n\n<p><strong>Sulaf Bozomqita \u2013 Week 11: Acceleration Logic &amp; Smarter Avoidance<\/strong><\/p>\n\n\n\n<p>This week I focused on improving the obstacle detection system by adding acceleration\/deceleration control and refining the avoidance maneuvers. As usual, I worked independently for this segment. Now, the reason decided to implement the acceleration and deacceleration was because I know this would make a smoother and safer navigation for the robot.<\/p>\n\n\n\n<p>Last week, I successfully integrated my module with \u00c5smund\u2019s motion control interface by making a MotionControl class too, to test and validate my module with the navigation module in reality, using a lookup table for PWM values. However, the speed changes were very abrupt in my opinion, and that would translate onto the robot as less smooth navigation. In addition, the avoidance was based on fixed delays. Thus, my goal this week was to make transitions more realistic and dynamic.<\/p>\n\n\n\n<p><strong>Updates made this week with the code:<\/strong><\/p>\n\n\n\n<p>I added acceleration and deceleration values for a smoother transition during navigation. I implemented a gradual speed changes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When resuming navigation, the speed ramps up smoothly instead of jumping to full speed (no more sudden movements).<\/li>\n\n\n\n<li>When stopping for an obstacle, the PWM decreases gradually and not suddenly (you can see that in the colsole, the progression of slowing up and down while navigating around an obstacle).<\/li>\n\n\n\n<li>Used timestamps and formulas for acceleration:<\/li>\n<\/ul>\n\n\n\n<p>v=v<sub>0<\/sub>+a\u22c5t (the physics formula for speed). And for the stopping distance: s=v<sup>2<\/sup>\/2a<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dynamic Avoidance Maneuvers:<\/p>\n\n\n\n<p>I also made a dynamic avoidance maneuverability this week, so that when it backs up, it does so until the front sensor reads a safe distance (instead of having a fixed time).<\/p>\n\n\n\n<p>The new updated code also turns left or right based on dynamical sensor readings. Then, to maneuver around an obstacle, it resumes forward with gradual acceleration for smoother recovery.<\/p>\n\n\n\n<p>Code of what I updated and improved on this week (as stated above):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"627\" height=\"265\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-50.png\" alt=\"\" class=\"wp-image-12559\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-50.png 627w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-50-300x127.png 300w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/figure>\n\n\n\n<p><em>This shows the speed used, utilizing the PWM for speed as well.<\/em><\/p>\n\n\n\n<p><em>The acceleration function for smoother transition I made this week:<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"559\" height=\"148\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-51.png\" alt=\"\" class=\"wp-image-12562\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-51.png 559w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-51-300x79.png 300w\" sizes=\"auto, (max-width: 559px) 100vw, 559px\" \/><\/figure>\n\n\n\n<p><em>The deacceleration function for stopping I made this week:<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"198\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-53.png\" alt=\"\" class=\"wp-image-12563\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-53.png 751w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-53-300x79.png 300w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/figure>\n\n\n\n<p>The rest of the code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"745\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-54.png\" alt=\"\" class=\"wp-image-12560\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-54.png 735w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-54-296x300.png 296w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/figure>\n\n\n\n<p><strong>Testing Setup:<\/strong><\/p>\n\n\n\n<p>Hardware is still unavailable, so I continued using simulated sensor readings and PWM outputs. But again, it does not affect any of my code.:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"252\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-52.png\" alt=\"\" class=\"wp-image-12558\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-52.png 533w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-52-300x142.png 300w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/figure>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"588\" height=\"388\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-55.png\" alt=\"\" class=\"wp-image-12561\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-55.png 588w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-55-300x198.png 300w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><\/figure>\n\n\n\n<p>The console logs show the gradual acceleration steps when resuming speed, dynamic avoidance decisions based on sensor data, and a smooth PWM transitions during emergency stops.<\/p>\n\n\n\n<p><strong>\u00c5smund Wigen Thygesen<\/strong>&nbsp;<\/p>\n\n\n\n<p>This&nbsp;week&nbsp;I&nbsp;was&nbsp;going&nbsp;to&nbsp;set&nbsp;up&nbsp;our&nbsp;compass with the raspberry pi. We were planning&nbsp;on using&nbsp;an&nbsp;LSM303DLHC accelerometer and compass IC,&nbsp;but it was unfortunately forgotten about when we sent in our list of components to buy&nbsp;and now&nbsp;it&#8217;s&nbsp;too late to get it. So&nbsp;instead&nbsp;we&#8217;re&nbsp;going to use a&nbsp;microbit&nbsp;for its compass.&nbsp;<\/p>\n\n\n\n<p>The plan was to have the&nbsp;microbit&nbsp;act as a slave I2C device, just&nbsp;forward&nbsp;it&#8217;s&nbsp;own compass data&nbsp;to the master when&nbsp;requested. However, turns out the&nbsp;microbit&nbsp;I2C chip is hardwired to be a master,&nbsp;the raspberry pi&nbsp;<em>can&nbsp;<\/em>be configured as a&nbsp;slave&nbsp;device and it should technically work to&nbsp;use a setup like that to achieve what we want, but initially I dismissed that thought and considered other options and found a different solution.&nbsp;<\/p>\n\n\n\n<p>The other data busses are also unavailable since our PCB which interfaces with the&nbsp;raspberry pi has already been made and the pins are occupied. However, the&nbsp;microbit&nbsp;v1.5&nbsp;uses a similar compass IC to what we were planning on using and&nbsp;the I2C bus that the chip is connected to is the same as the one that is exposed to the edge connector&nbsp;(this is not the case for&nbsp;microbit&nbsp;v2+). This means I should be able to communicate directly with the compass from the raspberry pi, so long as those&nbsp;pins are set as floating in the&nbsp;microbit&nbsp;processor.&nbsp;&nbsp;<\/p>\n\n\n\n<p>The IC is an LSM303AGR, which&nbsp;i&nbsp;found out is not supported by the library I was planning&nbsp;on using&#8230;and I&nbsp;can&#8217;t&nbsp;seem to find&nbsp;an appropriate&nbsp;library&nbsp;for it.&nbsp;So&nbsp;I guess this&nbsp;is a good opportunity to&nbsp;learn more about the I2C protocol.&nbsp;&nbsp;<\/p>\n\n\n\n<p>After&nbsp;some&nbsp;reading&nbsp;I was able to read the&nbsp;magnometer&nbsp;registers on the chip using the&nbsp;smbus&nbsp;library, which does&nbsp;writing&nbsp;and reading of registers over I2C for you. So now I was able&nbsp;to read the data, but it was not calibrated and could not be used to&nbsp;accurately&nbsp;tell the angle of the vehicle.&nbsp;&nbsp;<\/p>\n\n\n\n<p>At&nbsp;startup&nbsp;the A and C config registers are set, we mostly just use default values,&nbsp;except the A register, where we set the sample rate to 50Hz&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"817\" height=\"88\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-44.png\" alt=\"\" class=\"wp-image-12552\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-44.png 817w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-44-300x32.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-44-768x83.png 768w\" sizes=\"auto, (max-width: 817px) 100vw, 817px\" \/><\/figure>\n\n\n\n<p>Then we just need to read the output registers and combine&nbsp;the bytes for each&nbsp;component, this code is&nbsp;essentially a&nbsp;copy from a forum post and am realizing they also do a twos compliment conversion, which I&nbsp;don&#8217;t&nbsp;think is necessary, but&nbsp;I&#8217;ll&nbsp;have to look more into that next week.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"810\" height=\"375\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-46.png\" alt=\"\" class=\"wp-image-12554\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-46.png 810w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-46-300x139.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-46-768x356.png 768w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/figure>\n\n\n\n<p>So&nbsp;I needed to do some calibration, initially I tried a simple calibration technique that I found in the same forum I&nbsp;used to&nbsp;base my&nbsp;initial&nbsp;code on, but it turned out to not really help much, not enough for our purposes at least.&nbsp;So&nbsp;I moved on to&nbsp;reading through&nbsp;the&nbsp;microbit&nbsp;source code to find their drivers and calibration code.&nbsp;&nbsp;<\/p>\n\n\n\n<p>When the only magnetic field present is that of the earth, a perfect&nbsp;magnometer&nbsp;should in theory produce&nbsp;a constant signal&nbsp;magnitude&nbsp;across the x,&nbsp;y&nbsp;and z axes.&nbsp;So that is what the&nbsp;microbit&nbsp;calibration code tries to correct to and is the approach I took as well.&nbsp;&nbsp;<\/p>\n\n\n\n<p>The calibration has 3 steps<img loading=\"lazy\" decoding=\"async\" width=\"515\" height=\"93\" src=\"https:\/\/dronesonen.usn.no\/db2e2f0d-0d74-416f-9e26-a3ac43dca269\">&nbsp;<\/p>\n\n\n\n<p>First&nbsp;I&nbsp;obviously need to sample some datapoints to use for the calibration. Here I found that doing 80 reads&nbsp;over 10 seconds works well, and as the data is&nbsp;sampled&nbsp;I tilt&nbsp;the&nbsp;microbit&nbsp;smoothly around trying to get&nbsp;a somewhat even&nbsp;coverage of datapoints across our imaginary sphere.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Then we need to get the centre of the sphere, which importantly is different from the centre of the datapoints, since the datapoints can be more&nbsp;densly&nbsp;populated on one side of the sphere, but we need the centre&nbsp;of the sphere.&nbsp;We start by taking the average and use that as a starting point, then we use a hill climb algorithm to iterate towards the centre, this is the&nbsp;was&nbsp;microbit&nbsp;does it, but I first decided I wanted to try implementing a gradient descent algorithm which should be able to do it faster and more elegantly. I&nbsp;did&nbsp;kinda&nbsp;succeed, but my implementation&nbsp;ended up not being faster and&nbsp;generally being&nbsp;more inconsistent, so I fell back on&nbsp;basically just&nbsp;copying what&nbsp;microbit&nbsp;did&nbsp;and ended up with this.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"901\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-49.png\" alt=\"\" class=\"wp-image-12555\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-49.png 705w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-49-235x300.png 235w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/figure>\n\n\n\n<p>From there we&nbsp;essentially find&nbsp;the point furthest from our centre and call the distance from it to the centre our radius. Then&nbsp;we calculate the scale factor needed for each point to be on the sphere, then&nbsp;add the x,&nbsp;y&nbsp;and z components to a &#8220;scale weight&#8221; vector, which we normalize and&nbsp;multiply with the largest scale factor to get our final scale vector.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"786\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-48.png\" alt=\"\" class=\"wp-image-12556\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-48.png 781w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-48-298x300.png 298w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-48-150x150.png 150w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-48-768x773.png 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/figure>\n\n\n\n<p>To apply the&nbsp;calibration&nbsp;we simply subtract the centre position from the reading and multiply by the scale vector.&nbsp;I also&nbsp;take a couple&nbsp;readings&nbsp;and average them&nbsp;for consistency.&nbsp;&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"313\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-47.png\" alt=\"\" class=\"wp-image-12557\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-47.png 859w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-47-300x109.png 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2025\/11\/image-47-768x280.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<p><strong>Rick Embregts<\/strong>&nbsp;<\/p>\n\n\n\n<p>This week most components for the PCB&#8217;s have arrived. Now I have to wait for the PCB&#8217;s themself to arrive to begin the assembling process. While picking up the pcb components I noticed that the motor&#8217;s weren&#8217;t with the package. Due to miscommunication, it was believed that we didn&#8217;t need the motors anymore. This is a big setback since we need to get the vehicle operational as soon as possible.&nbsp;<\/p>\n\n\n\n<p>Since I didn&#8217;t know when the pcb&#8217;s would arrive, I started working on a backup plan for the electrical system. In this backup plan the entire system gets powered by a PSU from school. In this backup plan the motorcontroller wil be borrowed from school and the relay for the spray motor will be seperate from the motor controller. Next week the schematic for the backup plan well be ready.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bram van den&nbsp;Nieuwendijk&nbsp; This week, I began by 3D printing several parts and doing some laser cutting to continue building the prototype. The bottom section of the prototype is now ready for testing as soon as the wheels (currently being 3D printed) are completed. The rotation mechanism for the top part in the x-direction is [&hellip;]<\/p>\n","protected":false},"author":114,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12551","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/12551","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\/114"}],"replies":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12551"}],"version-history":[{"count":2,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/12551\/revisions"}],"predecessor-version":[{"id":13110,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/12551\/revisions\/13110"}],"wp:attachment":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}