How to use the sensors

Using the sensors

Now we will use the proximity sensors to prevent the robot from falling off the table. There are nine proximity sensors on each Thymio II: 5 at the front, 2 underneath and 2 at the back. The ones underneath can be used to stop at the edge of the table.

Proximity sensors

A proximity sensor can measure the distance to nearby objects. To do this two different components are used: an infrared emitter and a receiver. The emitter radiates infrared light (invisible to us) and the receiver measures how much of this light is reflected and comes back. If an object is close, a large part of the light will be reflected from it and returns to the robot. If the object is farther away, only a small part of the light comes back. In this way it is possible to measure the distance to objects.

In our case, the bottom sensors will be used to detect the table. Put the robot on the table and observe the value of prox.ground.delta (click refresh) shown in Aseba Studio (Memory, variables).

proxtable.png

Now do it again while holding the robot in the air. You can see the value changes a lot.

proxvide.png

When the robot is on the table, the values are about 600 (a lot of light comes back). When it is lifted up, the values are much smaller (not much light). So we will add at the bottom of our code this condition :

If the value of one of the two sensors is too low (no table detected), we stop the motors. Now you can see that the robot stops at the edge of the table.

The debugger

It may be that while testing the robot, we want to see in more details what is happening. This can help us to correct errors in our code or to run the instructions step by step. In our case we shall look what happens when the robot reaches the edge of the table.

In Aseba Studio, if we do a right-click on the line

    call leds.top(32, 0, 0)

we can select Set breakpoint
Screen%20Shot%202012-05-04%20at%2011.57.48%20AM.png

The breakpoint is shown by a red square at the left.

Screen%20Shot%202012-05-04%20at%2012.05.09%20PM.png

This means that when we arrive at this point, the robot will wait until we tell it to continue.

Let's try it. We first have to remove the tick in the auto box if we want to keep the values at the breakpoint. Once the breakpoint is set, we can make the robot move to the edge of the table. It stops; we can observe the situation at this moment, for example we see here that the bottom sensors measured the values 151 and 45 (not much light, so the table is not being detected).

Screen%20Shot%202012-05-04%20at%2012.19.28%20PM.png

As soon as we click again on Run the robot continues (it lights up red) until the next breakpoint. We can remove the breakpoint by a right-click on the breakpointed line and then selecting Clear breakpoint.

previous page | next page

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License