Hi,
We have formula as bellow:
#define GRAVITY_EARTH (9.80665f) /* Earth's gravity in m/s^2 */
#define RAD (57.2957805f)
#define INV_RAD (0.01745329f)
/*!
* @brief This internal API is used to convert lsb to ms2
*
* @param[in] val: value
* @param[in] range: range value
* @param[in] bit_width
*
* @return float value in ms2
*
*/
float lsb_to_ms2(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;
}
float lsb_to_mg(int16_t val, float g_range, uint8_t bit_width)
{
float half_scale = (float)(1 << bit_width) / 2.0f;
return 1000.0f * val * g_range / half_scale;
}
float lsb_to_dps(int16_t val, float g_range, uint8_t bit_width)
{
float half_scale = (float)(1 << bit_width) / 2.0f;
return val * g_range / half_scale;
}
example:
accel_x = lsb_to_ms2(accel_data[i].x, 8, 16);
gyro_x = lsb_to_dps(gyro_data[i].x, 2000, 16);
#define MAG_FRAMES 20
struct bmm150_mag_data mag_data[MAG_FRAMES];
rslt = bmm150_aux_mag_data(aux_data[i].data, &bmm150dev);
mag_data[i].x = bmm150dev.data.x;
mag_data[i].y = bmm150dev.data.y;
mag_data[i].z = bmm150dev.data.z;
... View more