Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4053990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:31:02+00:00 2026-05-20T14:31:02+00:00

I am working on a project which includes an Android application which is used

  • 0

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

  • Speed: When you tilt the phone forward/backwards (pitch) it simulates giving gas and breaking.
  • Direction: When you tilt the phone left/right (roll) it simulates steering to the left and right.

I have already written some code which seemed to work fine. But when I took a closer look, I found that some values are acting weird.

When I tilt the phone forward/backward to handle the speed it works perfect I get the expected speed and direction values. But when I tilt the phone to the left/right to handle the direction it seems to corrupt some values. When it is tilting to the left/right that doesn’t only change the direction value (roll) but it also affects the speed value (pitch).

For extra information:

  • Programming for Android 2.2
  • Device is an Google Nexus One
  • Holding the device in portrait

The most relevant code 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;    

So when I run the code, and I look at the printed values. When tilting the device left/right, it seems to affect the pitch value as well. How come? And how can I get the pure pitch value, when ‘roll’-ing? So that tilting the phone to the left/right doesn’t affect/corrupt the pitch value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:31:03+00:00Added an answer on May 20, 2026 at 2:31 pm

    You could read up on Gimbal lock. That’s bitten me before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project which includes some slightly more complex dynamic layout of
I'm working on a project which includes generating pie and bar graph charts on
I started a small project which includes working with MIDI files. I've been wondering,
I am currently working on a PHP project which includes extensive database usage. The
I'm working on an ASP.NET MVC 2 / .NET 3.5 project which includes SSRS
I am working on a project, which includes a searching task by entering the
I am working on a project built in WPF, which includes an embedded WebBrowser.
I'm working on a project which includes persistence library (JPA 1.2), EJB 3 and
I'm working on a project which is just about to start, and since I
I'm working in a project which needs to clean up some third party XSD

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.