- Plan
From now on, we will start to use Python to program the kittenbot. I had problems when using MuEditor, so I will use Atom to write the code. I decided to program my kittenbot to move when an object was between what the ultrasonic sensor determined was between a distance of 15 and 100 units, slowing down as it got closer, as if it was curious or afraid of what it was.
- ProgramThe code I wrote (with help from Tristan and Rudi), that ended up working, was this:
-
from microbit import *
-
import robotbit
-
while True:
-
d = robotbit.sonar(pin1)
-
if d > 10 and d < 100:
-
s = d * 2
-
robotbit.motor(1, s, 0)
-
robotbit.motor(3, s, 0)
-
else:
-
robotbit.motorstop(1)
-
robotbit.motorstop(3)
When I tested it, it advanced towards my leg and then stopped once it got close, and kept doing so as I moved around as long as my leg was at a distance the ultrasonic sensor could see.
-
- Analysis and reflection
An example in nature that behaves similar to how my robot behaves could be a predator, like a tiger or a bear, they follow the prey while hiding and then surprise them. Of course, the latter part cannot be replicated by a robot as simple as this one, but there is definitely room for improvement in the first part, specifically callibrating the speed of the motors so that the robot moved in a straight line and check the function so that the motors always have enough power to move until they need to stop.