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.
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.
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.
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.
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.