I'm trying to calculate the distance between and android device and the HC-05 bluetooth module (connected to an arduino module: the MEGA 2560), using an android app created using appinventor.
For example I'd like to know if the devices are 4 meters from each other so I can turn on an alarm.
After doing some research it seems that is almost imposible to do, it seems that the most that can be done is estimate that distance constantly sensing the RSSI indicator.
Is this possible? if not ,what could I use?
Are the elements of my project (HC05,arduino, appinventor) the ones I should be using?
Is this the only way?
If the two points are within line of sight, then you can use a laser based rangefinder system, or something that uses "Time of flight" using a sound wave or a light wave. Here's one that I found with a quick google: http://hackaday.com/2014/07/01/pew-pew-an-arduino-based-laser-rangefinder/
We run into an issue with omni-directionality though,
If they don't have line of sight, you're going to have to think about how the signal is attenuated with whatever is in the way, because the difference in attenuation between a brick wall, and a gypsum(drywall) wall is great.
Related
I am testing out a positioning system using iBeacon and Altbeacon. I have found that my triangulation results are actually pretty accurate, but sometimes it takes upwards of 5 seconds to see the proper results.
For example, say I am currently standing at Point A. Altbeacon + my triangulation has me properly placed very close to Point A. However, when I move 5 meters away to Point B, I remain around Point A for around 6 seconds and all of the sudden I snap into place right near Point B. Is this an issue with Altbeacon, or possibly the communication between my iBeacons and my Android tablet?
Note: I am using a Kindle Fire 10, running FireOS 5.1.1 on top of Android. The Bluetooth iBeacon technology is BLE, and broadcasts at around 1Hz.
The issue of time lag that you describe may be caused by averaging intervals on the signal measurement. You do not say what scanning framework you are using, or if you are using raw RSSI or a distance estimate as input to your algorithm. The Android Beacon Library by default uses a 20 second averaging interval (configurable) for its distance estimates. Other framework's use similar averaging.
Reducing the averaging interval will lessen the lag, but increase the noise as an input to your algorithm.
EDIT: To reduce the distance estimate sampling interval to 3 seconds from the default 20 seconds, call:
RunningAverageRssiFilter.setSampleExpirationMilliseconds(3000l);
I have tried previously what you were trying to do. There was a lot of issues making it impossible to get correct triangulation results.
Theoretically it should work, but
Practically you will have a lot of challenges, like the fact the Bluetooth Beacon uses the 2.4GHz frequency, almost all Bluetooth Beacon has non-directional antenna, which means that you might risk not measuring the signal source but the reflection of the signal surrounded by the beacon.
The other fact is the noise from other sources or Bluetooth Beacon in your environment.
Depending on the Android phone model, the receiver antenna of Bluetooth is not necessarily mount same place in the phone, that means how you hold the phone will change the RSSI reading
Holding the phone in hand or near human body might also give different readings or no reading at all, since the human body contains water that is a signal reducer/killer for Bluetooth signal.
So even thus you improve your latency time of Bluetooth Beacon by software, you will still have these challenge make it almost impossible to get the right results.
I have seen a new directional Bluetooth Beacon I have not testing it yet, but it sounds like it solving some the mentioned issues.
It is correct what #davidgyoung wrote, but that won’t change the fact of real world scenario.
Btw, I have worked with Altbeacon a very nice and respected tool, and I used both RSSI and distance estimate with different type of Bluetooth Beacon and different phones and it did not help much, it is not Altbeacon the problem.
And regarding the university project I mentioned in my comments, we ended up using Bluetooth Beacon in different way to help us finding directions to target for visually impaired people, and we have developed scientific paper on it.
Finally for inspiration of what you are doing and what I mentioned in my answer, see this video it shows triangulation experiment, the provider of this video is btw also a user at Stackoverflow.
Note: my answer here is focusing on the context of triangulation and the challenges here make it as not a sweet solution.
I want to calculate distance Bluetooth Paired device from android mobile. I am new in Android Bluetooth Concept can any one suggest me it's possible or not possible in android sdk.if it's possible post any code or tutorial link!
The Bluetooth signal strength distance relation depends on the devices (built-in Bluetooth device, antenna, actual orientation of device), current way the persons hold their devices, objects in-between... You could measure this for a pair of devices for a given situation and use these information.
A larger and more general solution would incorporate an external Bluetooth network. Bluetooth triangulation is the basic concept, that will help. The link will give an insight on certainties that are achievable with such a setup. Take is as an upper limit, a device to device approach will be worse.
The EE Stack Exchange site has a more complete answer which includes a mention of Apple using 802.11v for determining if Apple Watch is close to a MacBook.
Bluetooth uses radio, and radio travels at the speed of light. A 1cm round trip will take less than 100ps. Timing something that short will be tricky, probably you'll want a 10GHz clock, though there are other options. But even then, Bluetooth isn't designed to instantly echo the radio message. If you receive, process and re-transmit the message, then the processing delay will be much longer than the time of flight, and will vary randomly by at least the period of the clock used with the Bluetooth chip.
You can't. Maybe, you can get approximate value from signal indicator but it's too much subject because of envirounment - is there something between connected devices, some reflection surfaces, etc.
There is a way you can research, is coding a response time. just calculate the bluethooth response time in nano secs, physically measure the distance between the devices and make a tree rule... is the same concept of GPS. This is a Laboratory work. I have a project that i have to develop it, in schedule i will taking it in a month.
OFC, its possible. It just requires ultra precise app, build to calculate "pings" between the two objects - kinda like ekko-location or laser distance measurement - its about how much time a specific signal travels back and forth.
The project objective is something like this:
We would have a locomotive robot having on-board GPS on it.
Now using that GPS we want to track the position of robot and trace it on android cellphone.
(as they provide best interface with Google services)
Not only that
We even want to control the robot from android cellphone.
Is it possible to send control signal from android cellphone to that robot so that robot can make a move according to control signal.
How can we make a connection between android cellphone and on-board GPS of robot.
(We are somewhat newbie to robotics)
Any better ideas, suggestions are most welcome.
Check out Dension Wirc module:
WiRC module by Dension
It works for RC controlled platforms by sending a pulse width modulated train, allowing you to control servos and electronic speed controllers. There are 8 channels. I'm using it to control 2 tracks and a pan/tilt turret, it works great. I emailed the support team, and they sent me an iPhone project, which got me running in a matter of hours. The WiRC kit comes with a camera, so I can drive my robot remotely via wifi.
In terms of GPS, I did a test on iPhone, under clear sky, and the GPS signal drifts badly. The accuracy is indeed somewhere between 30-50 feet, it is not enough to track position of a small robot precisely. I will post a screenshot of my experiment.
Check out this screenshot: I'm walking along the white paths on the map with the phone in my shirt pocket. Every second it places a pin on the map. You can see how badly the red pins deviate from the white path. This is 30-50 feet off path. For a 2 feet long robot, this is a major trouble. If it tries to correct it's path with such resolution of GPS, it is likely to become very confused.
I've seen a differential drive equation on wikipedia (a motor with slit encoders), counting the number of slits that passed past encoder in a certain interval of time. This may help correct the GPS, but requires additional hardware
I am working on something same like this
I am trying to make an autonomous robot capable of moving itself based on some extensive robotics algorithms but certainly you don't need that.
But I think it will be better for you to mount the Android phone on the Robot and then control it with your laptop via WiFi or any other medium.
Mounting an android phone will have many advantages like:
Having a nice GPS and where there is no need to do extra work to integrate it with other hardware and software.
And you can have other hardware like accelerometer, proximity sensor, gravity sensor etc. which can be useful in many ways.
Now there is a lot of data for making Robots based on Android. Here is the Cellbots
they work on making robots from android and control them remotely from laptops or Android.
I was trying to port Sebastian Madgwich's sensor fusion algorithm ( http://www.x-io.co.uk/node/8 ) to Android, but the first results seem not to be correct, and the resulting quaternion is moving everywhere when the phone is steady. One of the problem might be that I'm not able to sample at the same time the three sensors (gyro, accelerometer and magnetometer), but it looks like Android sensor manager doesn't allow to do so.
Did anybody succeeded in porting the algorithm with more success?
thanks in advance
I haven't implemented this in Android, but I have it working on an iPad 2 for an augmented reality application i'm working on for my MSc thesis. To get it working smoothly I found that it's best to set the update rate for the sensors inline with the frame rate (so, 30hz for me), but it's probably worth experimenting to see what's best for your device.
I'm not sure exactly what you mean by flying everywhere, but sensor drift will probably cause a noticeable amount of error - my objects slowly rotate randomly when the device is at rest. Very annoying, but something you have to accept when using IMUs.
Also, make sure you update the quaternion after you have a new reading from all of the sensors, instead of ofter each sensor gets a new reading separately.
I'm working with android sensor data. My application use
SensorManager.getRotationMatrixFromVector(
mRotationMatrix , event.values);
and it has been working well until this morning, when the rotation matrix started to send a lot of noise data (Change N to W in a second).
It's not a problem with my code, because on friday was working and no changes have been done. I have used a compass app from the market, and the compass is giving random data.
I have tested my app on another tablet, and it is working well.
Does someone know why is this happening? A problem with the sensor? Does it need a calibration?
I've worked quite a lot with these electronic compasses on mobile phones and its quite possible that there is nothing wrong with your code or sensor.
Instead it could very well be a problem with your environment. There are magnetic fields interfering with the earth's magnetic fields all the time. From electrical equipment interference to the metal structure holding up a building. At the end of the day a compass is just a magnet. If you stand beside a large lump of metal the compass will be attracted to it and point to it rather than the magnetic north pole.
Try this:
Install GPS status
then turn off all filtering (settings... gps & sensors...sensor filtering... no filtering).
Do the calibration (figure of 8 wavy stuff) and then move the phone around your desk.. near monitors, cables, etc. You'll see it go crazy. The information is completely unreliable. I found in the past that moving the phone a few inches to the right completely changed its reading. The same happens with a real compass. Strictly speaking there is no "problem". The device's compass is assigning itself with the strongest magnetic field. Even the magnetic content of nearby rocks can interfere with the compass.
As a further test I've just placed a real (orienteering) compass over my phone which has a compass app installed. The real compass is now pointing everywhere but magnetic North. The two devices are interfering with each other.
So my advice is.. go somewhere in the open, like a park or field, away from any potential interference and power lines, (if you have one bring a real compass to check that the GPS status app is pointing the right way), and see if your compass works as you'd expect.
Extra: The answer from #resus is also important when calibrating. Rotate the phone a few times in each axis. Looks silly but it does calibrate it properly.
Extra 2: Would it be possible/practical to use the compass bearing of your GPS? It would require that the device be moving (walking speed should be fine) but you would not need to worry about any interference. It should give an accurate reading provided your GPS signal is good.
Extra 3: Another thought just occurred to me.. You could try apply a low pass filter to the sensor. This means that the sudden changes in the sensor reading are filtered out .. have a look at this answer. And if that doesn't do a good job there are lots of algorithms on the web for you to choose from.
If you definitely haven't changed anything in your code, and it still works fine on other devices, it would suggest a problem with that particular device.
While your app is running (i.e. the compass is in use), you should be able to wave it in a figure of 8 in order to automatically recalibrate the compass. You should also make sure you aren't standing next to any large lumps of metal etc. that might interfere with readings.
You can override the onAccuracyChanged() method of SensorEventListener to flash up a message to the user when the compass requires recalibration (probably when accuracy drops to SENSOR_STATUS_ACCURACY_LOW).
In my experience of playing with the compass on android phones, they can be pretty unreliable...
If your application work on another tablet and other compass application do not work on your device, this is probably due to a bad calibration.
As said in the post above, to make the calibration, wave your device in a figure of 8. I just want to add that you should do it for EACH axis. This should fix your problem.
If it is not a calibration error, as some people have already answered, it is possible that the compass had gone through a magnetic field and now it is desmagnetized, so it is not working properly.
Where do you usually keep the tablet? Could it be that it was near big servers or magnets?
You should check the compass just in case, talk to to android's tech support.
Hope it helps.
I think the question was if calibration could be done without sending any data to compass. Because not everybody says that the compass is calibrated as shown in this video: https://support.google.com/maps/answer/6145351?hl=en and obviously you can not do anything else than advise the user to calibrate before using the program or when you get too much changes.
For example going left and right 90 degrees in about 25 ms.
Anyway I think it's good to give some seconds to the app before start taking data, because it gives some unstable values (too high and low in short time without movement) at the app loading moment.
Just let the handler onSensorChanged() coded with a conditional, and start a thread on the onCreate() handler, which will set a boolean to true, after some seconds.
Then you start to capture data on the onSensorChanged() handler.
Also this thread can help to detect the sensor accuracy, and then you can popup: In Android can I programmatically detect that the compass is not yet calibrated?
I know because I am building a robot using the compass of the smartphone, and I'm having this experience. So, if you are making a robot, make sure to give an spaced place between electronics and hardware to the smartphone, but remember that it's on any compass: electromagnetic fields can be altered by metals so heavily.
Nowadays I have the luck of developing a robot with an HMC-5983 and an MPU-6050, which can be calibrated by using its libraries with Arduino.
That code is compatible/portable to other uController but for not also so easy for smartphones, I guess that the offsets needed for calibrating the compass, the gyro and the accelerometer are inside some internals of Android, not available in the SDK.
I answered before thinking that maybe calibration was only for some devices, but realized that must be as I said before.
So, if playing with robots its possible, I mean it's also easy, but when using an smartphone maybe some custom firmware as CyanogenMod would bring the possibility of investigating the way of setting that offsets, but more important to run some program ported from sketch (following its concept only) to get them first ...
So, good luck ! What is also true, is that in both devices (smartphone and my robot) it's need to move them for them to get working well, as I showed you in the video of latest answer, also helpful on robots.
Good luck and a lot of fun with those things, are very powerful.