Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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
65 #include "sdLog.h"
66 #include "subsystems/chibios-libopencm3/chibios_sdlog.h"
67 bool_t log_ptu_started;
68 #endif
69 
70 #if SEND_PTU
71 #include "mcu_periph/uart.h"
72 #include "messages.h"
74 #include "subsystems/gps.h"
75 #endif
76 
77 void mf_ptu_init(void) {
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  // Read ADC
99  // Read PWM
100  humid_period = USEC_OF_PWM_INPUT_TICKS(pwm_input_period_tics[PWM_INPUT_CHANNEL_HUMIDITY]);
101 
102  // Log data
103 #if LOG_PTU
104  if (pprzLogFile.fs != NULL) {
105  if (!log_ptu_started) {
106  sdLogWriteLog(&pprzLogFile, "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");
107  log_ptu_started = TRUE;
108  }
109  else {
110  sdLogWriteLog(&pprzLogFile, "%d %d %d %d %d %d %d %d %d %d %d %d\n",
112  gps.fix, gps.tow, gps.week,
115  }
116  }
117 #endif
118 
119  // Send data
120 #if SEND_PTU
121 #define PTU_DATA_SIZE 3
122  float ptu_data[PTU_DATA_SIZE];
123  ptu_data[0] = (float)(PTU_PRESSURE_SCALE * ((int16_t)pressure_adc - PTU_PRESSURE_OFFSET));
124  ptu_data[1] = (float)(PTU_TEMPERATURE_SCALE * ((int16_t)temp_adc - PTU_TEMPERATURE_OFFSET));
125  ptu_data[2] = (float)(PTU_HUMIDTY_SCALE * ((int16_t)humid_period - PTU_HUMIDTY_OFFSET));
126  DOWNLINK_SEND_PAYLOAD_FLOAT(DefaultChannel, DefaultDevice, PTU_DATA_SIZE, ptu_data);
127 #endif
128 }
129 
130 
unsigned short uint16_t
Definition: types.h:16
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:65
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:69
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:77
int32_t lat
in degrees*1e7
#define PTU_PRESSURE_SCALE
Definition: mf_ptu.c:37
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:72
#define ADC_CHANNEL_PTU_NB_SAMPLES
ADC buffers.
Definition: mf_ptu.c:54
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
Definition: adc_arch.c:59
Some architecture independent helper functions for GPIOs.
arch independent PWM input capture API
struct adc_buf pressure_buf
Definition: mf_ptu.c:56
void gpio_set(uint32_t port, uint16_t pin)
Set a gpio output to high level.
#define PTU_HUMIDTY_SCALE
Definition: mf_ptu.c:49
int32_t hmsl
height above mean sea level in mm
Definition: gps.h:67
#define USEC_OF_PWM_INPUT_TICKS(_v)
uint8_t fix
status of fix
Definition: gps.h:78
uint8_t av_nb_sample
Definition: adc.h:57
int16_t week
GPS week.
Definition: gps.h:79
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:54
#define FALSE
Definition: imu_chimu.h:141
uint16_t temp_adc
Definition: mf_ptu.c:61
uint32_t tow
GPS time of week in ms.
Definition: gps.h:80
int32_t z
Down.
uint16_t pressure_adc
Raw values.
Definition: mf_ptu.c:60
void mf_ptu_periodic(void)
Definition: mf_ptu.c:95
int16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:70
#define PTU_TEMPERATURE_SCALE
Definition: mf_ptu.c:43
Device independent GPS code (interface)
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
uint32_t humid_period
Definition: mf_ptu.c:62
volatile uint32_t pwm_input_period_tics[PWM_INPUT_NB]
Definition: pwm_input.c:31
#define TRUE
Definition: imu_chimu.h:144
struct adc_buf temp_buf
Definition: mf_ptu.c:57
static void gpio_setup_output(uint32_t port, uint32_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.h:76
int32_t lon
in degrees*1e7
#define PTU_TEMPERATURE_OFFSET
Definition: mf_ptu.c:40
#define PTU_HUMIDTY_OFFSET
Definition: mf_ptu.c:46
struct GpsState gps
global GPS state
Definition: gps.c:41
#define PTU_PRESSURE_OFFSET
Default scale and offset send raw values if nothing defined in airframe file.
Definition: mf_ptu.c:34