Robot Control Library
bmp.h
Go to the documentation of this file.
1 /**
2  * <rc/bmp.h>
3  *
4  * @brief Interface to the BMP280 barometer
5  *
6  *
7  * @author James Strawson
8  * @date 3/14/2018
9  *
10  * @addtogroup Barometer_BMP
11  * @{
12  */
13 
14 #ifndef RC_BMP_H
15 #define RC_BMP_H
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 
22 /**
23  * Setting given to rc_bmp_init which defines the oversampling
24  * done internally to the barometer. For example, if BMP_OVERSAMPLE_16 is used
25  * then the barometer will average 16 samples before updating the data
26  * registers. The more oversampling used, the slower the data registers will
27  * update. You should pick an oversample that provides an update rate slightly
28  * slower than the rate at which you will be reading the barometer.
29  */
30 typedef enum rc_bmp_oversample_t{
31  BMP_OVERSAMPLE_1 = (0x01<<2), ///< update rate 182 HZ
32  BMP_OVERSAMPLE_2 = (0x02<<2), ///< update rate 133 HZ
33  BMP_OVERSAMPLE_4 = (0x03<<2), ///< update rate 87 HZ
34  BMP_OVERSAMPLE_8 = (0x04<<2), ///< update rate 51 HZ
35  BMP_OVERSAMPLE_16 = (0x05<<2) ///< update rate 28 HZ
37 
38 
39 /**
40  * Setting given to rc_bmp_init to configure the coefficient of the internal
41  * first order filter. We recommend disabling the filter with BMP_FILTER_OFF and
42  * doing your own filtering with the discrete filter functions below.
43  */
44 typedef enum rc_bmp_filter_t{
45  BMP_FILTER_OFF = (0x00<<2),
46  BMP_FILTER_2 = (0x01<<2),
47  BMP_FILTER_4 = (0x02<<2),
48  BMP_FILTER_8 = (0x03<<2),
49  BMP_FILTER_16 = (0x04<<2)
51 
52 
53 /**
54  * struct to hold the data retreived during one read of the barometer.
55  */
56 typedef struct rc_bmp_data_t{
57  double temp_c; ///< temperature in degrees celcius
58  double alt_m; ///< altitude in meters
59  double pressure_pa; ///< current pressure in pascals
61 
62 
63 /**
64  * @brief powers on the barometer and initializes it with the given
65  * oversample and filter settings.
66  *
67  * Optionally call rc_bmp_set_sea_level_pressure_pa afterwards to change the sea
68  * level pressure from default.
69  *
70  * @param[in] oversample see rc_bmp_oversample_t
71  * @param[in] filter see rc_bmp_filter_t
72  *
73  * @return 0 on success, otherwise -1.
74  */
75 int rc_bmp_init(rc_bmp_oversample_t oversample, rc_bmp_filter_t filter);
76 
77 
78 /**
79  * @brief If you know the current sea level pressure for your region and
80  * weather, you can use this to correct the altititude reading.
81  *
82  * This is not necessary if you only care about differential altitude from a
83  * starting point. Must be called after rc_bmp_init to have an effect.
84  *
85  * @param[in] pa sea level pressure in pascals
86  *
87  * @return 0 on success, -1 on failure
88  */
90 
91 
92 /**
93  * @brief Puts the barometer into a low power state, should be called at
94  * the end of your program before close.
95  *
96  * @return 0 on success, -1 on failure
97  */
98 int rc_bmp_power_off(void);
99 
100 
101 /**
102  * @brief Reads the newest temperature and pressure measurments from the
103  * barometer over the I2C bus.
104  *
105  * @param data pointer to data struct where new data will be written.
106  *
107  * @return 0 on success, -1 on failure
108  */
109 int rc_bmp_read(rc_bmp_data_t* data);
110 
111 
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif // RC_BMP_H
118 
119 /** @} end group Barometer */
rc_bmp_oversample_t
Definition: bmp.h:30
double alt_m
altitude in meters
Definition: bmp.h:58
update rate 182 HZ
Definition: bmp.h:31
double pressure_pa
current pressure in pascals
Definition: bmp.h:59
Definition: bmp.h:47
Definition: bmp.h:56
update rate 28 HZ
Definition: bmp.h:35
double temp_c
temperature in degrees celcius
Definition: bmp.h:57
rc_bmp_filter_t
Definition: bmp.h:44
int rc_bmp_read(rc_bmp_data_t *data)
Reads the newest temperature and pressure measurments from the barometer over the I2C bus...
int rc_bmp_init(rc_bmp_oversample_t oversample, rc_bmp_filter_t filter)
powers on the barometer and initializes it with the given oversample and filter settings.
update rate 133 HZ
Definition: bmp.h:32
update rate 51 HZ
Definition: bmp.h:34
Definition: bmp.h:45
update rate 87 HZ
Definition: bmp.h:33
Definition: bmp.h:49
int rc_bmp_power_off(void)
Puts the barometer into a low power state, should be called at the end of your program before close...
struct rc_bmp_data_t rc_bmp_data_t
int rc_bmp_set_sea_level_pressure_pa(double pa)
If you know the current sea level pressure for your region and weather, you can use this to correct t...
Definition: bmp.h:48
Definition: bmp.h:46