Main Content

MyTurtle: self-learning robot (Part 3 - Head and Bumpers)

This project is about creating a self-learning robot. Part 3 is about adding a head and bumpers to the movement unit.

In the previous part (Part 2 - Movement unit) I wrote about making a chassis for the movement unit of the self-learning robot MyTurtle. In this part I am going to add checking obstacles with the ultrasonic sensor HC-SR04, bumpers to record a hit and show all the actual code to serve the movement unit.

This project has a longer code so I created more tabs in the software to make things clear and easily accessible. Parts of the code lower are from these tabs.

Ultrasonic head
As I wrote in the first part (Part 1 - Basic idea) MyTurtle will think and learn. These two basic assumptions forced me to decide how it will work with the ultrasonic sensor to avoid obstacles. As I mentioned I do not want to tell MyTurtle what to do. It can only check the actual status (Neuron) and react to it (Action) due to its previous experiences.

So I decided that MyTurtle will always see the obstacle in front of its head. But it can turn its head to the left, to the right or forward. Moreover it can check obstacles around it. In this case it will not see an obstacle in front of its head only but all around (left, front, right).

The code about the ultrasonic sensor contains 2 functions - isObstacle() and CheckObstacles(). The return value of isObstace() is true if an obstacle is 10cm or less in front of the head. CheckObstacles() returns the status of obstacles around to write into Neuron. We will talk about it in other parts.”

Link to article