SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
MagnetometerUtils Namespace Reference

Functions

float dmsToDecimalDegrees (int degrees, int minutes, float seconds=0.0f)
 Convert degrees-minutes-seconds to decimal degrees.
 
float dmsToRadians (int degrees, int minutes, float seconds=0.0f)
 Convert degrees-minutes-seconds to radians.
 
float calculateHeading (const MagnetometerData &data, float declination=0.0f)
 Calculate heading (yaw) angle from magnetometer data in radians.
 
float calculateHeadingDegrees (const MagnetometerData &data, float declination_deg=0.0f)
 Calculate heading (yaw) angle from magnetometer data in degrees.
 
float calculateMagneticStrength (const MagnetometerData &data)
 Calculate total magnetic field strength.
 
float gaussToMicroTesla (float gauss)
 Converts Gauss to microTesla.
 
float microTeslaToGauss (float ut)
 Converts microTesla to Gauss.
 
float rangeToGauss (MagFullScaleRange range)
 

Function Documentation

◆ calculateHeading()

float MagnetometerUtils::calculateHeading ( const MagnetometerData data,
float  declination = 0.0f 
)
inline

Calculate heading (yaw) angle from magnetometer data in radians.

This function computes the magnetic heading in the horizontal plane using the x and y components of the magnetometer. The result is corrected for magnetic declination (difference between true north and magnetic north).

Note
This calculation assumes the device is level (no tilt compensation). For accurate results when device is tilted, use with accelerometer data.
Parameters
dataMagnetometer data structure containing magnetic field measurements
declinationMagnetic declination correction in radians (positive east)
Returns
Heading angle in radians, range [0, 2π) (0 = magnetic north)

Definition at line 74 of file MagnetometerUtils.hpp.

References M_PI, mag(), and MagnetometerData::magnetic_field.

Referenced by SensorBMM150::readData(), SensorQMC5883L::readData(), SensorQMC6309::readData(), and SensorQSTMagnetic::readData().

◆ calculateHeadingDegrees()

float MagnetometerUtils::calculateHeadingDegrees ( const MagnetometerData data,
float  declination_deg = 0.0f 
)
inline

Calculate heading (yaw) angle from magnetometer data in degrees.

This is a convenience wrapper that returns the heading in degrees (0-360).

Parameters
dataMagnetometer data structure containing magnetic field measurements
declination_degMagnetic declination correction in degrees (positive east)
Returns
Heading angle in degrees, range [0, 360) (0 = magnetic north)

Definition at line 115 of file MagnetometerUtils.hpp.

References M_PI, mag(), and MagnetometerData::magnetic_field.

◆ calculateMagneticStrength()

float MagnetometerUtils::calculateMagneticStrength ( const MagnetometerData data)
inline

Calculate total magnetic field strength.

Computes the magnitude of the magnetic field vector from all three axes. This represents the total strength of the magnetic field at the sensor.

Parameters
dataMagnetometer data structure containing magnetic field measurements
Returns
Magnetic field strength in Gauss

Definition at line 143 of file MagnetometerUtils.hpp.

References mag(), and MagnetometerData::magnetic_field.

Referenced by loop().

◆ dmsToDecimalDegrees()

float MagnetometerUtils::dmsToDecimalDegrees ( int  degrees,
int  minutes,
float  seconds = 0.0f 
)
inline

Convert degrees-minutes-seconds to decimal degrees.

Parameters
degreesWhole degrees (can be negative)
minutesArc minutes (0-59)
secondsArc seconds (0-59.999...)
Returns
Decimal degrees

Definition at line 46 of file MagnetometerUtils.hpp.

Referenced by dmsToRadians(), and setup().

◆ dmsToRadians()

float MagnetometerUtils::dmsToRadians ( int  degrees,
int  minutes,
float  seconds = 0.0f 
)
inline

Convert degrees-minutes-seconds to radians.

Definition at line 55 of file MagnetometerUtils.hpp.

References dmsToDecimalDegrees(), and M_PI.

◆ gaussToMicroTesla()

float MagnetometerUtils::gaussToMicroTesla ( float  gauss)
inline

Converts Gauss to microTesla.

Note
This function is used to convert magnetic field strength from Gauss to microTesla.
Parameters
gaussThe magnetic field strength in Gauss.
Return values
Themagnetic field strength in microTesla.

Definition at line 157 of file MagnetometerUtils.hpp.

Referenced by loop().

◆ microTeslaToGauss()

float MagnetometerUtils::microTeslaToGauss ( float  ut)
inline

Converts microTesla to Gauss.

Note
This function is used to convert magnetic field strength from microTesla to Gauss.
Parameters
utThe magnetic field strength in microTesla.
Return values
Themagnetic field strength in Gauss.

Definition at line 168 of file MagnetometerUtils.hpp.

Referenced by SensorBMM150::readData().

◆ rangeToGauss()

float MagnetometerUtils::rangeToGauss ( MagFullScaleRange  range)
inline

Definition at line 174 of file MagnetometerUtils.hpp.

References FS_12G, FS_16G, FS_25G, FS_30G, FS_32G, FS_4G, and FS_8G.