Calibrated accelerometer
Answer
9/18/17 2:45 PM

I used the code snippet for the calibrated acceleromter from the XDK sensor guide, but it won't print any values to the console. What could be the problem?

/* system header files */
#include <stdio.h>
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

/* own header files */
#include "XdkApplicationTemplate.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"
/* sensor header file */
#include "XdkSensorHandle.h"


static void initCalibratedAccelerationSensor(void) {
    /* Initialization of the calibrated accelerometer */
    Retcode_T calibratedAccelInitReturnValue = RETCODE_FAILURE;
    calibratedAccelInitReturnValue = CalibratedAccel_init(
            xdkCalibratedAccelerometer_Handle);
}

static void readCalibratedAccelerationSensor(xTimerHandle xTimer) {
    (void) xTimer;
    CalibratedAccel_Status_T calibrationAccuracy = CALIBRATED_ACCEL_UNRELIABLE;
    Retcode_T calibrationStatus = RETCODE_FAILURE;
    calibrationStatus = CalibratedAccel_getStatus(&calibrationAccuracy);
    if (CALIBRATED_ACCEL_HIGH == calibrationAccuracy
            && RETCODE_OK == calibrationStatus) {
        /* Reading of the data of the calibrated accelerometer */
        Retcode_T returnDataValue = RETCODE_FAILURE;
        CalibratedAccel_XyzMps2Data_T getAccelMpsData = { INT32_C(0), INT32_C(
                0), INT32_C(0) };
        returnDataValue = CalibratedAccel_readXyzMps2Value(&getAccelMpsData);
        if (RETCODE_OK == returnDataValue) {
            printf(
                    "Calibrated Acceleration data: \n\r %f m/s2\n\r %f m/s2\n\r %f m/s2 \n\r",
                    (float) getAccelMpsData.xAxisData,
                    (float) getAccelMpsData.yAxisData,
                    (float) getAccelMpsData.zAxisData);
        }
    }
}

void appInitSystem(void * CmdProcessorHandle, uint32_t param2) {
    BCDS_UNUSED(param2);
    /* Include this beneath BCDS_UNUSED(param2); in appInitSystem() */
    uint32_t timerBlockTime = UINT32_MAX;
    uint32_t oneSecondDelay = UINT32_C(1000);
    uint32_t timerAutoReloadOn = pdTRUE;
    xTimerHandle CalibratedAccelerationSensorHandle = NULL;
    initCalibratedAccelerationSensor();
    CalibratedAccelerationSensorHandle = xTimerCreate(
            (const char *) "readCalibratedAccelerationSensor", oneSecondDelay,
            timerAutoReloadOn, NULL, readCalibratedAccelerationSensor);
    xTimerStart(CalibratedAccelerationSensorHandle, timerBlockTime);
}

0 (0 Votes)
RE: Calibrated accelerometer
Answer
9/18/17 2:57 PM as a reply to Stefan Maier.
Hello Stefan, welcome to the community.

The problem can be a lot of things, so let´s start by the basics:

- Does XDK was correctly indetified by Workbench console?
- If so, place a printf() in a point of code will always working just to see if console log is runnning;

Now let´s walkthrough for some points:

- Test the result of CalibratedAccel_init () function, does it initialized the acc correctly?
- Test the result of CalibratedAccel_readXyzMps2Value (), it returns with success or with error code? which error?

Looking to read your responses.

Best

Felipe
0 (0 Votes)
RE: Calibrated accelerometer
Answer
9/18/17 4:05 PM as a reply to Felipe Neves.

Hello Stefan,

The advantage of the calibrated sensors is that they calibrate themselves when the application is flashed to the XDK.

As you can see in your code, the sensor values are only printed if the following if-condition is valid:

if (CALIBRATED_ACCEL_HIGH == calibrationAccuracy
           && RETCODE_OK == calibrationStatus) {
       /* Reading of the data of the calibrated accelerometer */

}

 

I guess the state of calibrationAccuracy didn't reach the required accuracy in the if-condition. I recommend to insert an else condition, to check which calibration state is reached during the timer loops. Otherwise, you can use a lower calibration state too.

Please let me know if this was helpful and do not hesitate to ask if you have further questions.

Kind regards,
Franjo

0 (0 Votes)
RE: Calibrated accelerometer
Answer
9/19/17 1:15 PM as a reply to Franjo Stjepandic.

Thank you, Felipe and Franjo.

Printing to the console works. The accelerator sensor gets initialized and CalibratedAccel_readXyzMps2Value(&getAccelMpsData) returns 0 (RETCODE_OK).

You're right, Franjo. I added the else-block and no matter what value I set for

CalibratedAccel_Status_T calibrationAccuracy = ...;

CALIBRATED_ACCEL_UNRELIABLE or CALIBRATED_ACCEL_LOW or CALIBRATED_ACCEL_MEDIUM or CALIBRATED_ACCEL_HIGH

calibrationAccuracy is always 0 (CALIBRATED_ACCEL_UNRELIABLE)

But how to make it work with a higher calibrationAccuracy?

0 (0 Votes)
RE: Calibrated accelerometer
Answer
9/19/17 4:46 PM as a reply to Stefan Maier.

Hello Stefan,

I've tried out different ways to calibrated the accelerometer, and the one that works most consistently, is as follows:

1. Let the bottom of the XDK face the earth
2. Rotate the XDK sideways (around the x-axis, alternatively around the y-axis, but not around the z-axis) for 90° around that axis
3. Hold it still for ~1 second
4. Repeat 2. and 3. until the status reaches CALIBRATED_ACCEL_HIGH.

As a general rule of thumb, two axes should alternate in experiencing the gravitational acceleration (once in a positive direction, once in a negative direction per 360°). For example, if the XDK's bottom is facing earth and you rotate it around the z-axis, only the bottom will ever experience gravitational acceleration.

On a sidenote, the axes of the XDK can be seen on the XDK's top-side, in one corner of the glass pane.

Tell me if this is helpful, otherwise I will illustrate this process for clarification.

Kind regards,
Franjo

+1 (1 Vote)
RE: Calibrated accelerometer
Answer
9/25/17 9:36 AM as a reply to Franjo Stjepandic.
Thank you. Now it works.
0 (0 Votes)
RE: Calibrated accelerometer
Answer
9/25/17 2:27 PM as a reply to Stefan Maier.

Hello Stephan,

I am glad to hear that it is working now.

Kind regards,
Franjo

0 (0 Votes)
RE: Calibrated accelerometer
Answer
1/10/19 8:53 PM as a reply to Franjo Stjepandic.

Franjo,

It seems in Workbench 3.5 the need to rotate the XDK for calibration has been removed.  It was my understanding that this was necessary in order for the XDK to be able to eliminate the Zero-G Offset Error inherent to the BMA280, and hence calibrate the XDK data for a reading closer to the real value.

I ran the calibrated and the normal fucntions side by side I get quite different reponses.  Then when i run through the calibration routine you describe above the calibrated data get better.  It seems to me that you still need to run this routine, so why depricate the function to indicate that this is calibrated?

Chris

0 (0 Votes)
RE: Calibrated accelerometer
Answer
1/11/19 3:22 PM as a reply to BCDS Tester.
Hello Chris,

The implementation of the BCDS_CalibratedAccel.h interface is using the accelerometer of the BMI160 not the BM280. The differences you are observing are most likely caused by the fact, that the resolution between the BMI160 and the BMA280 differs between 3 bits. On that behalf, observing huge differences would make sense when comparing two sensors with different resolutions.

In regards to the removed calibration function in XDK-Workbench 3.5.0, this might be, because the calibration is now made within the implementation of the API. Then an active recalibration within the XDK application would be neglectable.

Nevertheless, since you conducted tests with the implementation of the BMA280 and the calibrated accelerometer based on the BMI160, it might be worth comparing these with the implementation of the BMI160 in the interface BCDS_Accelerometer.h ad the calibrated accelerometer based on the BMI160 in BCDS_CalibratedAccel.h .

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)