we are trying to read the data from the Magnetometer but it looks like to saturate very quickly when the device get close to some iron. We found that the source code has the following struct to hold the data extracted from the sensor :

typedef struct { 
    uint32_t rawSensors[N_RAW_SENS]; 
    double scaledSensors[N_RAW_SENS]; // g's, rad/s, G, deg C, (body frame) 
    int32_t scaledSensors_q27[N_RAW_SENS]; // g's, rad/s, G, deg C, (body frame) 
    uint64_t tstamp; // timestamp of last sample 
} sensors_data_t;

We noticed that the function

void GetMagData_G(double *data) { 
     for(int i = 0; i < 3; i++){ 
         data[i] = gSensorsData.scaledSensors[i+XMAG]; 

retrieve the scaledSensor, how is it scaled, can it be changed by some parameter ? why does it saturate so quickly ? What's inside rawSensor ? Since the code of the library is not open, can you at least try to shed some light on how it works ?

Thanks Valerio

Hi Valerio,
the magnetometer reads values from -8 to +8 Gauss. The raw value (which will be between -32768 to +32768 counts) from the sensor is scaled to a floating point value where -1 represents -8 Gauss and +1 represents +8 Gauss.
Values outside +-8 Gauss will cause the scaled sensor value to saturate at +-1.

This post is deleted!

Hi @stephen-hinchy ,

thanks for the answer, but the bytes i read from each axis from the struct gSensorsData.rawSensors[i+XMAG]; do not look like short int (2 bytes), because we see 3/4 bytes populated, so it looks like it's not in the -32768 to +32768 (16 bit short int) range 😞


Log in to reply