Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
mf_ptu.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Gautier Hattenberger
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  */
22 
23 #include "modules/meteo/mf_ptu.h"
24 
25 #include "mcu_periph/gpio.h"
26 #include "mcu_periph/adc.h"
27 #include "mcu_periph/pwm_input.h"
28 #include "generated/airframe.h"
29 
33 #ifndef PTU_PRESSURE_OFFSET
34 #define PTU_PRESSURE_OFFSET 0
35 #endif
36 #ifndef PTU_PRESSURE_SCALE
37 #define PTU_PRESSURE_SCALE 1.0
38 #endif
39 #ifndef PTU_TEMPERATURE_OFFSET
40 #define PTU_TEMPERATURE_OFFSET 0
41 #endif
42 #ifndef PTU_TEMPERATURE_SCALE
43 #define PTU_TEMPERATURE_SCALE 1.0
44 #endif
45 #ifndef PTU_HUMIDTY_OFFSET
46 #define PTU_HUMIDTY_OFFSET 0
47 #endif
48 #ifndef PTU_HUMIDTY_SCALE
49 #define PTU_HUMIDTY_SCALE 1.0
50 #endif
51 
53 #ifndef ADC_CHANNEL_PTU_NB_SAMPLES
54 #define ADC_CHANNEL_PTU_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
55 #endif
56 struct adc_buf pressure_buf;
57 struct adc_buf temp_buf;
58 
63 
64 #if LOG_PTU
66 bool log_ptu_started;
67 #endif
68 
69 #if SEND_PTU
70 #include "mcu_periph/uart.h"
71 #include "pprzlink/messages.h"
73 #include "modules/gps/gps.h"
74 #endif
75 
76 void mf_ptu_init(void)
77 {
79  adc_buf_channel(ADC_CHANNEL_TEMPERATURE, &temp_buf, ADC_CHANNEL_PTU_NB_SAMPLES);
80 
81 #ifdef PTU_POWER_GPIO
82  gpio_setup_output(PTU_POWER_GPIO);
83  gpio_set(PTU_POWER_GPIO);
84 #endif
85 
86  pressure_adc = 0;
87  temp_adc = 0;
88  humid_period = 0;
89 
90 #if LOG_PTU
91  log_ptu_started = false;
92 #endif
93 }
94 
95 void mf_ptu_periodic(void)
96 {
97  // Read ADC
100  // Read PWM
101  humid_period = get_pwm_input_period_in_usec(PWM_INPUT_CHANNEL_HUMIDITY);
102 
103  // Log data
104 #if LOG_PTU
105  if (pprzLogFile != -1) {
106  if (!log_ptu_started) {
107  sdLogWriteLog(pprzLogFile,
108  "P(adc) T(adc) H(usec) GPS_fix TOW(ms) Week Lat(1e7rad) Lon(1e7rad) HMSL(mm) gpseed(cm/s) course(1e7rad) climb(cm/s)\n");
109  log_ptu_started = true;
110  } else {
111  sdLogWriteLog(pprzLogFile, "%d %d %d %d %d %d %d %d %d %d %d %d\n",
113  gps.fix, gps.tow, gps.week,
116  }
117  }
118 #endif
119 
120  // Send data
121 #if SEND_PTU
122 #define PTU_DATA_SIZE 3
123  float ptu_data[PTU_DATA_SIZE];
124  ptu_data[0] = (float)(PTU_PRESSURE_SCALE * ((int16_t)pressure_adc - PTU_PRESSURE_OFFSET));
125  ptu_data[1] = (float)(PTU_TEMPERATURE_SCALE * ((int16_t)temp_adc - PTU_TEMPERATURE_OFFSET));
126  ptu_data[2] = (float)(PTU_HUMIDTY_SCALE * ((int16_t)humid_period - PTU_HUMIDTY_OFFSET));
127  DOWNLINK_SEND_PAYLOAD_FLOAT(DefaultChannel, DefaultDevice, PTU_DATA_SIZE, ptu_data);
128 #endif
129 }
130 
131 
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:54
uint8_t av_nb_sample
Definition: adc.h:57
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
Some architecture independent helper functions for GPIOs.
struct GpsState gps
global GPS state
Definition: gps.c:69
Device independent GPS code (interface)
uint32_t tow
GPS time of week in ms.
Definition: gps.h:108
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:93
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:91
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:98
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:95
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:96
uint16_t week
GPS week.
Definition: gps.h:107
uint8_t fix
status of fix
Definition: gps.h:106
int32_t lat
in degrees*1e7
int32_t z
Down.
int32_t lon
in degrees*1e7
#define PTU_PRESSURE_OFFSET
Default scale and offset send raw values if nothing defined in airframe file.
Definition: mf_ptu.c:34
uint32_t humid_period
Definition: mf_ptu.c:62
void mf_ptu_init(void)
Data acquisition module for Meteo France PTU board.
Definition: mf_ptu.c:76
struct adc_buf pressure_buf
Definition: mf_ptu.c:56
void mf_ptu_periodic(void)
Definition: mf_ptu.c:95
#define ADC_CHANNEL_PTU_NB_SAMPLES
ADC buffers.
Definition: mf_ptu.c:54
uint16_t pressure_adc
Raw values.
Definition: mf_ptu.c:60
struct adc_buf temp_buf
Definition: mf_ptu.c:57
#define PTU_PRESSURE_SCALE
Definition: mf_ptu.c:37
uint16_t temp_adc
Definition: mf_ptu.c:61
#define PTU_HUMIDTY_SCALE
Definition: mf_ptu.c:49
#define PTU_TEMPERATURE_SCALE
Definition: mf_ptu.c:43
#define PTU_TEMPERATURE_OFFSET
Definition: mf_ptu.c:40
#define PTU_HUMIDTY_OFFSET
Definition: mf_ptu.c:46
uint32_t get_pwm_input_period_in_usec(uint32_t channel)
Definition: pwm_input.c:44
arch independent PWM input capture API
FileDes pprzLogFile
Definition: sdlog_chibios.c:75
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93