Skip to content

Commit

Permalink
[module] add a new meteo module to get data from Meteo France PTU board
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierhattenberger committed Jun 26, 2014
1 parent 4ba57b1 commit bf27f53
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 0 deletions.
37 changes: 37 additions & 0 deletions conf/modules/mf_ptu.xml
@@ -0,0 +1,37 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="mf_ptu" dir="meteo">
<doc>
<description>Data acquisition module for the PTU board from Meteo France (pressure, temperature, humidity)</description>
<configure name="ADC_PRESSURE" value="ADC_X" description="Select ADC channel for pressure sensor"/>
<configure name="ADC_TEMPERATURE" value="ADC_X" description="Select ADC channel for temperature sensor"/>
<configure name="PWM_INPUT_HUMIDITY" value="PWM_INPUTX" description="Select PWM input channel for humidity sensor"/>
<section name="MF_PTU">
<define name="PTU_POWER_GPIO" value="GPIOX,GPIOYY" description="If defined, enable power by setting the specified GPIO to 1 at starup"/>
<define name="PTU_PRESSURE_OFFSET" value="0" description="Offset in ADC of the pressure sensor"/>
<define name="PTU_PRESSURE_OFFSET" value="1." description="Scale factor of the pressure sensor"/>
<define name="PTU_TEMPERATURE_OFFSET" value="0" description="Offset in ADC of the temperature sensor"/>
<define name="PTU_TEMPERATURE_OFFSET" value="1." description="Scale factor of the temperature sensor"/>
<define name="PTU_HUMIDITY_OFFSET" value="0" description="Offset in micro seconds of the humidity sensor"/>
<define name="PTU_HUMIDITY_OFFSET" value="1." description="Scale factor of the pressure sensor"/>
<define name="LOG_PTU" value="TRUE|FALSE" description="Log data on SD card (ascii format, raw PTU data + GPS data"/>
<define name="SEND_PTU" value="TRU|FALSE" description="Send data over telemetry (PAYLOAD_FLOAT message, scaled PTU data"/>
</section>
</doc>
<depend require="pwm_meas"/>
<header>
<file name="mf_ptu.h"/>
</header>
<init fun="mf_ptu_init()"/>
<periodic fun="mf_ptu_periodic()" freq="10" autorun="TRUE"/>
<makefile target="ap">
<file name="mf_ptu.c"/>
<define name="ADC_CHANNEL_PRESSURE" value="$(ADC_PRESSURE)"/>
<define name="USE_$(ADC_PRESSURE)"/>
<define name="ADC_CHANNEL_TEMPERATURE" value="$(ADC_TEMPERATURE)"/>
<define name="USE_$(ADC_TEMPERATURE)"/>
<define name="PWM_INPUT_CHANNEL_HUMIDITY" value="$(PWM_INPUT_HUMIDITY)"/>
<define name="USE_$(PWM_INPUT_HUMIDITY)" value="PWM_PULSE_TYPE_ACTIVE_LOW"/>
</makefile>
</module>

119 changes: 119 additions & 0 deletions sw/airborne/modules/meteo/mf_ptu.c
@@ -0,0 +1,119 @@
/*
* Copyright (C) 2014 Gautier Hattenberger
*
* This file is part of paparazzi
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/

#include "modules/meteo/mf_ptu.h"

#include "mcu_periph/gpio.h"
#include "mcu_periph/adc.h"
#include "mcu_periph/pwm_input.h"
#include "generated/airframe.h"

/** Default scale and offset
* send raw values if nothing defined in airframe file
*/
#ifndef PTU_PRESSURE_OFFSET
#define PTU_PRESSURE_OFFSET 0
#endif
#ifndef PTU_PRESSURE_SCALE
#define PTU_PRESSURE_SCALE 1.0
#endif
#ifndef PTU_TEMPERATURE_OFFSET
#define PTU_TEMPERATURE_OFFSET 0
#endif
#ifndef PTU_TEMPERATURE_SCALE
#define PTU_TEMPERATURE_SCALE 1.0
#endif
#ifndef PTU_HUMIDTY_OFFSET
#define PTU_HUMIDTY_OFFSET 0
#endif
#ifndef PTU_HUMIDTY_SCALE
#define PTU_HUMIDTY_SCALE 1.0
#endif

/** ADC buffers */
#ifndef ADC_CHANNEL_PTU_NB_SAMPLES
#define ADC_CHANNEL_PTU_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
#endif
struct adc_buf pressure_buf;
struct adc_buf temp_buf;

/** Raw values */
uint16_t pressure_adc;
uint16_t temp_adc;
uint32_t humid_period;

#if LOG_PTU
#include "sdLog.h"
#include "subsystems/chibios-libopencm3/chibios_sdlog.h"
#endif

#if SEND_PTU
#include "mcu_periph/uart.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
#include "subsystems/gps.h"
#endif

void mf_ptu_init(void) {
adc_buf_channel(ADC_CHANNEL_PRESSURE, &pressure_buf, ADC_CHANNEL_PTU_NB_SAMPLES);
adc_buf_channel(ADC_CHANNEL_TEMPERATURE, &temp_buf, ADC_CHANNEL_PTU_NB_SAMPLES);

#ifdef PTU_POWER_GPIO
gpio_setup_output(PTU_POWER_GPIO);
gpio_set(PTU_POWER_GPIO);
#endif

pressure_adc = 0;
temp_adc = 0;
humid_period = 0;
}

void mf_ptu_periodic(void) {
// Read ADC
pressure_adc = pressure_buf.sum / pressure_buf.av_nb_sample;
temp_adc = temp_buf.sum / temp_buf.av_nb_sample;
// Read PWM
humid_period = USEC_OF_PWM_INPUT_TICKS(pwm_input_period_tics[PWM_INPUT_CHANNEL_HUMIDITY]);

// Log data
#if LOG_PTU
if (pprzLogFile.fs != NULL) {
sdLogWriteLog(&pprzLogFile, "%d %d %d %d %d %d %d %d %d %d %d %d\n",
pressure_adc, temp_adc, humid_period,
gps.fix, gps.tow, gps.week,
gps.lla_pos.lat, gps.lla_pos.lon, gps.hmsl,
gps.gspeed, gps.course, -gps.ned_vel.z);
}
#endif

// Send data
#if SEND_PTU
#define PTU_DATA_SIZE 3
float ptu_data[PTU_DATA_SIZE];
ptu_data[0] = (float)(PTU_PRESSURE_SCALE * ((int16_t)pressure_adc - PTU_PRESSURE_OFFSET));
ptu_data[1] = (float)(PTU_TEMPERATURE_SCALE * ((int16_t)temp_adc - PTU_TEMPERATURE_OFFSET));
ptu_data[2] = (float)(PTU_HUMIDTY_SCALE * ((int16_t)humid_period - PTU_HUMIDTY_OFFSET));
DOWNLINK_SEND_PAYLOAD_FLOAT(DefaultChannel, DefaultDevice, PTU_DATA_SIZE, ptu_data);
#endif
}


33 changes: 33 additions & 0 deletions sw/airborne/modules/meteo/mf_ptu.h
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2014 Gautier Hattenberger
*
* This file is part of paparazzi
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/

/** Data acquisition module for Meteo France PTU board
*/

#ifndef MF_PTU_H
#define MF_PTU_H

extern void mf_ptu_init(void);
extern void mf_ptu_periodic(void);

#endif

0 comments on commit bf27f53

Please sign in to comment.