Edge Avoider

This a simple project for one afternoon. I wanted to build a robot that moves randomly on a table and doesn't fall down. The results can be seen on this video. For the robot to operate correctly a table mustn't be glass and the lighter colour the better. For those who doesn't have such table I altered the program so that robot stays inside an area surrounded by black line.

The construction is very similar to my other robot Linefollower, but in fact I didn't base my design on that. I wanted to make a universal two-wheel base for my future projects instead. I won't describe the details of such an easy construction. I reccomend watching the building instruction.

The program is not very complicated either. The robot repeatedly reads light intensity and in case of it changing rapidly the robot stops, backs up a bit and then starts turning for a random number of degrees in a random direction. The program is easily customizable. You can adopt it to your lightning conditions and type of surface the robot drives on. You just need to change the CRITICALDIFF parameter.

After finishing building and coding I did some test runs. Everything worked just fine from the first time. I couldn't have been happier. However I advise to be careful about the robot falling from the table. It is possible that robot starts to drive in such a direction that it falls first and then detects an edge of the table. I reccommend using round tables. I thought of building a rotating light sensor to overcome this, but I figured out it is not worth it. Maybe some day I will design my own light sensors for Lego Mindstorms set. These are not hard to build so it will be a quick project.

All in all, the Edge Avoider robot is very simple to build and program and it gives a lot of fun. I reccommend it to everyone - as always!



3D Gallery

To watch pictures in this gallery you need special red-cyan anaglyph glasses. They are to buy in many Internet stores for less than 1$.

Program code

//author: Krzysztof Kapusta, All rights reserved #define MOTORS OUT_BC #define SEN S1 #define WHOLETURN 950 #define DRIVEPWR 100 #define CRITICALDIFF 150 #define TM 60000 task main() { SetSensorType(SEN, IN_TYPE_COLORRED); SetSensorMode(SEN, IN_MODE_RAW); ResetSensor(SEN); int ambient = SensorRaw(SEN); int thld = ambient - CRITICALDIFF; OnFwd(OUT_BC, DRIVEPWR); long ctick = CurrentTick(); while (CurrentTick()-ctick < TM ) { if (Sensor(SEN) < thld) { Off(MOTORS); RotateMotorEx(MOTORS, DRIVEPWR, -250, 0, 1, 0); RotateMotorEx(OUT_BC, DRIVEPWR, Random(WHOLETURN/2), (Random(2)*2 - 1)*100, 1, 0); OnFwd(OUT_BC, DRIVEPWR); //Wait(2000); } } Off(MOTORS); }

Show/hide all the code


Thx. Próbowałem z czujnikami dotyku, ale nie byłem zadowolony. Programuję w Not eXactly C.

Posted by: Admin | 2012-04-22

A i może zrób coś chodzącego, albo jeżdżącego na 2 kołach ;]

Posted by: Ten co wcześniej :) | 2012-04-22

Robot prosty, ale fajny do zabawy :] Można by było go zrobić z 2 czujnikami dotyku :] PS. W czym programujesz? NQC?

Posted by: Anonymous | 2012-04-22

Taki jest mój skryty zamiar :D

Posted by: admin | 2012-04-16

Czy mógłbyś zbudować line followera v3, gdy robisz ten czujnik światła? Tylko takiego, który po drodze może napotkać cegłę

Posted by: Lego mindstorms | 2012-04-16

Post your comment