Lab 4 – Braitenberg Machines – Andres Malaga

  1. 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.

  1. ProgramThe code I wrote (with help from Tristan and Rudi), that ended up working, was this:
    1. from microbit import *

    2. import robotbit

    3. while True:

    4.     d = robotbit.sonar(pin1)

    5.     if d > 10 and d < 100:

    6.         s = d * 2

    7.         robotbit.motor(1, s, 0)

    8.         robotbit.motor(3, s, 0)

    9.     else:

    10.         robotbit.motorstop(1)

    11.         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.

  2.  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. 

Leave a Reply