1. Are you ready for the Galaxy S20? Here is everything we know so far!

Angle sensors without external influences

Discussion in 'Android Development' started by R1Snake, Aug 5, 2020.

  1. R1Snake

    R1Snake Lurker
    Thread Starter

    Hi,

    i have currently developed an app that has a good status but now some logic errors cause me big problems.

    Background is that I want to display the current lean angle on my motorcycle with my mobile phone.

    I have the following code for this:

    if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
    CreateGPS(sensorEvent);
    accels = sensorEvent.values;
    }
    if (sensorEvent.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
    mags = sensorEvent.values;

    if (accels != null && mags != null) {
    float R[] = new float[9];
    float I[] = new float[9];

    boolean success = SensorManager.getRotationMatrix(R, I, accels, mags);

    if (success) {
    float orientation[] = new float[3];
    SensorManager.getOrientation(R, orientation);
    azimuth = orientation[0]; // orientation contains: azimuth, pitch and roll
    pitch = orientation[1];
    roll = orientation[2];

    this.SetAngle(Math.toDegrees(-pitch));

    }
    }


    Sounds logical in theory and works too. However, I have the following problems which may be related.

    If I put the mobile phone in the car and drive into a curve then I have also once 40 degrees inclination in my car ) (G forces must be calculated somehow out of the logic)
    There are vibrations on the bike which cause the wrong values to be displayed (I think it is also related to the G-forces)

    What is the best way to edit the code to display meaningful values? Hang something on the logic tube here.

    this.SetAngle is a method that shows me the angle graphically.

    Thanks for your help.
     


Loading...

Share This Page

Loading...