Vacumm Cleaner Part 1

  So the next program we have to do is the Vacumm Cleaner. This practice si divided in two parts, here is the development of the first part wich consist on implementate a simple Crash-Turn. Let''s get down to work!


My first implementation is defined by three cases:

1. Go Forward

2. Go Backwards

3. Turn

So knowing with self.bumper.getBumperData().state if it has collide or not, the robot would decide wich action have to do.

In case it hasn't crash (bumper state return 0) it can keep going forward.

In case it has crash it will separate from the object wich had collide with (going backwards).  How long? well, i use the interactions of the programn to stablish the "time" so if the number of iterations from once it has collide to now is less than 10 it would send the motors the order of going backwards. If the number of iterations is bigger it would stop and pass to the state of turn.

In the case of turning first the robot will decide randomly to wich side it's going to turn. Once is decided the time while is going to be on this state is calculated as in the Go Backwards case.


The final result of this is:



Not really efficient, isn't it?

Let's make some improvements.


First one, im going to make that if the robot crash on the left side it would go backwards and then turn to the side in wich is not the object in this case to the right. We can know this information using:  self.bumper.getBumperData().bumper  where 1 is Left, 0 is Center and 2 Right. Now it wouldn't turn randomnly,


it will turn to the oposite side of the collision. In case it crashes on the center it would randomly decide to wich side turn.

The second change: it won't turn all the time the same number of iterations. With this we avoid to start an infinite loop in wich the robot always go and crash with the same things. So when it has to turn it randomly chose the number of iterations between 7 and 20. I set 7 becouse less is very short (so it can't turn properly) and 20 becouse more or less 25 is a 180º turn, i want it to be a little less.


The final result:




Finally instead of using the bumper to know if the robot has crashed or not i ended using the laser. So with this the robot wont hit the walls or the objets it finds on its way.

To do this it was as simple as get the information of the laser using laser.getLaserData(), then with the function parse_laser_data(laser_data) that apperas in the JdRobot page i get a list with the distance witch is measuring the laser at one point and its angle. This list will help me to know if the laser is detecting any object to close. 

How? well i create a function wich travel along each position of the list and looks if the distance in each position is small if its is small i save it on a variable. Then when the list ends i look if this smallest distance is less than the minimum distance to an object, if it is i send a crahs an the side where it has "collide". How to know the side? if the smallest distance was between 0 and 80 the laser point wich measure this belongs to the left side, if it is between 80 and 100 is on the center, else is on the right side (this where the numbers that fitted better from my point of view).

The result:

Comments

Popular Posts