Week 8/9 : Oop Tree

Object Orientated Programming in CircuitPython to make Digital Trees

We think we’ve taken the Asteroids development as far as we can just now (looking at speeding up the FFT calculations)… but, in the mean time, Phil has started re-visiting an old passion… OOP Trees!

Object Orientated Programming in CircuitPython to make Digital Trees… Phil used to play with Macromedia Director 8 / 8.5 (!) and made some digital trees. Phil’s had an idea of re-visiting making OOP trees, but on the tiny Raspberry Pi Pico using CircuitPython…

Over 2 days, Phil’s successfully written a Tree Class, thinking of a tree as a series of “nodes” – He passed several key parameters to the Tree Class, an X,Y location, how many nodes the tree will have (“the Trunk”), how much those nodes can vary in direction from each other & how far they will be from each other. t = Tree() # Params cut out for ease here

Phil had a brainwave, to define all the lengths & angles “at the start” – and then “simply” multiply the values by a scale (from 0 to 1) – the “age” of the tree… so the entire tree is drawn but “scaled down” (to 0) at the start & in a loop, slowly increase the tree’s “age” by a tiny increment… giving the impression of growth! (it all worked smoothly! Not bad for a self taught N00B(!) – Phil’s sure there are probably a lot of pythonic conventions that need to be learned! ).

So, having a “working trunk” growing & stretching nicely, Phil wondered about adding branches… The thing is, they are nearly identical to a Trunk, just that the base of the 1st node isn’t “at a fixed point” (in the “ground”) – but a node on the Trunk (or even another Branch!). With a quick addition of “fNode” (“follow node”) – the Trunk having fNode = None & a branch having fNode = parentNode, he added in the code.py t.newBranch([2,3,3,4, 10]) The array passed, are positions of nodes in t (duplicates just add more branches to that node!). He even put in an error check to see if a node requested is in the range of the parent’s nodes! IT ALL WORKED! woohoo! The Branch grows just like the Trunk, but its base node follows the position of its parent node!

With the branches & trunk now growing nicely (and stopping growing when it reaches the scale of 1), Phil turned to add in leaves… a new Class “leaf” was added to the script & contains info of a colour of leaf, the radius of the leaf (using vectorIO.Circle objects) . Phil thought that the control of when / where & how many leaves appear should be decided by each node (on the trunk or branches). Passing several random numbers to determine how many, how big, how far away from the node they should be was passed in to the object. A few functions Phil’s made (“utility scripts”) like getting an X,Y position based on a known x,y position + length & angle (using Pythagoras) & adding a random range of R G B values to a “base R G B” colour to get variations of greens / browns (any colour!) – Phil rendered out leaves a hoy! But, things were slowing down again on the tiny Pico… So Phil decided to only render leaves when their parents reached specific criteria (age / length away from root) – and this gave a lovely effect of the leaves slowly blinking into existence, as the tree aged!

Phil was inspired & energised , getting into a “playful” development state…”I’ll try this!” he thought… boom! it works! And so, he added a few playful things, like a random “gust of wind” that jiggles the nodes occasionally, increasing & decreasing the scale quickly with the 2 buttons from week 1 … so many possibilities …

Anyway, if you want to have a play (& probably hone / improve the OOP!) download the scripts for the Pico set up here. Have fun!

Digital Maker CIC – CPD for the College Development Network

Digital Maker CIC had the privilege of being asked to run a robotics challenge workshop for the CDN (College Development Network Scotland) in Dundee & Angus College’s Gardyne campus on Friday 28th of September for over 20 College Lecturers.

Teams from all over Scotland joined us for a fun day, exploring, building & programming robots in order to compete in various challenges once the teams were ready. We gave each team a CamJam robotics kit with minimal worksheets / instructions and spent around 30 mins building the kits, using raspberry Pi Zeros & piTop Ceeds (to control / interface with the robot rover via  5 meter USB cable). the Edinburgh team took the initiative to make their rover wirelessly controlled, downloading & installing software through their own phone (extra points there!)

Once everyone had built & played with their rovers, controlling it via simple on-screen button & programmable interfaces (Custom Adapted Blockly by Digital Maker CIC), we then added a line detection sensor, giving the participants experience in electronics & GPIO use on the Pi Zero. The challenge was to create a line following algorithm using only 1 sensor & the Blockly interface, to get the team’s rover around a line path in the quickest time. There were a lot of different approaches, using repeat loops, “if statements” and more. One of the most elegant solutions was a simple algorithm by West Lothian College.

All teams produced line following algorithms with varying degrees of success, but, all teams were resilient & spent time honing their algorithms, trying various tweaks & fixes based on their observations, critical thinking & experimentation, which was great to see. The fastest line follower was under 1 minute, the longest (complete circuit) was just under 3 minutes.

Some teams managed to start exploring adding an ultrasonic distance sensor (HC SR04) to tackle the minimal maze we had brought along too, but, time had got the better of us, and after 6 hours of playing, experimenting, trying and learning, time was up!

We’d like to thank Kenji Lamb for organising the event & asking Digital Maker CIC to facilitate the workshop. We are planning to run a 2nd CDN Robotics CPD challenge with Kenji in 2019… so if you are interested, or want more information, please do get in touch!