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

This file contains functions for initializing and reading data from a magnetometer and accelerometer sensors using I2C communication. The module used is the LSM303DLHC. More...

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "pico/time.h"
#include "hardware/gpio.h"
#include "hardware/i2c.h"
#include "magnetometer/magnetometer.h"
Include dependency graph for magnetometer.c:

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 ()
 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...
 

Variables

int16_t g_bias_x = 0
 Bias for x-axis acceleration.
 
int16_t g_bias_y = 0
 Bias for y-axis acceleration.
 
int16_t g_bias_z = 0
 Bias for z-axis acceleration.
 
float * gp_current_bearing = 0
 Pointer to current bearing in radians.
 
float * gp_max_bearing = 0
 Maximum bearing in radians.
 
float * gp_min_bearing = 0
 Minimum bearing in radians.
 
float * gp_true_heading = 0
 Pointer to true heading in radians.
 

Detailed Description

This file contains functions for initializing and reading data from a magnetometer and accelerometer sensors using I2C communication. The module used is the LSM303DLHC.

Author
Jurgen Tan
Version
0.2
Date
2023-10-29

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.