Skip to the content.

End of Week 8 01/11/25

This blog seems a little early, but that is just because of how recently the last one got written. Only 5 days between them, but we got a lot done. That UI rendering app I talked about, Bokeh, well, we got it running. In our first trial, we used the “fake” data scenario to produce ten random points. What I mean is, the data randomized coordinates and displayed the points on the map. This told us something very important: the program works! Knowing this, it was a matter of testing the code we had already made for the robot to go in real life. As I have probably already mentioned, I used trigonometry to map exact coordinates for the motion. The robot moves a centimeter at a time, and turns when its in danger of smashing its nose on the wall. As it goes on its merry way, working around the room slowly but surely, it communicates its position after each move. A line of dots allows for a rough estimate of room dimensions. A program, I recently realized, similar to the one used by roomba vacuums like the one my mom got for Christmas. The problem is not the concept. In theory, all of this works. Of course on our first attempt, though, we recieved a pesky error. And second. And third. What could be wrong? Well, that was a reasonable question. But even more pressing, how could we know what was wrong? This wasn’t codecademy. The active terminal informed us of our failure simply by not working. Not helpful, but not unreasonable. Often, in the real world, there isn’t a big, knowledgable hand that reaches from the sky and pushes you into the light. Computer science is no exception. Even in this age of AI, when it seems plausible an ape could soon type “Hello world!”, the answer is not always clear. So we had to debug. Not the first time, we debugged our flask code when we initially set that up a week or so ago. VSCode offered us the ability to set break points throughout the code at critical points, and it would stop if it reached buggy code. We were able to “Run and Debug” at the click of a button. This feature unfortunately did not work, though, because you can’t attach the debugger to the robot when it is running python. More and more, my dad is having me figure out solutions to problems with little to no help from him. This was the case multiple times during the week, including here. The one piece of advice he did offer was to create “manual breakpoints.” I went hog wild, throwing down ‘print(debug ‘’)’ after just about every line of code. Eventually I was able to narrow it down to a specific line or two of code. Turned out there were discrepencies between the variable names in flask and python. But the important thing was that I picked up a new debugging method. A method which I am certian I will use again. Anyway, after we got the robot reconnected to the wifi (we need to automate this tedious process eventually), it was functional. Very innacurate, but functional. After that was cleanup and refinement. The code I cranked out was incredibly messy. Finding the source of inaccuracy was like finding a bride in a brothel. So what came next was a very valuable teaching moment. My dad cleaned up the code and I watched. This is the kind of thing that must be taught in my humble opinion. As I watched him condense, delete, and unify, I realized how much I had to learn. The content was not changed. I had the basic idea, thankfully. But the simplification and increase in readability made it seem like the real deal. The accuracy was affected by a simply problem wrapped in a mess of code. Basically, there was a calculation I made to approximate the rotation in one centimeter. A rotation of 31.83098863 degrees! intuitive! Combine this with the fact of the sensor measuring in millimeters and the conversion necessary, as well as the mix of abbreviated and unabbreviated variable names (an apparent software warcrime), and you have a bot who’s poor little head is swimming. After cleanup, it was far more accurate. Still plenty of work and refinement, but much progress. I will make a big project video for this when it is all said and done.

Takeaway:

-While my dad guided me through the cleanup process, I tried to impress him by citing a coding philosophy I heard which stated “if it works don’t fix it.” He wasn’t impressed. This philosphy didn’t necessarily apply anyway, seeing as my code was hardly functional. But his point was that messy code had no longevity. He said the creater of Friendster (a precursor to Facebook if you didn’t know) should be one of the richest men on earth, but that the app crumbled when its user base skyrocketed. The program couldn’t keep up, and when it came time to expand, they instead drowned in unfixable, unreadable code. I will continue to start messy, but I am going to try to make my code easy to reorganize. Because truly, readability is a key player in code.