CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Compass/AP_Compass_BMM350.h
Views: 1798
1
/*
2
* This file is free software: you can redistribute it and/or modify it
3
* under the terms of the GNU General Public License as published by the
4
* Free Software Foundation, either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* This file is distributed in the hope that it will be useful, but
8
* WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
* See the GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License along
13
* with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
16
#pragma once
17
18
#include "AP_Compass_config.h"
19
20
#if AP_COMPASS_BMM350_ENABLED
21
22
#include <AP_Common/AP_Common.h>
23
#include <AP_HAL/AP_HAL.h>
24
#include <AP_HAL/I2CDevice.h>
25
#include <AP_Math/AP_Math.h>
26
27
#include "AP_Compass.h"
28
#include "AP_Compass_Backend.h"
29
30
#define BMM350_I2C_ADDR_MIN 0x14
31
#define BMM350_I2C_ADDR_MAX 0x17
32
33
34
class AP_Compass_BMM350 : public AP_Compass_Backend
35
{
36
public:
37
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
38
bool force_external,
39
enum Rotation rotation);
40
41
void read() override;
42
43
static constexpr const char *name = "BMM350";
44
45
private:
46
AP_Compass_BMM350(AP_HAL::OwnPtr<AP_HAL::Device> dev,
47
bool force_external,
48
enum Rotation rotation);
49
50
AP_HAL::OwnPtr<AP_HAL::Device> _dev;
51
52
/**
53
* @brief BMM350 offset/sensitivity coefficient structure
54
*/
55
struct vector4f
56
{
57
float x; // x axis
58
float y; // y axis
59
float z; // z axis
60
float temp; // Temperature
61
};
62
63
/**
64
* @brief BMM350 magnetometer cross axis compensation structure
65
*/
66
struct cross_axis
67
{
68
float cross_x_y;
69
float cross_y_x;
70
float cross_z_x;
71
float cross_z_y;
72
};
73
74
/**
75
* @brief BMM350 magnetometer compensate structure
76
*/
77
struct mag_compensate
78
{
79
struct vector4f offset_coef; // Offset coefficient
80
struct vector4f sensit_coef; // Sensitivity coefficient
81
Vector3f tco; // Temperature coefficient of the offset
82
Vector3f tcs; // Temperature coefficient of the sensitivity
83
float t0_reading; // Initialize T0_reading parameter
84
struct cross_axis cross_axis; // Cross axis compensation
85
};
86
87
enum power_mode
88
{
89
POWER_MODE_SUSPEND = 0,
90
POWER_MODE_NORMAL = 1,
91
POWER_MODE_FORCED = 3,
92
POWER_MODE_FORCED_FAST = 4
93
};
94
95
/**
96
* Device periodic callback to read data from the sensor.
97
*/
98
bool init();
99
void timer();
100
bool read_otp_data();
101
bool wait_pmu_cmd_ready(const uint8_t cmd, const uint32_t timeout);
102
bool mag_reset_and_wait();
103
bool set_power_mode(const enum power_mode mode);
104
bool read_bytes(const uint8_t reg, uint8_t *out, const uint16_t read_len);
105
106
uint8_t _compass_instance;
107
bool _force_external;
108
enum Rotation _rotation;
109
struct mag_compensate _mag_comp; // Structure for mag compensate
110
};
111
112
#endif // AP_COMPASS_BMM350_ENABLED
113
114