upm
1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
|
API for the LSM303D 3-Axis Geomagnetic Sensor. More...
The LSM303D is an ultra-low-power high-performance system-in-package featuring a 3D digital linear acceleration sensor and a 3D digital magnetic sensor. The LSM303D has linear acceleration full scales of 2g/4g/8g/16g and a magnetic field dynamic range of 50 Gauss.
Not all functionality of this chip has been implemented in this driver, however all the pieces are present to add any desired functionality. This driver supports only I2C operation.
This device requires 3.3v operation.
Public Member Functions | |
LSM303D (int bus=LSM303D_DEFAULT_I2C_BUS, int addr=LSM303D_DEFAULT_I2C_ADDR) | |
~LSM303D () | |
void | update () |
void | getMagnetometer (float *x, float *y, float *z) |
std::vector< float > | getMagnetometer () |
void | getAccelerometer (float *x, float *y, float *z) |
std::vector< float > | getAccelerometer () |
float | getTemperature () |
void | init (LSM303D_M_RES_T res) |
void | setAccelerometerFullScale (LSM303D_AFS_T fs) |
void | setMagnetometerFullScale (LSM303D_MFS_T fs) |
void | setAccelerometerODR (LSM303D_AODR_T odr) |
void | setMagnetometerODR (LSM303D_MODR_T odr) |
Protected Member Functions | |
uint8_t | readReg (uint8_t reg) |
int | readRegs (uint8_t reg, uint8_t *buffer, int len) |
void | writeReg (uint8_t reg, uint8_t val) |
Protected Attributes | |
lsm303d_context | m_lsm303d |
LSM303D | ( | int | bus = LSM303D_DEFAULT_I2C_BUS , |
int | addr = LSM303D_DEFAULT_I2C_ADDR |
||
) |
LSM303D constructor
This driver only supports I2C.
Due to the fact that this chip is currently obsolete, we only support minimum functionality.
bus | I2C bus to use |
addr | The I2C address of the device |
std::runtime_error | on failure. |
void update | ( | void | ) |
Update the internal stored values from sensor data. This method must be called before querying the acceleration, magnetometer, or temperature.
std::runtime_error | on failure |
void getMagnetometer | ( | float * | x, |
float * | y, | ||
float * | z | ||
) |
Return magnetometer data in micro-Teslas (uT). update() must have been called prior to calling this method.
x | Pointer to a floating point value that will have the current x component placed into it |
y | Pointer to a floating point value that will have the current y component placed into it |
z | Pointer to a floating point value that will have the current z component placed into it |
std::vector< float > getMagnetometer | ( | ) |
Return magnetometer data in micro-Teslas (uT) in the form of a floating point vector. update() must have been called prior to calling this method.
void getAccelerometer | ( | float * | x, |
float * | y, | ||
float * | z | ||
) |
Return acceleration data in gravities. update() must have been called prior to calling this method.
x | Pointer to a floating point value that will have the current x component placed into it |
y | Pointer to a floating point value that will have the current y component placed into it |
z | Pointer to a floating point value that will have the current z component placed into it |
std::vector< float > getAccelerometer | ( | ) |
Return acceleration data in gravities in the form of a floating point vector. update() must have been called prior to calling this method.
float getTemperature | ( | void | ) |
Return temperature data in degrees Celsius. NOTE: This is not the ambient room temperature. update() must have been called prior to calling this method.
void init | ( | LSM303D_M_RES_T | res | ) |
Initialize the device and start operation. This function is called from the constructor so it will not typically need to be called by a user unless the device is reset. It will initialize the accelerometer and magnetometer (if enabled) to certain default running modes.
res | One of the LSM303D_M_RES_T values. This value sets the resolution of the magnetometer. At init time, this value is set to LSM303D_M_RES_HIGH. |
std::runtime_error | on failure |
void setAccelerometerFullScale | ( | LSM303D_AFS_T | fs | ) |
Set the full scale (sensitivity) value for the accelerometer. This device supports 2G, 4G, 6G, 8G, and 16G full scale modes.
fs | One of the LSM303D_AFS_T values |
std::runtime_error | on failure |
void setMagnetometerFullScale | ( | LSM303D_MFS_T | fs | ) |
Set the full scale (sensitivity) value for the magnetometer. This device supports 2, 4, 8, and 16 Gauss full scale modes.
fs | One of the LSM303D_MFS_T values |
std::runtime_error | on failure |
void setAccelerometerODR | ( | LSM303D_AODR_T | odr | ) |
Set the accelerometer output data rate (ODR)
odr | One of the LSM303D_AODR_T values. The default set at initialization time is LSM303D_AODR_100HZ. |
std::runtime_error | on failure |
void setMagnetometerODR | ( | LSM303D_MODR_T | odr | ) |
Set the magnetometer output data rate (ODR)
odr | One of the LSM303D_MODR_T values. The default set at initialization time is LSM303D_MODR_12_5HZ. |
std::runtime_error | on failure |
|
protected |
Read a register
reg | The register to read |
|
protected |
Read contiguous registers into a buffer
buffer | The buffer to store the results |
len | The number of registers to read |
std::runtime_error | on failure |
|
protected |
Write to a register
reg | The register to write to |
val | The value to write |
std::runtime_error | on failure |