Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMI270 accel data anomily

    BMI270 accel data anomily

    bod609
    Member

    Hello all, I am experiencing a couple of anomalies in the data read from BMI270 using the reference API.

    1) The accelerometer data is out by a factor of 4.

    2) The timestamp data always reads 0.

    Please take a look at the following code and output and see if you can spot what I am missing:

    CODE:

    static int8_t BMI270_sensor_config(struct bmi2_dev *bmi2_dev)
    {

    int8_t rslt = BMI2_OK;
    struct bmi2_sens_config config[2];

    config[0].type = BMI2_ACCEL;
    config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
    config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
    config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
    config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
    config[1].type = BMI2_GYRO;
    config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
    config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
    config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
    config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
    config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;

    if(rslt = BMI2_OK) bmi2_set_sensor_config(config, 2, bmi2_dev);

    return rslt;
    }

    void
    bmi270_raw_feed(void)
    {

    struct bmi2_sensor_data sensor_data[2];

    sensor_data[0].type = BMI2_ACCEL;
    sensor_data[1].type = BMI2_GYRO;

    bmi2_get_sensor_data(sensor_data, 2, &bmi270_dev);

    /*Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
    test_x = lsb_to_mps2(sensor_data[0].sens_data.acc.x, 2, bmi270_dev.resolution); // bmi270_dev.resolution=16
    test_y = lsb_to_mps2(sensor_data[0].sens_data.acc.y, 2, bmi270_dev.resolution);
    test_z = lsb_to_mps2(sensor_data[0].sens_data.acc.z, 2, bmi270_dev.resolution);

    test_g = sqrt(test_x*test_x + test_y*test_y + test_z*test_z);
    }

    #define GRAVITY_EARTH (9.80665f)

    static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
    {
    float half_scale = ((float)(1 << bit_width) / 2.0f);
    return (GRAVITY_EARTH * val * g_range) / half_scale;
    }


    OUTPUT (sensor stationary):

    sensor_data[0].sens_data.acc.x =
    355
    sensor_data[0].sens_data.acc.y = 358
    sensor_data[0].sens_data.acc.z = 4104
    sensor_data[0].sens_data.acc.virt_sens_time = 0

    sensor_data[1].sens_data.gyr.x = 3
    sensor_data[1].sens_data.gyr.y = -2
    sensor_data[1].sens_data.gyr.z = 3
    sensor_data[0].sens_data.gyr.virt_sens_time = 0

    test_x = 0.208894104
    test_y = 0.211288303
    test_z = 2.45405674
    test_g = 2.47197771

    1) I would expect: test_g = GRAVITY_EARTH , however it seems: test_g = GRAVITY_EARTH/4 .The gyro data seems to be correct.

    2) I can get the correct timestamp data by reading the SENSORTIME registers directly.

    What is the most efficiant way to read gyro, accel and timestamp data together?

    Any help would be much appreciated!

    4 REPLIES 4

    Vincent
    Community Moderator
    Community Moderator

    The virt_sens_time is only used in FIFO data unpack. 

    In read sensor data function you called,  this parameter is not feed with any valid data.   So your print out is 0. 

    I suggest you to read the sensor time register directly.

    To convert the lsb to g,  i suggest you following our API example:

    lsb_per_g = (uint16_t)(power(2, dev->resolution) / (2 * range));

    Then use the lsb value get from read sensor data to devided by lsb_per_g to get g value on each axis.

     

    Many thanks for your reply Vincent, and for clearing up part (2) of the problem. It’s pretty straight forward to read all the accel, gyro and timestamp data directly in one burst, so maybe I’ll just do that.

    I will use the method for converting lsb to g to highlight again part (1) of the problem
    :

    Since
    config[0].cfg.acc.range = BMI2_ACC_RANGE_2G; the sensitivity is 16384 LSB/g
    (This can be worked out using the given equation, and is also found on p13 of the data-sheet).

    Converting accel data gives
    x = 355/16384 = 0.02166748046875 g
    y = 358/16384 = 0.0218505859375 g
    z = 4104/16384 = 0.25048828125 g

    magnitude = sqrt(x*x + y*y + z*z) = 0.25237136695
    g

    This shows clearly that the accelerometer readings are 1/4 of what would be expected.

    Any ideas?

    It seems the issue is with my BMI270_sensor_config .
    I noticed that changing the range made no difference to the data, so after configuring the accelerometer seperately (as in the accel.c example provided with the API), the data now seems correct.

    Hi,

     

    I got the same issue with you, the accelerometer data is out by a factor of 4

    and  changing the range made no difference to the data.

    Do you still remember how you finally fix this issue?

    I am using and the accel.c example and still got this problem.

    My post is here

    https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMI270-accel-data-anomily-out-by-factor-...

    Thanks!

     

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist