Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
pump_control.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
29#include "navigation.h"
30#include "mcu_periph/adc.h"
31#include "mcu_periph/gpio.h"
33
34#ifndef PUMP_CONTROL_ADC
35#error "PUMP_CONTROL_ADC must be defined!"
36#define PUMP_CONTROL_ADC ADC_4
37#endif
38
39#ifndef PUMP_CONTROL_ADC_EMPTY
40#define PUMP_CONTROL_ADC_EMPTY 20000
41#endif
42
43#ifndef PUMP_CONTROL_GPIO_ACTIVATE
44#define PUMP_CONTROL_GPIO_ACTIVATE GPIOA,GPIO0
45#endif
46
47#ifndef PUMP_CONTROL_GPIO_PURGE
48#define PUMP_CONTROL_GPIO_PURGE GPIOA,GPIO1
49#endif
50
51
52#define PUMP_CTRL_OFF 0
53#define PUMP_CTRL_PUMP 1
54#define PUMP_CTRL_VALVE 2
55
56static const float nav_dt = 1.f / NAVIGATION_FREQUENCY;
57
59
61 struct adc_buf adc_b;
62 float time;
64};
65
67
78
87
96
103
107
108bool pump_done(float duration, float timeout)
109{
111 if (pump_pumping()) {
113 }
114 if ((timeout > 0.f && pump_control.time > timeout)
115 || pump_control.time_pumping > duration) {
116 return true;
117 }
118 return false;
119}
120
121void pump_control_handler(float value) {
122 int val = value;
123 switch (val)
124 {
125 case PUMP_CTRL_OFF:
126 pump_stop();
127 break;
128 case PUMP_CTRL_PUMP:
130 break;
131 case PUMP_CTRL_VALVE:
132 pump_purge();
133 break;
134
135 default:
136 break;
137 }
138}
139
arch independent ADC (Analog to Digital Converter) API
#define DEFAULT_AV_NB_SAMPLE
Definition adc.h:41
static uint16_t adc_buf_get(struct adc_buf *s)
Get filtered value from buffer.
Definition adc.h:76
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition adc.h:53
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:312
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition gpio_arch.c:33
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
Definition gpio_arch.h:104
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
Definition gpio_arch.h:114
Some architecture independent helper functions for GPIOs.
uint16_t foo
Definition main_demo5.c:58
#define NAVIGATION_FREQUENCY
Default fixedwing navigation frequency.
Definition nav.h:49
static float timeout
void pump_control_init(void)
void pump_stop(void)
#define PUMP_CONTROL_ADC
void pump_control_report(void)
void pump_purge(void)
#define PUMP_CONTROL_GPIO_ACTIVATE
bool pump_pumping(void)
#define PUMP_CTRL_VALVE
#define PUMP_CTRL_PUMP
float time_pumping
float pump_ctrl_state
bool pump_done(float duration, float timeout)
#define PUMP_CONTROL_ADC_EMPTY
void pump_control_handler(float value)
#define PUMP_CONTROL_GPIO_PURGE
void pump_activate(void)
static const float nav_dt
static struct PumpControl pump_control
struct adc_buf adc_b
#define PUMP_CTRL_OFF
uint16_t val[TCOUPLE_NB]
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.