Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
baro_board.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2010 The Paparazzi Team
3
*
4
* This file is part of paparazzi.
5
*
6
* paparazzi is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
9
* any later version.
10
*
11
* paparazzi is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with paparazzi; see the file COPYING. If not, write to
18
* the Free Software Foundation, 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
20
*/
21
28
#include "
subsystems/sensors/baro.h
"
29
30
#include "generated/airframe.h"
31
#include "
subsystems/abi.h
"
32
#include "
led.h
"
33
34
36
#ifndef BOOZ_ANALOG_BARO_THRESHOLD
37
#define BOOZ_ANALOG_BARO_THRESHOLD 850
38
#endif
39
59
#ifndef BOOZ_BARO_SENS
60
#define BOOZ_BARO_SENS 0.759837
61
#endif
62
63
struct
BaroBoard
baro_board
;
64
65
void
baro_init
(
void
)
66
{
67
68
adc_buf_channel
(
ADC_CHANNEL_BARO
, &
baro_board
.
buf
,
DEFAULT_AV_NB_SAMPLE
);
69
70
baro_board
.
status
=
BB_UNINITIALIZED
;
71
baro_board
.
absolute
= 0;
72
baro_board
.
offset
= 1023;
73
DACSet
(
baro_board
.
offset
);
74
baro_board
.
value_filtered
= 0;
75
#ifdef BARO_LED
76
LED_OFF
(BARO_LED);
77
#endif
78
}
79
80
void
baro_periodic
(
void
)
81
{
82
83
baro_board
.
absolute
=
baro_board
.
buf
.
sum
/
baro_board
.
buf
.
av_nb_sample
;
84
baro_board
.
value_filtered
= (3 *
baro_board
.
value_filtered
+
baro_board
.
absolute
) / 4;
85
if
(
baro_board
.
status
==
BB_UNINITIALIZED
) {
86
RunOnceEvery(10, {
baro_board_calibrate
();});
87
}
else
{
88
uint32_t
now_ts =
get_sys_time_usec
();
89
float
pressure = 101325.0 -
BOOZ_BARO_SENS
* (
BOOZ_ANALOG_BARO_THRESHOLD
-
baro_board
.
absolute
);
90
AbiSendMsgBARO_ABS(
BARO_BOARD_SENDER_ID
, now_ts, pressure);
91
}
92
}
93
94
/* decrement offset until adc reading is over a threshold */
95
void
baro_board_calibrate
(
void
)
96
{
97
if
(
baro_board
.
value_filtered
<
BOOZ_ANALOG_BARO_THRESHOLD
&&
baro_board
.
offset
>= 1) {
98
if
(
baro_board
.
value_filtered
== 0 &&
baro_board
.
offset
> 15) {
99
baro_board
.
offset
-= 15;
100
}
else
{
101
baro_board
.
offset
--;
102
}
103
DACSet
(
baro_board
.
offset
);
104
#ifdef BARO_LED
105
LED_TOGGLE
(BARO_LED);
106
#endif
107
}
else
{
108
baro_board
.
status
=
BB_RUNNING
;
109
#ifdef BARO_LED
110
LED_ON
(BARO_LED);
111
#endif
112
}
113
}
114
BARO_BOARD_SENDER_ID
#define BARO_BOARD_SENDER_ID
default onboard baro
Definition:
abi_sender_ids.h:33
LED_OFF
#define LED_OFF(i)
Definition:
led_hw.h:52
abi.h
adc_buf_channel
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
Definition:
adc_arch.c:289
DACSet
static void DACSet(uint16_t x)
Definition:
dac_arch.h:36
BaroBoard::buf
struct adc_buf buf
Definition:
baro_board.h:47
uint32_t
unsigned long uint32_t
Definition:
types.h:18
LED_ON
#define LED_ON(i)
Definition:
led_hw.h:51
adc_buf::sum
uint32_t sum
Definition:
adc.h:54
LED_TOGGLE
#define LED_TOGGLE(i)
Definition:
led_hw.h:53
BB_UNINITIALIZED
@ BB_UNINITIALIZED
Definition:
baro_board.h:38
baro_init
void baro_init(void)
Definition:
baro_board.c:76
baro_periodic
void baro_periodic(void)
Definition:
baro_board.c:90
BOOZ_BARO_SENS
#define BOOZ_BARO_SENS
scale factor to convert raw ADC measurement to pressure in Pascal.
Definition:
baro_board.c:60
BaroBoard
Definition:
baro_board.h:42
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition:
sys_time_arch.c:68
ADC_CHANNEL_BARO
#define ADC_CHANNEL_BARO
Definition:
booz_1.0.h:111
BOOZ_ANALOG_BARO_THRESHOLD
#define BOOZ_ANALOG_BARO_THRESHOLD
threshold >0 && <1023
Definition:
baro_board.c:37
BaroBoard::offset
uint16_t offset
Definition:
baro_board.h:45
adc_buf::av_nb_sample
uint8_t av_nb_sample
Definition:
adc.h:57
led.h
arch independent LED (Light Emitting Diodes) API
BaroBoard::status
enum BaroBoardStatus status
Definition:
baro_board.h:43
baro.h
BaroBoard::value_filtered
uint16_t value_filtered
Definition:
baro_board.h:46
baro_board
struct BaroBoard baro_board
Definition:
baro_board.c:63
BB_RUNNING
@ BB_RUNNING
Definition:
baro_board.h:39
baro_board_calibrate
void baro_board_calibrate(void)
Definition:
baro_board.c:95
BaroBoard::absolute
int32_t absolute
Definition:
baro_board.h:44
DEFAULT_AV_NB_SAMPLE
#define DEFAULT_AV_NB_SAMPLE
Definition:
adc.h:41
sw
airborne
boards
booz
baro_board.c
Generated on Tue Feb 1 2022 13:51:13 for Paparazzi UAS by
1.8.17