INF2004-Project v0.1
 
Loading...
Searching...
No Matches
magnetometer.h File Reference

Header file for the magnetometer driver. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAGNETO_ACCEL_ADDR   0x19
 Default I2C address for the LSM303DLHC accelerometer.
 
#define MAGNETO_BEARING_OFFSET   1.0f
 Offset for bearing.
 
#define MAGNETO_CRA_REG_M   0x00
 Register for the magnetometer control.
 
#define MAGNETO_CTRL_REG1_A   0x20
 Register for the accelerometer control.
 
#define MAGNETO_GRAVITY_CONSTANT_F   9.80665 / 16384.0
 1 g = 16384 LSB
 
#define MAGNETO_I2C_BAUDRATE   1000000
 1 MHz baudrate for I2C communication.
 
#define MAGNETO_I2C_SCL_PIN   1
 SCL pin for I2C communication.
 
#define MAGNETO_I2C_SDA_PIN   0
 SDA pin for I2C communication.
 
#define MAGNETO_METER_ADDR   0x1E
 Default I2C address for the LSM303DLHC magnetometer.
 
#define MAGNETO_MR_REG_M   0x02
 Register for the magnetometer mode selection.
 
#define MAGNETO_OUT_X_H_A   0x29
 Register for the x-axis acceleration (high).
 
#define MAGNETO_OUT_X_H_M   0x03
 Register for the x-axis magnetometer (high).
 
#define MAGNETO_OUT_X_L_A   0x28
 Register for the x-axis acceleration (low).
 
#define MAGNETO_OUT_X_L_M   0x04
 Register for the x-axis magnetometer (low).
 
#define MAGNETO_OUT_Y_H_A   0x2B
 Register for the y-axis acceleration (high).
 
#define MAGNETO_OUT_Y_H_M   0x07
 Register for the y-axis magnetometer (high).
 
#define MAGNETO_OUT_Y_L_A   0x2A
 Register for the y-axis acceleration (low).
 
#define MAGNETO_OUT_Y_L_M   0x08
 Register for the y-axis magnetometer (low).
 
#define MAGNETO_OUT_Z_H_A   0x2D
 Register for the z-axis acceleration (high).
 
#define MAGNETO_OUT_Z_H_M   0x05
 Register for the z-axis magnetometer (high).
 
#define MAGNETO_OUT_Z_L_A   0x2C
 Register for the z-axis acceleration (low).
 
#define MAGNETO_OUT_Z_L_M   0x06
 Register for the z-axis magnetometer (low).
 

Functions

float magneto_get_curr_bearing (void)
 Gets the current bearing of the magnetometer sensor. More...
 
float magneto_get_true_bearing (void)
 Gets the true bearing of the magnetometer sensor. More...
 
void magneto_init (void)
 Initializes the magnetometer by initializing the USB, I2C, and setting the GPIO pins.
 
bool magneto_is_bearing_invalid (void)
 Checks if the current bearing is invalid if it is out of bounds. More...
 
void magneto_read_data (void)
 Reads magnetometer data from the magnetometer sensor and outputs the values into the global variables. More...
 

Detailed Description

Header file for the magnetometer driver.

Author
Jurgen Tan
Version
0.1
Date
2023-10-30

Function Documentation

◆ magneto_get_curr_bearing()

float magneto_get_curr_bearing ( void  )

Gets the current bearing of the magnetometer sensor.

Returns
float Current bearing in radians.

References gp_current_bearing.

Here is the caller graph for this function:

◆ magneto_get_true_bearing()

float magneto_get_true_bearing ( void  )

Gets the true bearing of the magnetometer sensor.

Returns
float True bearing in radians.

References gp_true_heading.

◆ magneto_is_bearing_invalid()

bool magneto_is_bearing_invalid ( void  )

Checks if the current bearing is invalid if it is out of bounds.

Returns
true Bearing is invalid.
false Bearing is valid.

References gp_current_bearing, gp_max_bearing, and gp_min_bearing.

◆ magneto_read_data()

void magneto_read_data ( void  )

Reads magnetometer data from the magnetometer sensor and outputs the values into the global variables.

References gp_current_bearing, gp_max_bearing, gp_min_bearing, gp_true_heading, MAGNETO_BEARING_OFFSET, and MAGNETO_METER_ADDR.