What’s a robot? Our working definition is that it’s a machine that Senses, Thinks, and Acts. Cubelets and MOSS are pretty primitive robots; if you prefer Sense, Plan, Act, they probably won’t be offended.
Anyway, each Cubelet falls into one of the Sense, Think, or Act categories, and one of the main reasons that they seem primitive (compared to a mouse, say), is that they fundamentally work together based on simple, linear, one-to-one relationships. Snap a Distance Sensor onto a Drive block, and the more the distance sensor detects, the faster the motor goes. The less, the slower. All of the Sense and Act Cubelets output basically linear values (or actions) based on their inputs:
A linear, monotonic relationship like this makes simple, perfect, robotty sense, but doesn’t have a lot in common with the messy, biological irregularities and discontinuities that we find in systems that look alive. What if we try something that’s not monotonic: a function that doubles back on itself. How about an easy piecewise function that makes a triangle: y=x for x<0.5 and y=1-x for x>0.5. At Wolfram Alpha, we can plot it like this: Plot[Piecewise[{{x, x<0.5}, {1-x, x>0.5}}], {x, 0, 1}]
I used Cubelets Studio and a Bluetooth Cubelet to reprogram a Knob block to apply this transformation to any data that flows through it. Then I added a Bar Graph so that I could see what was going on and got this:
Which is exactly right, but I want to use the full range of the bar graph, so I’ll make my triangle wave twice as tall by adding a simple 2x. It works, and I know you can picture a full bar graph response so I’m not going to bother with a video. Here’s the code: void loop() { int temp = get_knob(); if (temp <= 127) { block_value = 2 * temp; } else { block_value = 2 * (255 – temp); } }
OK. Now I’m going to switch it up a bit and flash (almost) the same code into a Distance sensor (swapping get_distance() for get_knob()) and build a little mobile robot. It’s a differential drive robot with the modified Distance sensor controlling one motor, and a stock Knob controlling the other for easy tuning. The Passive block is just for balance.
Hm! This little robot looks like it’s attracted to the box but also careful to keep its distance. Is it “thinking”? Is it “intelligent”? Maybe not, but it seems like we’re getting a little closer to intelligence here than we can do with a robot made out of stock Cubelets….