Orientation Android as a steering - roll corrupt feed?

Hi guys,

I am working on a project that includes an Android application that is used for control / steering.

  • Speed: . When you tilt your phone forward / backward (step), it simulates gas flow and disturbance.
  • Direction: When tilting the phone left / right (roll), it simulates steering left and right.

I already wrote code that seemed to work fine. But when I looked closer, I found that some of the values โ€‹โ€‹act strangely.

When I tilt the phone forward / back to handle speed, it works great, I get the expected values โ€‹โ€‹of speed and direction. But when I tilt the phone left / right to handle the direction, it seems to distort some values. When it tilts left / right, which not only changes the direction value (roll), but also affects the speed value (step).

For more information:

  • Programming for Android 2.2
  • The device is Google Nexus One.
  • Hold device in portrait

The most appropriate code that I use to read the sensor values โ€‹โ€‹is as follows:

public void onSensorChanged(SensorEvent sensorEvent)
{        
    synchronized (this)
    {
        if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION)
        {
            float azimuth = sensorEvent.values[0]; // azimuth rotation around the z-axis
            float pitch = sensorEvent.values[1];   // pitch rotation around the x-axis
            float roll = sensorEvent.values[2];    // roll rotation around the y-axis

            System.out.println("pitch: " + pitch);
            System.out.println("roll: " + roll);
            System.out.println("--------------------");

            // Convert the sensor values to the actual speed and direction values
            float speed = (pitch * 2.222f) + 200;
            float direction = roll * -2.222f;    

, , . / , , . ? , "roll'-ing"? , / / .

.

+5
1
+2

All Articles