#include <LSM303Magnetometer.h>
LSM303Magnetometer::LSM303Magnetometer |
( |
unsigned char |
_deviceAddress = MAG_ADDRESS , |
|
|
int |
_busId = 1 |
|
) |
| |
LSM303Magnetometer Constructor, initialises the device - writes default settings to the sensor
- See also
- start() to start reading the device and updating heading values.
- Parameters
-
void initDevice()
Definition: i2cDevice.cpp:33
void setDeviceAddress(unsigned char _deviceAddress)
Definition: LSM303DLHC.h:495
void loadRecommendedFlightSettings()
Definition: LSM303DLHC.cpp:22
void setBusId(int _busId)
Definition: LSM303DLHC.h:502
void startSensorThread()
Definition: LSM303DLHC.cpp:192
double LSM303Magnetometer::calcHeading |
( |
| ) |
|
Calculates heading using the following equation :
x2 = ( x ) * cos( -1 * atan2( X, sqrt( Y * Y + Z * Z )) ) + ( z ) * sin( -1 * atan2( X, sqrt( Y * Y + Z * Z )) ); y2 = ( x ) * sin( atan2( Y, sqrt( X * X + Z * Z )) ) * sin( -1 * atan2( X, sqrt( Y * Y + Z * Z )) ) + ( y ) * cos( atan2( Y, sqrt( X * X + Z * Z )) ) - ( z ) * sin( atan2( Y, sqrt( X * X + Z * Z )) ) * cos( -1 * atan2( X, sqrt( Y * Y + Z * Z )) );
return ( atan2( x2, y2 ) * 180 ) / 3.14159265358979323846;
- Returns
- double Current heading calculation
33 double x2 = 0, y2 = 0;
35 double t_roll = x * x + z * z;
36 float rollRadians = ( float ) atan2((
double ) y, sqrt( t_roll ));
38 double t_pitch = y * y + z * z;
39 float pitchRadians = ( float ) atan2((
double ) x, sqrt( t_pitch ));
41 float cosRoll = ( float ) cos( rollRadians );
42 float sinRoll = ( float ) sin( rollRadians );
44 float cosPitch = ( float ) cos( -1 * pitchRadians );
45 float sinPitch = ( float ) sin( -1 * pitchRadians );
47 x2 = ( x ) * cosPitch + ( z ) * sinPitch;
48 y2 = ( x ) * sinRoll * sinPitch + ( y ) * cosRoll - ( z ) * sinRoll * cosPitch;
50 return ( atan2( x2, y2 ) * 180 ) / M_PI;
int LSM303Magnetometer::start |
( |
| ) |
|
start() - Allows the independent control to start the thread that updates the Magnetometer readings.
- Parameters
-
- Exceptions
-
- Returns
- int deviceStatus : 1 = on, 0 = off or 2 = error
66 threadRet = pthread_create( &threadHandle, NULL, LSM303Magnetometer::runMainSensorUpdateThread,
this );
69 if ( threadRet != 0 ) {
72 if ( threadRet == EAGAIN ) {
74 threadRet = pthread_create( &threadHandle, NULL, LSM303Magnetometer::runMainSensorUpdateThread,
this );
75 if ( threadRet != 0 ) {
78 + to_string( threadRet ) );
81 else if ( threadRet == EPERM ) {
86 else if ( threadRet == EINVAL ) {
104 }
const string THREAD_FATAL
Definition: i2cSetupException.h:20
Definition: i2cSetupException.h:24
void setStatus(deviceStatus _status)
Definition: i2cDevice.cpp:80
Error
Status Error (thread is disabled)
Definition: LVMaxSonarEZ.h:92
const string THREAD_PERMISSIONS
Definition: i2cSetupException.h:21
int getStatus()
Definition: i2cDevice.cpp:85
const string THREAD_UNKNOWN
Definition: i2cSetupException.h:19
const string THREAD_INVALID_ARG
Definition: i2cSetupException.h:22
On
Status On (thread is active)
Definition: LVMaxSonarEZ.h:90
double quadro::i2c::LSM303Magnetometer::heading |
Store current calculated heading value;.
The documentation for this class was generated from the following files: