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_KellerLD.h
Views: 1798
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15
16
* Driver for 4 LD ... 9 LD line of pressure transducers from Keller:
17
* http://www.keller-druck.com/home_e/paprod_e/4ld_e.asp
18
*
19
* These sensors operate on I2C and come in a variety of form factors.
20
* The measurement range is between 0-200 bar depbending on the model.
21
* They are definitely not the worlds smallest pressure transmitter.
22
*
23
* Default address is 0x40.
24
*/
25
26
#pragma once
27
28
#include "AP_Baro_Backend.h"
29
30
#if AP_BARO_KELLERLD_ENABLED
31
32
#include <AP_HAL/AP_HAL.h>
33
#include <AP_HAL/Semaphores.h>
34
#include <AP_HAL/Device.h>
35
36
#ifndef HAL_BARO_KELLERLD_I2C_ADDR
37
#define HAL_BARO_KELLERLD_I2C_ADDR 0x40
38
#endif
39
40
class AP_Baro_KellerLD : public AP_Baro_Backend
41
{
42
public:
43
void update() override;
44
45
static AP_Baro_Backend *probe(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev);
46
47
private:
48
AP_Baro_KellerLD(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev);
49
50
bool _init();
51
52
void _timer();
53
54
bool _read();
55
56
void _update_and_wrap_accumulator(uint16_t pressure, uint16_t temperature, uint8_t max_count);
57
58
AP_HAL::OwnPtr<AP_HAL::Device> _dev;
59
60
/* Shared values between thread sampling the HW and main thread */
61
/* These are raw outputs, not calculated values */
62
struct {
63
uint32_t sum_pressure;
64
uint32_t sum_temperature;
65
uint8_t num_samples;
66
} _accum;
67
68
uint8_t _instance;
69
70
enum class SensorMode {
71
PR_MODE = 0, // Vented gauge
72
PA_MODE = 1, // Sealed gauge
73
PAA_MODE = 2, // Absolute
74
UNDEFINED = 3,
75
};
76
77
// to store sensor mode
78
SensorMode _p_mode;
79
// Model-specific offset/calibration values stored in device ROM
80
// pressure offset used in pressure calculation
81
float _p_mode_offset;
82
// measurement range parameters used in pressure calculation
83
float _p_min;
84
float _p_max;
85
86
// helpers for reading out calibration information:
87
bool transfer_with_delays(uint8_t *send, uint8_t sendlen, uint8_t *recv, uint8_t recvlen);
88
bool read_measurement_limit(float *limit, uint8_t msb_addr, uint8_t lsb_addr);
89
bool read_cal();
90
bool read_mode_type();
91
};
92
93
94
#endif // AP_BARO_KELLERLD_ENABLED
95
96