Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
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 "subsystems/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 = USEC_OF_PWM_INPUT_TICKS(pwm_input_period_tics[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 
uint8_t av_nb_sample
Definition: adc.h:57
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void mf_ptu_init(void)
Data acquisition module for Meteo France PTU board.
Definition: mf_ptu.c:76
#define PTU_PRESSURE_SCALE
Definition: mf_ptu.c:37
#define ADC_CHANNEL_PTU_NB_SAMPLES
ADC buffers.
Definition: mf_ptu.c:54
uint16_t week
GPS week.
Definition: gps.h:100
Some architecture independent helper functions for GPIOs.
arch independent PWM input capture API
struct adc_buf pressure_buf
Definition: mf_ptu.c:56
#define PTU_HUMIDTY_SCALE
Definition: mf_ptu.c:49
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:265
uint32_t sum
Definition: adc.h:54
int32_t z
Down.
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
arch independent ADC (Analog to Digital Converter) API
#define USEC_OF_PWM_INPUT_TICKS(_v)
uint16_t temp_adc
Definition: mf_ptu.c:61
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
uint16_t pressure_adc
Raw values.
Definition: mf_ptu.c:60
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:88
void mf_ptu_periodic(void)
Definition: mf_ptu.c:95
#define PTU_TEMPERATURE_SCALE
Definition: mf_ptu.c:43
uint32_t tow
GPS time of week in ms.
Definition: gps.h:101
Device independent GPS code (interface)
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
int32_t lon
in degrees*1e7
FileDes pprzLogFile
Definition: sdlog_chibios.c:76
uint32_t humid_period
Definition: mf_ptu.c:62
volatile uint32_t pwm_input_period_tics[PWM_INPUT_NB]
Definition: pwm_input.c:31
struct adc_buf temp_buf
Definition: mf_ptu.c:57
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:93
#define PTU_TEMPERATURE_OFFSET
Definition: mf_ptu.c:40
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:91
#define PTU_HUMIDTY_OFFSET
Definition: mf_ptu.c:46
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:86
int32_t lat
in degrees*1e7
uint8_t fix
status of fix
Definition: gps.h:99
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:90
struct GpsState gps
global GPS state
Definition: gps.c:75
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
Definition: gpio_arch.h:93
#define PTU_PRESSURE_OFFSET
Default scale and offset send raw values if nothing defined in airframe file.
Definition: mf_ptu.c:34