Home » Android » java – Driving Style Detection using Smartphone Sensors

java – Driving Style Detection using Smartphone Sensors

Posted by: admin May 14, 2020 Leave a comment


I want to measure the acceleration (forward and lateral separately) using an android smartphone device in order to be able to analyse the driving behavior/style.

My approach would be as follows:

1. Aligning coordinate systems

Calibration (no motion / first motion):
While the car is stationary, I would calculate the magnitude of gravity using Sensor.TYPE_GRAVITY and rotate it straight to the z-axis (pointing downwards assuming a flat surface). That way, the pitch and roll angles should be near zero and equal to the angles of the car relativ to the world.

After this, I would start moving straight forward with the car to get a first motion indication using Sensor.TYPE_ACCELEROMETER and rotate this magnitude straight to the x-axis (pointing forward). This way, the yaw angle should be equal to the vehicle’s heading relativ to the world.

Update Orientation (while driving):
To be able to keep the coordinate systems aligned while driving I am going to use Sensor.TYPE_GRAVITY to maintain the roll and pitch of the system via

enter image description here

enter image description here

where A_x,y,z is the acceleration of gravity.

Usually, the yaw angle would be maintained via Sensor.ROTATION_VECTOR or Sensor.MAGNETIC_FIELD. However, the reason behind not using them is because I am going to use the application also in electrical vehicles. The high amounts of volts and ampere produced by the engine would presumably make the accuracy of those sensor values suffer. Hence, the best alternative that I know (although not optimal) is using the GPS course to maintain the yaw angle.

2. Getting measurements

By applying all aforementioned rotations it should be possible to maintain an alignment between the smartphone’s and vehicle’s coordinate systems and, hence, giving me the pure forward and lateral acceleration values on the x-axis and y-axis.


  • Is this approach applicable or did I miss something crucial?
  • Is there an easier/alternative approach to this?
How to&Answers:

In regards to finding acceleration, if you have access to the source code of the GPS couldn’t you find the forward motion by calculating the distance/time from the GPS?

If the goal is to find driving behavior and style I would imagine gathering a large data set and then using a k means cluster algorithm to sort the data followed by an lstmRNN (to make predictions) could be another method. (Though this requires you to have data from a large set I don’t know if this is possible nor do am I aware of what factors you would want to incorporate in your data set).

Sounds like an interesting problem though.