Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
cloud_sensor.c File Reference

Get data from Cloud Sensor. More...

#include "modules/meteo/cloud_sensor.h"
#include "generated/airframe.h"
#include "state.h"
#include "modules/core/abi.h"
#include "pprzlink/messages.h"
#include "modules/datalink/downlink.h"
#include "math/pprz_geodetic_float.h"
#include "math/pprz_stat.h"
#include "modules/gps/gps.h"
#include "filters/low_pass_filter.h"
#include "modules/loggers/sdlog_chibios.h"
#include "modules/loggers/pprzlog_tp.h"
+ Include dependency graph for cloud_sensor.c:

Go to the source code of this file.

Data Structures

struct  LinReg
 Structure used to compute the linear regression that provides the angstrom coefficient. More...
 
struct  Background
 Structure used to compute the background and the threshold which is a list of raw data, the mean and the standard deviation. More...
 
struct  CloudSensor
 Cloud sensor structure. More...
 
struct  MedianFilter
 Median Filter structure. More...
 

Macros

#define CLOUD_SENSOR_LOG_FILE   flightrecorder_sdlog
 
#define CLOUD_SENSOR_RAW_MAX   16
 
#define CLOUD_SENSOR_NB   4
 
#define CLOUD_SENSOR_OFFSET   4
 
#define CLOUD_SENSOR_BORDER_THRESHOLD   0.05
 
#define CLOUD_SENSOR_BORDER_HYSTERESIS   0.01
 
#define CLOUD_SENSOR_SINGLE_CHANNEL   1
 
#define CLOUD_SENSOR_BACKGROUND_THRESHOLD_COEF   2.f
 
#define CLOUD_SENSOR_BACKGROUND_HYSTERESIS_COEF   0.5f
 
#define CLOUD_SENSOR_CALIB_ALPHA   1.f
 
#define CLOUD_SENSOR_CALIB_BETA   1.f
 
#define CLOUD_SENSOR_CHANNEL_SCALE   1.f
 
#define CLOUD_SENSOR_TAU   0.f
 
#define CLOUD_RAW   0
 
#define CLOUD_BORDER   1
 
#define CLOUD_SENSOR_REPORT_BORDER_CROSSING   FALSE
 
#define CLOUD_SENSOR_LAMBDA   { 505.f, 590.f, 840.f, 840.f }
 
#define CLOUD_SENSOR_ANGSTROM_COEF   { 1.f, 1.f, 1.f, 1.f }
 
#define CLOUD_SENSOR_ANGSTROM_OFFSET   { 1.f, 1.f, 1.f, 1.f }
 
#define CLOUD_SENSOR_BACKGROUND_NB   30
 

Functions

static float lwc_from_buffer (uint8_t *buf)
 
static void send_cloud_sensor_data (struct transport_tx *trans, struct link_device *dev)
 
static void check_border (void)
 
static void send_data (uint32_t stamp)
 
void cloud_sensor_init (void)
 Init function. More...
 
void cloud_sensor_update_tau (float tau)
 
float median_filter_update (float new_sample, struct MedianFilter *filter)
 Median filter function. More...
 
float cloud_sensor_filtering (float new_sample, struct MedianFilter *medianFilter, struct FirstOrderLowPass *lowPassFilter)
 
void cloud_sensor_callback (uint8_t *buf)
 End median filter function. More...
 
void LWC_callback (uint8_t *buf)
 
void cloud_sensor_report (void)
 Report function. More...
 

Variables

static float lambdas [] = CLOUD_SENSOR_LAMBDA
 
static float angstrom_coef [] = CLOUD_SENSOR_ANGSTROM_COEF
 
static float angstrom_offset [] = CLOUD_SENSOR_ANGSTROM_OFFSET
 
static struct CloudSensor cloud_sensor
 Local variables. More...
 
static bool log_tagged
 
static struct MedianFilter medianFilter0
 
static struct FirstOrderLowPass lowPassFilter0
 
uint8_t cloud_sensor_compute_coef
 Extern variables. More...
 
uint8_t cloud_sensor_compute_background
 
float cloud_sensor_threshold
 
float cloud_sensor_hysteresis
 
float cloud_sensor_background
 
float cloud_sensor_calib_alpha
 
float cloud_sensor_calib_beta
 
float cloud_sensor_channel_scale
 
float cloud_sensor_tau
 

Detailed Description

Get data from Cloud Sensor.

  • compute coef value from PAYLOAD_FLOAT data
    • Liquid Water Content (LWC)
    • Angstrom coef
    • single sensor
  • get already computed LWC from PAYLOAD_COMMAND data

Definition in file cloud_sensor.c.


Data Structure Documentation

◆ LinReg

struct LinReg

Structure used to compute the linear regression that provides the angstrom coefficient.

The slope of the linear regression is computed as cov(X,Y)/var(X). var(X) can be precomputed as LED frequencies are not changing.

Definition at line 145 of file cloud_sensor.c.

Data Fields
float lambda[CLOUD_SENSOR_NB] list of sensor LED frequencies
float var_lambda variance of lambda

◆ Background

struct Background

Structure used to compute the background and the threshold which is a list of raw data, the mean and the standard deviation.

Definition at line 159 of file cloud_sensor.c.

Data Fields
uint8_t idx current index
float mean[CLOUD_SENSOR_NB] mean of the lists
float raw[CLOUD_SENSOR_NB][CLOUD_SENSOR_BACKGROUND_NB] lists of raw values
float std[CLOUD_SENSOR_NB] std of the lists

◆ CloudSensor

struct CloudSensor

Cloud sensor structure.

Definition at line 168 of file cloud_sensor.c.

+ Collaboration diagram for CloudSensor:
Data Fields
struct Background background structure for background parameters
float coef scalar coeff related to cloud parameter (LWC, angstrom, extinction,...)
bool inside_cloud in/out status flag
uint8_t nb_raw number of raw data in array
float raw[CLOUD_SENSOR_RAW_MAX] raw cloud sensor values
struct LinReg reg linear regression parameters
float values[CLOUD_SENSOR_NB] preprocessed cloud sensor values

◆ MedianFilter

struct MedianFilter

Median Filter structure.

Definition at line 181 of file cloud_sensor.c.

Data Fields
int current
int length
float values[3]

Macro Definition Documentation

◆ CLOUD_BORDER

#define CLOUD_BORDER   1

Definition at line 113 of file cloud_sensor.c.

◆ CLOUD_RAW

#define CLOUD_RAW   0

Definition at line 112 of file cloud_sensor.c.

◆ CLOUD_SENSOR_ANGSTROM_COEF

#define CLOUD_SENSOR_ANGSTROM_COEF   { 1.f, 1.f, 1.f, 1.f }

Definition at line 129 of file cloud_sensor.c.

◆ CLOUD_SENSOR_ANGSTROM_OFFSET

#define CLOUD_SENSOR_ANGSTROM_OFFSET   { 1.f, 1.f, 1.f, 1.f }

Definition at line 135 of file cloud_sensor.c.

◆ CLOUD_SENSOR_BACKGROUND_HYSTERESIS_COEF

#define CLOUD_SENSOR_BACKGROUND_HYSTERESIS_COEF   0.5f

Definition at line 92 of file cloud_sensor.c.

◆ CLOUD_SENSOR_BACKGROUND_NB

#define CLOUD_SENSOR_BACKGROUND_NB   30

Definition at line 152 of file cloud_sensor.c.

◆ CLOUD_SENSOR_BACKGROUND_THRESHOLD_COEF

#define CLOUD_SENSOR_BACKGROUND_THRESHOLD_COEF   2.f

Definition at line 87 of file cloud_sensor.c.

◆ CLOUD_SENSOR_BORDER_HYSTERESIS

#define CLOUD_SENSOR_BORDER_HYSTERESIS   0.01

Definition at line 77 of file cloud_sensor.c.

◆ CLOUD_SENSOR_BORDER_THRESHOLD

#define CLOUD_SENSOR_BORDER_THRESHOLD   0.05

Definition at line 72 of file cloud_sensor.c.

◆ CLOUD_SENSOR_CALIB_ALPHA

#define CLOUD_SENSOR_CALIB_ALPHA   1.f

Definition at line 96 of file cloud_sensor.c.

◆ CLOUD_SENSOR_CALIB_BETA

#define CLOUD_SENSOR_CALIB_BETA   1.f

Definition at line 100 of file cloud_sensor.c.

◆ CLOUD_SENSOR_CHANNEL_SCALE

#define CLOUD_SENSOR_CHANNEL_SCALE   1.f

Definition at line 104 of file cloud_sensor.c.

◆ CLOUD_SENSOR_LAMBDA

#define CLOUD_SENSOR_LAMBDA   { 505.f, 590.f, 840.f, 840.f }

Definition at line 123 of file cloud_sensor.c.

◆ CLOUD_SENSOR_LOG_FILE

#define CLOUD_SENSOR_LOG_FILE   flightrecorder_sdlog

Definition at line 52 of file cloud_sensor.c.

◆ CLOUD_SENSOR_NB

#define CLOUD_SENSOR_NB   4

Definition at line 62 of file cloud_sensor.c.

◆ CLOUD_SENSOR_OFFSET

#define CLOUD_SENSOR_OFFSET   4

Definition at line 67 of file cloud_sensor.c.

◆ CLOUD_SENSOR_RAW_MAX

#define CLOUD_SENSOR_RAW_MAX   16

Definition at line 57 of file cloud_sensor.c.

◆ CLOUD_SENSOR_REPORT_BORDER_CROSSING

#define CLOUD_SENSOR_REPORT_BORDER_CROSSING   FALSE

Definition at line 117 of file cloud_sensor.c.

◆ CLOUD_SENSOR_SINGLE_CHANNEL

#define CLOUD_SENSOR_SINGLE_CHANNEL   1

Definition at line 82 of file cloud_sensor.c.

◆ CLOUD_SENSOR_TAU

#define CLOUD_SENSOR_TAU   0.f

Definition at line 108 of file cloud_sensor.c.

Function Documentation

◆ check_border()

static void check_border ( void  )
static

Definition at line 266 of file cloud_sensor.c.

References cloud_sensor, cloud_sensor_hysteresis, cloud_sensor_threshold, CloudSensor::coef, and CloudSensor::inside_cloud.

Referenced by cloud_sensor_callback(), and LWC_callback().

+ Here is the caller graph for this function:

◆ cloud_sensor_callback()

◆ cloud_sensor_filtering()

float cloud_sensor_filtering ( float  new_sample,
struct MedianFilter medianFilter,
struct FirstOrderLowPass lowPassFilter 
)

Definition at line 382 of file cloud_sensor.c.

References cloud_sensor_calib_alpha, cloud_sensor_calib_beta, cloud_sensor_channel_scale, median_filter_update(), PowerVoltage, and update_first_order_low_pass().

Referenced by cloud_sensor_callback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cloud_sensor_init()

◆ cloud_sensor_report()

void cloud_sensor_report ( void  )

Report function.

Definition at line 547 of file cloud_sensor.c.

References DefaultChannel, DefaultDevice, and send_cloud_sensor_data().

+ Here is the call graph for this function:

◆ cloud_sensor_update_tau()

void cloud_sensor_update_tau ( float  tau)

Definition at line 324 of file cloud_sensor.c.

References cloud_sensor_tau, lowPassFilter0, and update_first_order_low_pass_tau().

+ Here is the call graph for this function:

◆ LWC_callback()

void LWC_callback ( uint8_t buf)

Definition at line 532 of file cloud_sensor.c.

References check_border(), cloud_sensor, CloudSensor::coef, dl_buffer, get_sys_time_usec(), lwc_from_buffer(), and send_data().

+ Here is the call graph for this function:

◆ lwc_from_buffer()

static float lwc_from_buffer ( uint8_t buf)
static

Definition at line 207 of file cloud_sensor.c.

Referenced by LWC_callback().

+ Here is the caller graph for this function:

◆ median_filter_update()

float median_filter_update ( float  new_sample,
struct MedianFilter filter 
)

Median filter function.

Definition at line 332 of file cloud_sensor.c.

References MedianFilter::current, MedianFilter::length, and MedianFilter::values.

Referenced by cloud_sensor_filtering().

+ Here is the caller graph for this function:

◆ send_cloud_sensor_data()

static void send_cloud_sensor_data ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 218 of file cloud_sensor.c.

References cloud_sensor, CloudSensor::coef, dev, gps, GpsState::hmsl, CloudSensor::nb_raw, CloudSensor::raw, stateGetPositionLla_i(), GpsState::tow, and val.

Referenced by cloud_sensor_callback(), and cloud_sensor_report().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_data()

static void send_data ( uint32_t  stamp)
static

Definition at line 282 of file cloud_sensor.c.

References CLOUD_BORDER, CLOUD_RAW, cloud_sensor, CLOUD_SENSOR_ID, CloudSensor::coef, and CloudSensor::inside_cloud.

Referenced by cloud_sensor_callback(), encodeHighBytes(), and LWC_callback().

+ Here is the caller graph for this function:

Variable Documentation

◆ angstrom_coef

float angstrom_coef[] = CLOUD_SENSOR_ANGSTROM_COEF
static

Definition at line 131 of file cloud_sensor.c.

Referenced by cloud_sensor_callback().

◆ angstrom_offset

float angstrom_offset[] = CLOUD_SENSOR_ANGSTROM_OFFSET
static

Definition at line 137 of file cloud_sensor.c.

Referenced by cloud_sensor_callback().

◆ cloud_sensor

struct CloudSensor cloud_sensor
static

◆ cloud_sensor_background

float cloud_sensor_background

Definition at line 200 of file cloud_sensor.c.

Referenced by cloud_sensor_callback(), and cloud_sensor_init().

◆ cloud_sensor_calib_alpha

float cloud_sensor_calib_alpha

Definition at line 201 of file cloud_sensor.c.

Referenced by cloud_sensor_filtering(), and cloud_sensor_init().

◆ cloud_sensor_calib_beta

float cloud_sensor_calib_beta

Definition at line 202 of file cloud_sensor.c.

Referenced by cloud_sensor_filtering(), and cloud_sensor_init().

◆ cloud_sensor_channel_scale

float cloud_sensor_channel_scale

Definition at line 203 of file cloud_sensor.c.

Referenced by cloud_sensor_filtering(), and cloud_sensor_init().

◆ cloud_sensor_compute_background

uint8_t cloud_sensor_compute_background

Definition at line 197 of file cloud_sensor.c.

Referenced by cloud_sensor_callback().

◆ cloud_sensor_compute_coef

uint8_t cloud_sensor_compute_coef

Extern variables.

variables for settings

Definition at line 196 of file cloud_sensor.c.

Referenced by cloud_sensor_callback(), and cloud_sensor_init().

◆ cloud_sensor_hysteresis

float cloud_sensor_hysteresis

Definition at line 199 of file cloud_sensor.c.

Referenced by check_border(), cloud_sensor_callback(), and cloud_sensor_init().

◆ cloud_sensor_tau

float cloud_sensor_tau

Definition at line 204 of file cloud_sensor.c.

Referenced by cloud_sensor_init(), and cloud_sensor_update_tau().

◆ cloud_sensor_threshold

float cloud_sensor_threshold

Definition at line 198 of file cloud_sensor.c.

Referenced by check_border(), cloud_sensor_callback(), and cloud_sensor_init().

◆ lambdas

float lambdas[] = CLOUD_SENSOR_LAMBDA
static

Definition at line 125 of file cloud_sensor.c.

Referenced by cloud_sensor_init().

◆ log_tagged

bool log_tagged
static

Definition at line 190 of file cloud_sensor.c.

Referenced by cloud_sensor_callback(), cloud_sensor_init(), and meteo_stick_init().

◆ lowPassFilter0

struct FirstOrderLowPass lowPassFilter0
static

◆ medianFilter0

struct MedianFilter medianFilter0
static

Definition at line 190 of file cloud_sensor.c.

Referenced by cloud_sensor_callback(), and cloud_sensor_init().