Reproducing a learned geometrical object using drawing pen of Robotnacka robot
Matej Švantner, Samuel Sitáš
Intro
This project uses Robotnacka robot, which is equipped with six binary sensors on the bottom, which report log.0 when there is white colour under the sensor and log.1 when black.
This robot also has five ultrasonic sensors, our program is equipped with routines for their periodic checking and showing in canvas, but the main part of the project is using reflective sensors on the bottom.
The program is functional, but nowhere near final stage. However, main parts work, and that's important.
Main functions
Aplication has two main functions. First is reproducing geometrical shape drawed on the floor. Robot travels along the lines and when finds out that it completed the "circle" and returned to the start coordinates, stops (hopefully).
This shape is exported to textfile specified in one of the textfields. All buttons and fields have tooltips, so if you are not sure what the button does, hover cursor over it.
Textfile is an ordinary csv/txt format, each line contains X and Y coordinates separated by ';'.
Second important function is reproducing this recorded shape by drawing with pen of the robot. You just have to type the filename into second textfield and press a button.
Algorithm
Robot uses custom algorithm for line following. It tries to keep front sensor near the edge, but in the black part. While it is on the black, robot goes forward and reports sensor coordinates to textfile. Careful, it reports SENSOR XY, not robot's XY (which are in the center of the robot). We need sensor's XY for precise representation.
When the sensor comes out of black, robot turns slightly to left and right, if it finds black, continues. If there is no black (sharp turn etc.), robot starts special procedure. It enables all 6 sensors, slightly turns and therefore gets knowledge about 360° circle. It compares, whether it is closer to the black line turning left or right and turns that way.
Drawing algorithm
We can not use direct coordinates. Robotnacka doesn't know where it is and you can't tell it to go to XY coordinates. Therefore we always need to use two successive ([n] and [n+1]) points with XY coordinates. From these points we make a vector, we calculate its length and direction using trigonometry. Then we tell the robot which direction should it turn and how many steps forward should it go.
Downloads
All videos are slow, recorded in real time. It is recommended to use good player a.k.a VLC and speed them up few times.
Capturing a star shape
Drawing a star shape
Complete archive with videos, source code, and whole NetBeans Project