RootsWiller
RootsWiller

Reputation: 21

How to get azimuth angle at the same time of getting accelerometer measure!ORIENTATION vs ACCELEROMETER

I'm doing this application that works like a pedometer counting steps, but I want it to show orientation for each step.

What i'm doing is registering two event listeners and than for each onsensorchanged event I'm picking up the values of the sensor.TYPE_ORIENTATION to get the azimuth angle, and of the sensor.TYPE_ACCELEROMETER, where I see if a step is given or not.

At this time I'm getting the values correctly but I want to peak only the azimuth angla when the step count is done!How do I do this ?

I'm supposing that it will be done inside the OnSensorChanged method, but I'm not getting an idea on how to just call Orientation sensor, when Accelerometer Sensor is activated and a step is count..

Looking inside the code it will be something like this: after registering the two listeners, ACCELEROMETER and ORIENTATION

OnSensorChanged(SensorEvent event)
{
    if((event.sensor.getType()==Sensor.TYPE_ACCELEROMETER))

    accValues=event.values;

    // NOW get the orientation azimuth value at this time..
    orientationValues=event.values;
}

Hope that someone can clarify me on this..

Upvotes: 2

Views: 1798

Answers (1)

shshnk
shshnk

Reputation: 1691

hey if you want the azimuthal angle you can get it using the ACCELEROMETER and MAGNETOMETER sensors. First get the accelerometer data and the magnetometer data .Next use SensorManager.getRotationMatrix(Rotation_data, Inclination_data, acc_data, mag_data) function. you have to give acc_data and mag_data as input and you get Rotation_data and Inclination_data as output. Just pass them as empty arrays initially. once you have get the Rotation_data use SensorManager.getOrientation(Rotation_data, angles) . angles is an array you get as output.Pass it also as an empty array initially. after the function call you get angles[0] as azimuthal,angles[1] is pitch and angles[3] is roll. All the arrays used are a single dimension array of 3 elements.

Upvotes: 2

Related Questions