Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Trusted Contributor
taylor-tomt
Posts: 231
Registered: ‎11-19-2010
My Device: Z10, Playbook

Gyro Sensor incorrectly zeroing (PB 2.1) Need BB insider to check this I think.

[ Edited ]

 

 

I created a new  project for PB open GL ES 1.1

 

All it does is initialize the screen, and request gyro sensor events and display them on the screen  using the BBUTIL_render_text and also prints them to stderr.

 

If the program is started with the PB under a constant rotation, the gyro will initially give the expected outputs, but at some random time the gyro appears to calibrate and the outputs become zero (+/- small amount). If you then stop the rotation, the gyro outputs of course read the negative of whatever the original rotation was.

 

Is the OS 'background' sensor cal activating because it thinks the gyro is at rest even though it is rotating with a constant rate? It sees the constant rate and incorrectly assumes that the gyro must be at rest but there is an offset, so it zeros it?

My guess is that the OS detects several sequential gyro readings all within some small range of each other, but not = 0, so it zeros the sensor.

 

Stop the app with the sensor in this state.

Now,  with the PB at rest, start the app again and the gyro outputs are still offset, but after a few seconds they recalibrate and the readings once again become correct.

If the PB is now set back to a constant rotation rate, the gyro will once again zero itself eventually.

This seems to support my speculation about the OS background cal task.

 

Can this behavior be stopped? Can the background cal task be stopped or suspended?

 

 

 

Please use plain text.
Trusted Contributor
taylor-tomt
Posts: 231
Registered: ‎11-19-2010
My Device: Z10, Playbook

Re: Sensor 'stuck' after sleep/wake (PB 2.1)

[ Edited ]

See updated original post

Please use plain text.
BlackBerry Development Advisor (Retired)
aparco
Posts: 15
Registered: ‎10-11-2012
My Device: BlackBerry Z10
My Carrier: Rogers

Re: Gyro Sensor incorrectly zeroing (PB 2.1) Need BB insider to check this I think.

[ Edited ]

Hi taylor-tomt,

 

This behaviour can not be stopped or suspended.  This is part of the gyro calibration.  However there are some changes currently being introuduced that might eliviate some of what you are seeing.

 

In the mean time, if you absolutely require raw gyroscope data, you can use the direct sensor API and extract the uncalibrated data.  In sensor_event_t, use the raw.x/y/z values:

 

typedef struct  {
    size_t size ;
    sensor_type_e type ;
    uint32_t flags ;
    sensor_accuracy_e accuracy ;
    uint64_t timestamp ;
    union {
        struct {
            struct {
                float x, y, z;
            } dsp, raw;
            union {
                struct {
                    float temperature;
                } gyro;
            };
        } motion;
    };
}sensor_event_t;

 

Please use plain text.
Trusted Contributor
taylor-tomt
Posts: 231
Registered: ‎11-19-2010
My Device: Z10, Playbook

Re: Gyro Sensor incorrectly zeroing (PB 2.1) Need BB insider to check this I think.

Thanks. Much Appreciated. I will try this shortly and let you know the results.

 

Please confirm:

 

So, sensor_event_get_xyz(), is returning processed data from the gyro?

 

If I use sensor_event_t, it will be populated when I receive the gyro sensor event, correct?

 

Will the raw data be in rad/s or deg/s?

I ask this because the data sheet for the Invensense gyros show everything in deg/s, but in BBUTIL, if you query the sensor info, max and min are returned as +/-1000, which is in degrees/second , and matches the Invensense data, but sensor_event_get_xyz returns rad/s.

It won't be hard for me to determine once I alter the code, but perhaps you could add it as a minor issue. It would be beneficial to have all readings from the gyro (or any sensor) returned in the same units, no matter where they come from.

 

Last question: When I port to OS 10, the same structure will be available?

 

 

Please use plain text.
Trusted Contributor
taylor-tomt
Posts: 231
Registered: ‎11-19-2010
My Device: Z10, Playbook

Re: Gyro Sensor incorrectly zeroing (PB 2.1) Need BB insider to check this I think.

Sorry, I just noticed that sensor_event_t is lilsted in the OS 10 API reference, so the real question is:

Does this structure exist in the currrent PB OS 2.1?

 

Thanks

Please use plain text.
BlackBerry Development Advisor (Retired)
aparco
Posts: 15
Registered: ‎10-11-2012
My Device: BlackBerry Z10
My Carrier: Rogers

Re: Gyro Sensor incorrectly zeroing (PB 2.1) Need BB insider to check this I think.

Questions answered inline.
Thanks,
Adam.

taylor-tomt wrote:

Thanks. Much Appreciated. I will try this shortly and let you know the results.

 

Please confirm:

 

So, sensor_event_get_xyz(), is returning processed data from the gyro?

Yes

 

If I use sensor_event_t, it will be populated when I receive the gyro sensor event, correct?

You need to follow the documentation and examples of using libsensor.  Calling sensor_get_event() will return a populated object.

 

Will the raw data be in rad/s or deg/s?

rad/s

 

I ask this because the data sheet for the Invensense gyros show everything in deg/s, but in BBUTIL, if you query the sensor info, max and min are returned as +/-1000, which is in degrees/second , and matches the Invensense data, but sensor_event_get_xyz returns rad/s.

It won't be hard for me to determine once I alter the code, but perhaps you could add it as a minor issue. It would be beneficial to have all readings from the gyro (or any sensor) returned in the same units, no matter where they come from.

 

Last question: When I port to OS 10, the same structure will be available?

Yes

 


 

Please use plain text.
Trusted Contributor
taylor-tomt
Posts: 231
Registered: ‎11-19-2010
My Device: Z10, Playbook

Re: Gyro Sensor incorrectly zeroing (PB 2.1) Need BB insider to check this I think.

[ Edited ]

libsensor.h does not exist in the PB 2.1 NDK

 

as such, sensor_get_event, and sensor_event_t also do not exist .

 

my PB is running 2.1.0.1088, so I have to use the 2.1 NDK .

 

If I could get a beta version of OS 10 for my PB, I would happily develop under OS10 and save myself the hassle of doing everthing twice.

 

If sensor_event_t, and all the related, required functions, are actually accessible in OS2.1, can you detail where to find it?

Please use plain text.
BlackBerry Development Advisor (Retired)
aparco
Posts: 15
Registered: ‎10-11-2012
My Device: BlackBerry Z10
My Carrier: Rogers

Re: Gyro Sensor incorrectly zeroing (PB 2.1) Need BB insider to check this I think.

taylor-tomt,

 

You are right, looks like this sensor library is not in PB2.1, you will have to wait for the next update.

 

It isn't a terrible thing to use the calibrated gyro data, it is the prefered method.  In future releases the calibration will even be better.  Your application would most likely benefit from more stable gyroscope readings.

Please use plain text.
Trusted Contributor
taylor-tomt
Posts: 231
Registered: ‎11-19-2010
My Device: Z10, Playbook

Re: Gyro Sensor incorrectly zeroing (PB 2.1) Need BB insider to check this I think.

I agree. I would prefer to use the calibrated outputs. Unfortunately, the current algorithm for zeroing the gyro is misinterpreting steady state rotation as no rotation and it zeros the output.

 

I have my test program running on my PB. if I start it with the PB stationary, the gyro readings are 0 (with a bit of noise, but lets ignore that for now).

 

I start it rotating at a constant rate and the gyro initially reads correctly. Depending on how precisely I control the rate (i.e. very little variation), the gyro output will become 0 within 30-90s.

 

I can then stop the rotation and the gyro output will be -1*(whatever the constant rate was) for 30-90s and again the gyro will calibrate and return to 0.

 

I understand that the system is trying to keep the gyro calibrated by determining when the device is not rotating and picking that time to zero the outputs, but the algorithm is insufficient at this time.

At a minimum I think it should check the azimuth sensor and if it is showing constant heading change, don't zero the gyro. But even that will get fooled if the azimuth sensor is being messed up by a nearby magnet (BTW, who puts a magnet on a case for a device that has a magnetometer built in? i.e. the bluetooth keyboard case for the PB???).

 

Please pass this along to the development team for their consideration.

If a foolproof algorithm for determining when to auto-zero the sensors can't be realized, a control to allow an app to temporarliy disable auto-cal would be useful.

 

Thanks for your help.

 

 

Please use plain text.