ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MMC56X3.h
Go to the documentation of this file.
1/**
2 * @file MMC56X3.h
3 * @brief A class for interfacing with the Adafruit MMC56x3 magnetometer sensor.
4 *
5 * This file defines the MMC56X3 class, which provides methods for initializing and retrieving
6 * data from the Adafruit MMC56x3 series magnetometer sensors, including magnetic field data
7 * and magnet position estimation.
8 *
9 * @date 22/12/2024
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include <Adafruit_MMC56x3.h> // Include for Adafruit MMC56x3 library.
16#include "../../Utils/Filter/MinFilter.h" // Include for minimum filtering.
17#include "../../Utils/Filter/RunningAverageFilter.h" // Include for running average filtering.
18#include "../../Utils/Math/Vector2D.h" // Include for 2D vector mathematics.
19#include "../../Utils/Math/Vector3D.h" // Include for 3D vector mathematics.
20#include "../../Utils/Time/TimeStep.h" // Include for timing utilities.
21
22/**
23 * @class MMC56X3
24 * @brief A class for managing the Adafruit MMC56x3 magnetometer sensor.
25 *
26 * The MMC56X3 class provides methods for initializing the sensor, retrieving magnetic field data,
27 * detecting magnets, and estimating magnet positions.
28 */
29class MMC56X3 {
30private:
31 static Adafruit_MMC5603 mag; ///< Instance of the Adafruit MMC5603 sensor.
32 static sensors_event_t magEvent; ///< Sensor event data for magnetic field measurements.
33 static RunningAverageFilter<10> xFilter; ///< Filter for the X-axis magnetic field data.
34 static RunningAverageFilter<10> yFilter; ///< Filter for the Y-axis magnetic field data.
35 static RunningAverageFilter<10> zFilter; ///< Filter for the Z-axis magnetic field data.
36 static TimeStep timeStep; ///< Time utility for regular updates.
37 static TimeStep timeStepCal; ///< Time utility for calibration intervals.
38 static Vector3D magneticField; ///< Processed magnetic field vector.
39 static bool didBegin; ///< Flag indicating if the sensor has been initialized.
40 static MinFilter<10> minF; ///< Minimum filter for noise reduction.
41 static float minimum; ///< Minimum threshold for detection.
42
43public:
44 /**
45 * @brief Initializes the MMC56x3 sensor.
46 *
47 * @param address The I2C address of the sensor (default is MMC56X3_DEFAULT_ADDRESS).
48 * @return True if initialization is successful, false otherwise.
49 */
50 static bool Initialize(uint8_t address = MMC56X3_DEFAULT_ADDRESS);
51
52 /**
53 * @brief Updates the magnetic field data from the sensor.
54 */
55 static void Update();
56
57 /**
58 * @brief Retrieves the current magnetic field vector.
59 *
60 * @return A Vector3D representing the magnetic field.
61 */
63
64 /**
65 * @brief Checks if a magnet is detected.
66 *
67 * @return A float value representing the detection confidence.
68 */
69 static float IsDetected();
70
71 /**
72 * @brief Calculates the magnitude of the magnetic field.
73 *
74 * @return The magnitude of the magnetic field as a float.
75 */
76 static float GetMagnitude();
77
78 /**
79 * @brief Estimates the position of a detected magnet.
80 *
81 * @return A Vector3D representing the estimated magnet position.
82 */
84};
A class for managing the Adafruit MMC56x3 magnetometer sensor.
Definition MMC56X3.h:29
static Vector3D EstimateMagnetPosition()
Estimates the position of a detected magnet.
Definition MMC56X3.cpp:56
static float minimum
Minimum threshold for detection.
Definition MMC56X3.h:41
static MinFilter< 10 > minF
Minimum filter for noise reduction.
Definition MMC56X3.h:40
static Vector3D GetMagneticField()
Retrieves the current magnetic field vector.
Definition MMC56X3.cpp:43
static RunningAverageFilter< 10 > xFilter
Filter for the X-axis magnetic field data.
Definition MMC56X3.h:33
static bool Initialize(uint8_t address=MMC56X3_DEFAULT_ADDRESS)
Initializes the MMC56x3 sensor.
Definition MMC56X3.cpp:15
static TimeStep timeStepCal
Time utility for calibration intervals.
Definition MMC56X3.h:37
static TimeStep timeStep
Time utility for regular updates.
Definition MMC56X3.h:36
static sensors_event_t magEvent
Sensor event data for magnetic field measurements.
Definition MMC56X3.h:32
static Adafruit_MMC5603 mag
Instance of the Adafruit MMC5603 sensor.
Definition MMC56X3.h:31
static float GetMagnitude()
Calculates the magnitude of the magnetic field.
Definition MMC56X3.cpp:52
static float IsDetected()
Checks if a magnet is detected.
Definition MMC56X3.cpp:48
static RunningAverageFilter< 10 > yFilter
Filter for the Y-axis magnetic field data.
Definition MMC56X3.h:34
static bool didBegin
Flag indicating if the sensor has been initialized.
Definition MMC56X3.h:39
static void Update()
Updates the magnetic field data from the sensor.
Definition MMC56X3.cpp:25
static RunningAverageFilter< 10 > zFilter
Filter for the Z-axis magnetic field data.
Definition MMC56X3.h:35
static Vector3D magneticField
Processed magnetic field vector.
Definition MMC56X3.h:38
Implements a minimum filter over a sliding window.
Definition MinFilter.h:28
Smooths data values using a weighted running average.
Provides a mechanism to trigger actions at a specified frequency.
Definition TimeStep.h:18
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26