upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
AK8975 Class Reference

API for the AK8975 magnetometer. More...

Detailed Description

This is a 3-axis magnetometer, which can be used alone, or coupled with another device (such as the mcu9150 9-axis motion sensor).

upm::AK8975 *sensor = new upm::AK8975();
sensor->init();
while (shouldRun)
{
sensor->update();
float x, y, z;
sensor->getMagnetometer(&x, &y, &z);
cout << "Magnetometer: ";
cout << "MX = " << x << " MY = " << y << " MZ = " << z << endl;
cout << endl;
usleep(500000);
}

Public Types

enum  AK8975_REG_T {
  REG_WIA = 0x00, REG_INFO = 0x01, REG_ST1 = 0x02, REG_HXL = 0x03,
  REG_HXH = 0x04, REG_HYL = 0x05, REG_HYH = 0x06, REG_HZL = 0x07,
  REG_HZH = 0x08, REG_ST2 = 0x09, REG_CNTL = 0x0a, REG_ASTC = 0x0c,
  REG_ASAX = 0x10, REG_ASAY = 0x11, REG_ASAZ = 0x12
}
 
enum  ST1_BITS_T { ST1_DRDY = 0x01 }
 
enum  ST2_BITS_T { ST2_DERR = 0x04, ST2_HOFL = 0x08 }
 
enum  CNTL_MODES_T { CNTL_PWRDWN = 0x00, CNTL_MEASURE = 0x01, CNTL_SELFTEST = 0x08, CNTL_FUSE_ACCESS = 0x0f }
 
enum  ASTC_BITS_T { ASTC_SELF = 0x40 }
 

Public Member Functions

 AK8975 (int bus=AK8975_I2C_BUS, uint8_t address=AK8975_DEFAULT_I2C_ADDR)
 
 ~AK8975 ()
 
bool init ()
 
bool setMode (CNTL_MODES_T mode)
 
bool isReady ()
 
bool waitforDeviceReady ()
 
bool update (bool selfTest=false)
 
bool selfTest ()
 
void getMagnetometer (float *x, float *y, float *z)
 

Protected Member Functions

float adjustValue (float value, float adj)
 

Protected Attributes

float m_xCoeff
 
float m_yCoeff
 
float m_zCoeff
 
float m_xData
 
float m_yData
 
float m_zData
 

Member Enumeration Documentation

AK8975 registers

enum ST1_BITS_T

ST1 bits

enum ST2_BITS_T

ST2 bits

CNTL register, operating mode values

ASTC (self test control) bits

Constructor & Destructor Documentation

AK8975 ( int  bus = AK8975_I2C_BUS,
uint8_t  address = AK8975_DEFAULT_I2C_ADDR 
)

ak8975 constructor

Parameters
busi2c bus to use
addressthe address for this device
~AK8975 ( )

AK8975 Destructor

Member Function Documentation

bool init ( )

set up initial values and start operation

Parameters
dsrthe data sampling rate: one of the DSR_BITS_T values
Returns
true if successful

Here is the call graph for this function:

Here is the caller graph for this function:

bool setMode ( CNTL_MODES_T  mode)

put the chip into a specific mode

Parameters
modeone of the CNTL_MODES_T values
Returns
true if successful

Here is the caller graph for this function:

bool isReady ( )

check to see if the ST1_DRDY bit is set, indicating the device can accept commands

Returns
true if device is ready, false otherwise

Here is the caller graph for this function:

bool waitforDeviceReady ( )

check to see if device is ready and sleep/retry if not. Returns once device indicates it's ready.

Returns
true if device is ready, false if retries exhausted

Here is the call graph for this function:

Here is the caller graph for this function:

bool update ( bool  selfTest = false)

take a measurement

Parameters
selfTesttrue if we are running a self test, false (default) otherwise.
Returns
true if successful, false otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

bool selfTest ( )

do a self test sequence. When self test is executed, the device activates internal calibrated magnets, and measures them, updating the measurement registers. Once complete, the data can be read as usual (getMagnetometer()) and the returned values compared against the following limits to determine correctness:

-100 < X < +100; -100 < Y < +100; -1000 < Z < -300

Returns
true if successful, false otherwise

Here is the call graph for this function:

void getMagnetometer ( float *  x,
float *  y,
float *  z 
)

return the compensated values for the x, y, and z axes. The unit of measurement is in micro-teslas (uT).

Parameters
xpointer to returned X axis value
ypointer to returned Y axis value
zpointer to returned Z axis value

Here is the call graph for this function:

Here is the caller graph for this function:

float adjustValue ( float  value,
float  adj 
)
protected

compute a compensated magnetometer axis value, based on the raw axis value and a per-device, per-axis adjustment coefficient that was read and stored at init() time.

Parameters
valuethe raw axis value to compensate
adjthe adjustment coefficient
Returns
true if successful

Here is the caller graph for this function:


The documentation for this class was generated from the following files: