Good day.
I want to make an app which is somewhat very close to the device movement.
In example: If the device moves backward, the unity 3D object should move backward, if forward then the object goes forward in 3D environment, then same and for left and right.
Anyway the workaround i have googled only brought me to accelerometer, which I don't need, as accelerometer is used to detect the tilt and not actual movement. So i wanted to ask, is that even possible to detect the movement of device in unity? If yes, what classes should i look for to achieve what i want.
Thank you beforehand.
Jow Blow's comment is correct: The accelerometer gives the acceleration (you don't say). Tilt can be found from the amount of acceleration, but other movements will be seen as well. If you are standing still and start moving forward, your accelerometer value will show it (since you accelerated).
There is no device that will measure if you are moving forward at constant speed on your phone. If you know a bit of physics you find more obvious why the accelerometer doesn't work: because constant speed means that the resultant of forces is null. So there is no force to detect.
If you need to detect constant speed and plan to move for a rather big distance, however, you could try using the GPS position but if you need a high precision, you won't be able to do it with a standard device.
Forget about detecting moving at constant speed on a short distance easily. A solution could be to detect an acceleration and estimate the direction and speed resulting from it (speed = time*acceleration). This method won't be really precise as any error will add up but it could be sufficiant
Related
My goal is to have a simple stroke rate detector displayed on my Android Watch (Sony Smartwatch), for this I need to detect when the watch changes from moving forwards to moving backwards.
I have code working that will get the event values (x,y,z) as detected in the onSensorChanged event (and display them on the watch), but I am struggling to make sense of these.
I understand the values report acceleration in the given axis, and I understand that z reports gravity. But if these values are reporting just acceleration, I am not clear how to know when there is a change of direction. I presume a positive number indicates acceleration, a number of 0 is a constant speed and a negative number is deceleration...is that correct? And if so, how can I detect when the Watch has changed direction from going forwards to going backwards?
Thanks in advance.
Android Wear is no different than "conventional" Android when it comes to detecting motion. Basically, you need to consider exactly what the accelerometers are recording: raw acceleration (with a lot of noise). To determine motion from that, you need to look at trends over time, and probably integrate the smoothed accelerometer data. It's not trivial.
You'll probably want to use the TYPE_LINEAR_ACCELERATION sensor, because it filters out gravity (which isn't relevant to your use case). And because the watch will probably experience some rotation during a rowing stroke (which you want to factor out), you may need to combine TYPE_ROTATION_VECTOR with the acceleration vector to accurately determine direction changes.
A couple of other SO questions which may help point you in the right direction:
how to calculate phone's movement in the vertical direction from rest?
How can I get the direction of movement using an accelerometer?
I've not attempted this specific problem, of course, but I've done enough other work with Android motion sensors to know that you have a good programming challenge ahead of you. Enjoy it!
I have a scenario,
I have kept my android device in the car. Can i check if the car is moving using accelerometer.
you may not be able and has nothing to do with maths or the system you choose. Inertial velocity cannot be measured at all. Without looking outside the car you cannot distinguish wether it is moving or not if speed is constant. The phone won´t be able on doing that with the accelerometer, maybe with the camera...
you may need two cameras, though, because you have to measure distances and triangulate where you are and where you´ve moved to in a time period. And what if the cameras fix a point on a plant or a tree that keep waving with the wind?
would not gps be better?
I'm trying to write a small android game where the phone is placed on the table.
On the screen there is a ball, which the user control its movement by moving the phone.
Along all the game the user won't lift the phone from the table.
At the beginning the ball will placed in the middle of the screen:
Pushing the phone from the user:
should move the ball toward the top of the smartphone screen:
And from the current position of the ball, moving the phone back to the user, and to the right:
will move the ball accordingly:
I read the Android Motion Sensors Guide carefully but I didn't even realize what Sensor \ Sensors should I use.
I would love to get any directions.
First of all TYPE_LINEAR_ACCELERATION, TYPE_ROTATION_VECTOR, TYPE_GRAVITY are not physical sensors but made from sensor fusion.
Secondly from Android 4+ these fused sensors make use of device Gyroscope, so they WON'T work if the mobile device doesn't has a gyroscope.
So if you want to make a generic app for all phones prefer using only Accelerometer (TYPE_ACCELEROMETER).
Now for your case since user won't lift the mobile from table, and if you want you can easily subtract the Gravity component from accelerometer. See http://developer.android.com/reference/android/hardware/SensorEvent.html
under section Sensor.TYPE_ACCELEROMETER. (Code is given too).
Now you can see How can I find distance traveled with a gyroscope and accelerometer? to find the linear displacement & the 1st answer states their is NO use of Gyroscope. (Or you can just google for finding the displacement/Linear velocity from acceleromter readings)
Hope this all would give you quite lot an idea.
It's really difficult to do this type of linear position sensing using the types of sensors that smartphones have. Acceleration is the second derivative of position with respect to time. So in theory, you could use the accelerometer data, integrating twice in time to achieve the absolute position. In practice, noise makes that calculation inaccurate.
On the other hand, if you're really talking about putting the camera facedown on the table, maybe you can come up with some clever way of using OpenCV's optical flow features to detect motion using the camera, almost like an optical mouse. I don't know how you would light the surface (the flash would probably burn through the battery) but it might be possible to work something out.
I have a question regarding inertial navigation with a mobile device.
I am using an android tablet for development but I think the question is related to
all types (even with better sensors) of hardware.
The most basic question when developing an inertial system is how to determine the
direction of the carrier's movement.
Even if we assume that the magnetometer readings are 100% accurate (which they are obviously not!) There is still the question of the device orientation relative to the user.
Simple example - if the user is walking north, but holds the device with the device's Y axis points north-east, (a link to a picture of the different axis: http://developer.android.com/reference/android/hardware/SensorEvent.html)
Then the magnetometer will point towards north-east.
How can we tell which way the user is actually heading?
(The same will be true if we use both magnetometer and Gyro for determining heading)
A possible solution will be to use the Accelerometer's Y-axis and X-axis readings.
Something in the direction of using arctan(a-Y/a-X)
(for example - if the user holds the device perfectly straight, then the X-Axis will show nothing...)
But since the Accelerometer's readings are not stable, it is not so easy...
Does anyone know of an algorithm that actually works? I am sure this is a well known problem, but I can't seem to find references to solutions...
Thanks in advance!
Ariel
See this answer for an idea: by obtaining the acceleration values in relation to the earth, you can then use the atan2 function to compute the actual direction.
You mention the user holds the tablet, and I assume fairly stable (unlike a case I am working on, where the user moves the phone constantly). Yet, for some reason, the user may change the orientation of the device, and this may influence the readings you obtain.
Thus, in the event of an orientation change, you should call remapCoordinates() accordingly to fix the readings you obtain.
NOTE: You can also use the getOrientation() method accordingly, and the first field represents the heading direction.
The really right answer is to leave the device sitting there for a while, detect the rotation of the earth, and then compute true north from that. Unfortunately, the gyros in a mobile phone aren't accurate enough for that....
I would like to detect when the phone is in motion, but not all kind of motion. For example picking up or waving the phone should not trigger.
I would like ideally to run a code when the phone/person is in > "walking" state. What options I have?
you can use a combination of the accelerometer and the digital compass, in phones that have them, to determine a speed and direction.
If all you need to do is determine if the person is walking, all you need is the accelerometer. Just process its output for foot steps.
There are plenty of tutorials on the web for detecting foot steps with an accelerometer.
You can also get your location from Wifi-Networks and Cell Towers. All location providers in Android are subclasses of android.location.LocationProvider. That's probably a good place to start. I don't know that either of those would be best for you, as their "range" can be several hundreds of feet wide.
Android accelerometer provides us the feature to know the acceleration using SensorEvent class. So use the object of the class, and handle onSensorChanged(), to determine the movement in the device.
x = sensorEvent.values[0];
States the acceleration in x direction.
So what you may be interested in is, find acceleration in x,y and z directions, and try to calculate the Average and standard deviation for the last 10 such samples.
Working on the standard deviation will surely get you to the right point! If it goes to 0, it means device is still. If SD>0.5 for more than 15sec's or so..it means device is continously moving! Lemme know if you need more help!
Cheers,
Nithin