Skip to content

Commit 1a00b5e

Browse files
authored
Merge pull request #10 from jerabaul29/main
document the units
2 parents 16a3c67 + 7021209 commit 1a00b5e

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ The access to the sensor value is done as explained below:
3737
AccGyr.ACC_GetAxes(accelerometer);
3838
AccGyr.GYRO_GetAxes(gyroscope);
3939

40+
## Units
41+
42+
All the MEMS drivers in stm32duino repositories have the same units when returning physical (scaled) values:
43+
44+
- mg for accelerometer (thousandth of g, 1g is 9.81 m/s^2)
45+
- mdps for gyroscope (thousandth of degree/s)
46+
- mgauss for magnetometer (thousandth of gauss)
47+
48+
Readings can be obtained either as raw (unscaled) ```uint16_t``` values from the ```XXX_GetAxesRaw``` functions, or as physical (scaled) ```uint32_t``` values from the ```XXX_GetAxes``` functions, where ```XXX``` is either ```ACC``` or ```GYRO```. The factor to use for scaling from a raw to a physical value is obtained from the ```XXX_GetSensitivity``` functions.
49+
50+
For example, to convert the raw acceleration reading to float m/s^2, the following can be done:
51+
52+
```cpp
53+
int16_t acc_raw[3];
54+
float acc_ms2[3];
55+
float acc_sensitivity;
56+
57+
AccGyr.ACC_GetAxesRaw(acc_raw);
58+
AccGyr.ACC_GetSensitivity(&acc_sensitivity);
59+
60+
acc_ms2[0] = ((float)acc_raw[0] * acc_sensitivity) / 1000.0f * 9.81f;
61+
acc_ms2[1] = ((float)acc_raw[1] * acc_sensitivity) / 1000.0f * 9.81f;
62+
acc_ms2[2] = ((float)acc_raw[2] * acc_sensitivity) / 1000.0f * 9.81f;
63+
```
64+
4065
## Documentation
4166
You can find the source files at
4267
https://github.com/stm32duino/ISM330DHCX

src/ISM330DHCXSensor.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ typedef struct {
5050

5151
/**
5252
* Abstract class of an ISM330DHCX.
53+
*
54+
* A few notes about the acceleration and angular rate outputs:
55+
* - these are returned as either int16_t for the raw (unscaled) value (XXX_GetAxesRaw functions)
56+
* or int32_t for the physical (scaled) value (XXX_GetAxes functions)
57+
* - the physical (scaled) readings have the following units:
58+
* - mg for accelerometer (thousandth of 1g, 1g is 9.81 m/s^2)
59+
* - mdps for gyroscope (thousandth of degree/s)
60+
* - conversion from raw to physical value is done by multiplying the output of the XXX_GetAxesRaw functions
61+
* by the output of the XXX_GetSensitivity functions.
62+
*
5363
*/
5464
class ISM330DHCXSensor {
5565
public:

0 commit comments

Comments
 (0)