Category Archives: Distance mesurement

Picture treatment

This post is about the method using to determinate the distance between the robot and the Nexus 7 tablet, using tablet’s camera. So I used a picture of the robot to know how the robot is far from the tablet. And with information coming from several cameras I am able to determine the robot position.

photo

In order to know the distance between the robot and the tablet, I built a kind of flag. This flag is a colored circle, so because it is a circle, whatever the perspective, it will be every time the same diameter.

Thus if the robot is far from the tablet, the circle will be smaller in the picture than if the robot was close to the tablet. Thanks to this know, I made some test, take some values, and find the equation.

Sans titre 1

Now, thank to the equation, I know the distance between the robot and the tablet with only a picture. You wan see on the following picture a screen shot of my program, with the distance measurement.

2014_06_17_14.33.13[1]

 

Camera

After tried two methods not enough reliable, this method is my last chance to find a well way to determinate distance between a tablet and a robot.

This method using the tablet camera and Bluetooth. Principle is pretty simple, we assume that the robot start from position 1 to position 2. When the robot leave position 1, it sends a Bluetooth signal to the tablet saying “I am started” (This signal is only a character). Once the robot is arriving at the position 2 it sends another signal indicating the distance between position 1 and position 2 (in centimeters). So we can ask us several questions about this new way:

Is it possible to communicate with Bluetooth between the robot and an Android device ?

Is the measure will be precise ?

Is one camera enough do measure the distance ?

I began by EV3 robot Bluetooth communication. Bluetooth protocol is pretty simple, there are only some important steps to follow:

1) Connector declaration

NXTCommConnector connector = Bluetooth.getNXTCommConnector();

2) Established connection

NXTConnection connect = connector.waitForConnection(0, NXTConnection.RAW);

3) Stream declaration

 DataInputStream dis = connect.openDataInputStream();
 DataOutputStream dos = connect.openDataOutputStream();

4) Read or write information

 short n = dis.readShort();
 dos.writeShort(n);

About Bluetooth on the Nexus 7 tablet, we will use a very simple program, made with processing. First of all, we declared and established the connection between the EV3 robot and the Nexus 7 tablet

 bt = new KetaiBluetooth(this);
 bt.connectToDeviceByName("EV3");
 bt.start();

To send a data you will use :

byte[] data = {'t','e','s','t','\r'};
bt.broadcast(data);

And you will use the event on the buffer to receive the data :

void onBluetoothDataEvent(String who, byte[] data) {
 if (isConfiguring)
 return;

 info += new String(data);

}

Now, we can share information between EV3 robot and the Nexus 7 tablet.

Next step is about picture treatment, I will talk about it in the next post. I used Processing to do picture treatment because it is a more adapted for thus kind of application.

Audio speed

After a first fail, we decided to find another way to measure distance. Since the robot is able to use Bluetooth and it had a loudspeaker, we thought that we could to use the velocity difference between these two kinds of waves to determine distance between the two devices.

For this second test, we will start by sending a 1 KHz audio signal from the robot and then send a Bluetooth signal again from the robot to a Nexus 7 tablet. Given that Bluetooth is faster than audio, Bluetooth wave will arrive earlier than the audio wave. Thus, we need only measuring time from Bluetooth reception to audio reception, and we will be able to find a correspondence between time and meters.

But there are several questions about this job:

– How can the audio wave from the robot be distinguished from ambient sound ?

– Is it possible to do a Bluetooth communication between a robot and an Android device ?

– Which measurement will be precise ?

– What is the maximum distance the devices could be placed from one another?

The first step is to send an audio signal recognizable from the robot. In order to send what I want, I use a  library from LeJOS : lejos.hardware.sound. There is a method playTone that is easy to use and powerful. It will enable you to play what frequency you want, during the time you want, and a the level you want.

package com.ev3;

import lejos.hardware.Sound;

public class Main
{
    public static void main(String[] args)
    {
         Sound.playTone(1000, 10000, 100);
    }
}

Now I have to find a way to receive, analyze, and recognize sound from the robot. Like the first attempt, it will take too much time to do my own application, so I found an application on Google Play called Frequency Analyser that allow to know the frequency of an audio signal received by micro.

2014_06_10_10.31.20

2014_06_10_10.31.20

We can see in the previous picture, that the application showed us the frequency of the received signal. To do this application we use a Fast Fourier Transform. It is really powerful and allows you to know the frequency of a signal.

With this application, we are able to detect an audio signal from about 7 meters. So now, I have to do my own application so as to be able to integrate what I want in addition to the audio part.

I tried to do the same application as the previous one, but it is too complicated and it would have taken me too much time to do the same. So, with my application, I am not able to recognize a signal. I am only able to know what the highest frequency range is. So thanks to the application, I am theoretically able know if my robot is sending me a 1Khz sound wave or not.

2014_06_12_08.34.06[1]

It works well when the robot is close to the tablet and there is no ambient sound, but when they are 2 meters away from one another, and when people are talking and making noise, it does not work anymore.

2014_06_12_08.43.13[1]

 

Seeing previous screens shots, we can conclude that this method could work with a very good sound analysis application. However, with a basic application, we cannot assure the reliability of the measurement, since there will be some noise, and if the devices are placed far from one another the application will not work anymore. I have to recall that this method is based on the very short time difference between two waves, so we MUST have a precise measure.

Because this way is not acceptable, we will talk about Bluetooth in the next post.

RSSI

RSSI : Received Signal Strength Indicator, is a measurement of the power present in a received radio signal.

The first method I used to solve my problem is based on RSSI. RSSI is used to pick up the intensity of a received signal, so if a device is far from another, the RSSI value should be lower than a closer device. This kind of measurement is mainly used with wi-fi, but it could still be implemented with Bluetooth.

In order to get the RSSI value, you need a reliable Bluetooth communication between two devices. It’s not easy to send data between devices that is why once communication is established, the hardest part is over. Now, you have to get back the RSSI value. Look on Bluetooth.device and find  EXTRA_RSSI.(links)

For my tests, I used an application from Google Play  because it would take me too much time to do my own application and there are other applications which are better, such as: Blueooth RSSI Monitor  (https://play.google.com/store/apps/details?id=com.xqapp.brm)

 

In theory, it should work, but now we will test the reliability of RSSI in practice:

For this test, I used my computer and a Nexus 7 tablet. They are both static and 3 meters from each other. The application shows the RSSI value in DB, and we can see on the following graph about 80 measurements, with a value every 2 seconds.

2014_05_20_10.48.43

Y axis : RSSI value (in DB)

X axis : Values (number of values)

According to theory, we should see a constant value because the devices have not moved, but we can observe that signal is very unstable. The value varied from -60DB to -89DB, so we cannot use this method to do a precise measurement.