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_Baro/AP_Baro_ICM20789.h
Views: 1798
1
#pragma once
2
3
#include "AP_Baro_Backend.h"
4
5
#if AP_BARO_ICM20789_ENABLED
6
7
#include <AP_HAL/AP_HAL.h>
8
#include <AP_HAL/Semaphores.h>
9
#include <AP_HAL/Device.h>
10
11
#ifndef HAL_BARO_ICM20789_I2C_ADDR
12
// the baro is on a separate I2C address from the IMU, even though in
13
// the same package
14
#define HAL_BARO_ICM20789_I2C_ADDR 0x63
15
#endif
16
17
class AP_Baro_ICM20789 : public AP_Baro_Backend
18
{
19
public:
20
void update() override;
21
22
static AP_Baro_Backend *probe(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev, AP_HAL::OwnPtr<AP_HAL::Device> dev_imu);
23
24
private:
25
AP_Baro_ICM20789(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev, AP_HAL::OwnPtr<AP_HAL::Device> dev_imu);
26
27
bool init();
28
bool send_cmd16(uint16_t cmd);
29
30
bool read_calibration_data(void);
31
32
void convert_data(uint32_t Praw, uint32_t Traw);
33
34
void calculate_conversion_constants(const float p_Pa[3], const float p_LUT[3],
35
float &A, float &B, float &C);
36
float get_pressure(uint32_t p_LSB, uint32_t T_LSB);
37
38
bool imu_spi_init(void);
39
bool imu_i2c_init(void);
40
41
void timer(void);
42
43
// calibration data
44
int16_t sensor_constants[4];
45
46
uint8_t instance;
47
48
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev;
49
AP_HAL::OwnPtr<AP_HAL::Device> dev_imu;
50
51
// time last read command was sent
52
uint32_t last_measure_us;
53
54
// accumulation structure, protected by _sem
55
struct {
56
float tsum;
57
float psum;
58
uint32_t count;
59
} accum;
60
61
// conversion constants. Thanks to invensense for including python
62
// sample code in the datasheet!
63
const float p_Pa_calib[3] = {45000.0, 80000.0, 105000.0};
64
const float LUT_lower = 3.5 * (1U<<20);
65
const float LUT_upper = 11.5 * (1U<<20);
66
const float quadr_factor = 1 / 16777216.0;
67
const float offst_factor = 2048.0;
68
};
69
70
#endif // AP_BARO_ICM20789_ENABLED
71
72