Reputation: 109
I would like to develop a personal app for this i need to detect my car's rotation. In a previous thread i got an answert to which sensors are good for that it's okay. Now i would like to ask you to please summerize the essential/needed mathematical relationship. What i would like to see in my app: - The car rotation in degrees - The car actual speed (in general this app will be used in slow speed situation like 3-5km/h)
I think the harder part of this is the rotation detect in real time. It will be good to the app could work when i place the phone in a car holder in landscape or portrait mode.
So please summerize me which equations,formulas,realtionships are needed to calculate the car rotation. And please tell me your recomendation to which motion/position sensor are best for this purpuse (gravity,accelerometer,gyro,..)
First i thought that i will use Android 2.2 for better compatibility with my phones but for me 2.3.3 is okay too. In this case i can use TYPE_ROTATION_VECTOR which looks like a good thing but i don't really know that it can be a useful for me or not?
I don't want full source codes i would like to develop it myself but i need to know where can i start, what deep math knowlegde needed and what part of math are needed. And for sensor question: i'am a bit confused there are many sensors which are possible ok for me.
Thanks,
Upvotes: 1
Views: 398
Reputation: 18151
There is no deep math that you need. You should use TYPE_MAGNETIC_FIELD
and TYPE_GRAVITY
if it is available. Otherwise use TYPE_ACCELEROMETER
but you need to filter the accelerometer values using Kalman
filter or low pass filter. You should use the direction of the back camera as the reference. This direction is the azimuth
returned by calling getOrientation
, but before calling getOrientation
you need to call remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR)
to get the correct azimuth
. Then along as the device is not laying flat, it does not matter what the device orientation is (landscape or portrait). Just make sure that the phone screen is facing the opposite direction of the car direction.
Now declare two class members startDirection
and endDirection
. In the beginning, startDirection
and endDirection
have the same values, now if the azimuth
change by more than say 3 degrees
, there is always a little fluctuation, then change the endDirection
to this value and continue to change until say 20 returned azimuth
have the same values (you have to experiment with this number). This mean that the car stop turning and then you calculate the difference between startDirection
and endDirection
, this gives you the degree of rotation
. Now set startDirection
and endDirection
to this new azimuth and wait for next turn.
Upvotes: 1