I've been doing a bit of research on a problem we are trying to solve. I think this is the best approach but please add in your opinions
We are trying to calculate reaction times in a real world driving scenario and would like to use a mobile phone as the data collection device. What we are trying to accomplish is how much acceleration and more importantly deceleration a driver exerts when exposed to certain prompts.
I found this paper that has allot of useful information Accelerometer physics
The problem is that we most likely will not have a calibration time to start at zero.. however it is assumed that the driver is starting at 0. We will use GPS positioning to locate the vehicle, tracking the time stamped location data we should calculate the time when the prompt took place then using the time stamped accelerometer data we should be able to calculate their reaction to the prompt.
This is the best way I have found to solve the problem however I'm not sure if the accelerometer data will be rendered useless because of not being able to calibrate it and also the noise seen from vibrations may be too great to use the data... Has anyone tried or used these types of methods before?
Interesting application.
You are missing an important point. You either have to implement the so-called sensor fusion yourself or use the sensor fusion provided on the platform you are using. Both Android and iPhone have one.
The TYPE_LINEAR_ACCELERATION (Android, SensorManager) or userAcceleration (iPhone) should be sufficient for you.
As for the linked PDF, don't try integrating the acceleration, you will get very poor results. Even though that answer is about position, the velocity will already be inaccurate. I would try the GPS instead.
I know it's very old question but since I am recently working on a similar project let me share what we did in our company. We simply used OBD-II dongle to get velocity of car. There are many API's that return information about vehicle.
PID010D returns speed of vehicle. I'm using this PID to calculate distance between points A and B since there is no PID to return Odometer :(
There are few libraries on github that you can find easily by search. This mine. This is not library but after run on your device you can see how it works.
Related
I would like to figure out how to locate a device by its connection strenght(dBm). Even if this don't give me a direct location, it could give me a radius of the device to the phone or the other way around. So far i've been able to gather the device name and RSSI "strenght" however, its a dynamic data i'm getting. I would like an continuously update of how good the strenght is. So the part I'm stuck on is getting the correct values(ive got -72dbm and -342654dbm form the tests) and i need updates every 3 second.
What you should really do is use the Android Beacon Library, it will work the distance out for you.
The actual calculation is very complex and this Library has been used by a lot of people since Radius Networks created it. The link is for the website downloads, but you can use gradle too.
It's easy to use and probably exactly what you're looking for
I'm trying to write an android code that uses the device sensors to detect freefall scenario.
I searched the web a lot for a solution to this problem but I was unable to find anything useful.
I did see that there are several apps that does exactly this so it is possible, but i didn't find any code sample or tutorial on how to do that.
Can anyone please help me with a code snippet or even with a mathematical calculation using the sensors data?
Thanks in advance
The device is in free fall if the length of the vector given by TYPE_ACCELEROMETER is approximately zero. In theory, it should be exactly zero, in practice, it well be only near zero. So you need to come up with some threshold by trial and error and declare that the device is in free fall if the length of that vector is below this threshold.
Check out the API here SensorEvent Values and the math behind FreeFall here Wikipedia.
You are trying to detect speed in some direction. Look at the motion equations on wikipedia. You are detecting acceleration over time that is normalized for the gyroscopic rotation of the device.
Also see: How to approach Fall Detection Algorithm
From what I've read, the accelerometer normally measures gravity. Thus, if you're in freefall and the device is not being moved laterally, all accelerometer readings should be zero. (Disclaimer: I have not written any accelerometer code.)
Google the iFall project by a group at Florida State University. The have published a paper describiing the approach they took for their Android iFall application, which gives a host of references for further/extended study. They also have an API available and explain how to use it, if you want a fast shortcut approach. (To use their API, I believe you just need to download and install their iFall app form the Playstore)
I've been doing a bit of research on a problem we are trying to solve. I think this is the best approach but please add in your opinions
We are trying to calculate reaction times in a real world driving scenario and would like to use a mobile phone as the data collection device. What we are trying to accomplish is how much acceleration and more importantly deceleration a driver exerts when exposed to certain prompts.
I found this paper that has allot of useful information Accelerometer physics
The problem is that we most likely will not have a calibration time to start at zero.. however it is assumed that the driver is starting at 0. We will use GPS positioning to locate the vehicle, tracking the time stamped location data we should calculate the time when the prompt took place then using the time stamped accelerometer data we should be able to calculate their reaction to the prompt.
This is the best way I have found to solve the problem however I'm not sure if the accelerometer data will be rendered useless because of not being able to calibrate it and also the noise seen from vibrations may be too great to use the data... Has anyone tried or used these types of methods before?
Interesting application.
You are missing an important point. You either have to implement the so-called sensor fusion yourself or use the sensor fusion provided on the platform you are using. Both Android and iPhone have one.
The TYPE_LINEAR_ACCELERATION (Android, SensorManager) or userAcceleration (iPhone) should be sufficient for you.
As for the linked PDF, don't try integrating the acceleration, you will get very poor results. Even though that answer is about position, the velocity will already be inaccurate. I would try the GPS instead.
I know it's very old question but since I am recently working on a similar project let me share what we did in our company. We simply used OBD-II dongle to get velocity of car. There are many API's that return information about vehicle.
PID010D returns speed of vehicle. I'm using this PID to calculate distance between points A and B since there is no PID to return Odometer :(
There are few libraries on github that you can find easily by search. This mine. This is not library but after run on your device you can see how it works.
I'm creating an application that gets the users speed whilst driving using the Android Location class. The problem that I am facing is that every post on a forum or article explains problems with the getSpeed() method. Having just gone into my car to test several times, it returns 0. I am not sure why, just wondering if anyone has been able to find out why and how to get the actual speed?
Thanks in advance
getSpeed works just fine, provided you have a capable GPS hardware in your device and you have enough satellites in sight. I am using it for a flight logging application.
One issue with getSpeed is, that the emulator will always return 0; even if it is fed with NMEA data which has speed info. So testing requires the real devices.
If the GPS receiver is inside the car, one issue might be, that it cannot acquire enough satellites in time for your test. Try leaving the device near the windshield (if it is not covered with a reflective surface based on something metallic!) and give it time to get a fix. Consider using a GpsStatusListener to get a count of visible satellites.
The trick mentioned above to compute speed from distances of samples requires filtering of the data. The more samples you use the more noise you get (which needs filtering, search for it here, there are several articles on stackoverflow on this topic). The less samples you use the greater is the error when not moving on a straight line.
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.