Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
airspeed_uavcan.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 Freek van Tienen <freek.v.tienen@gmail.com>
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
26#include "airspeed_uavcan.h"
27#include "uavcan/uavcan.h"
28#include "core/abi.h"
29#include "uavcan.equipment.air_data.RawAirData.h"
30
31/* Enable ABI sending */
32#ifndef AIRSPEED_UAVCAN_SEND_ABI
33#define AIRSPEED_UAVCAN_SEND_ABI true
34#endif
35
36/* Default pressure scaling */
37#ifndef AIRSPEED_UAVCAN_DIFF_P_SCALE
38#define AIRSPEED_UAVCAN_DIFF_P_SCALE 1.0f
39#endif
40
41/* Airspeed lowpass filter*/
42#ifdef USE_AIRSPEED_UAVCAN_LOWPASS_FILTER
44
45#ifndef AIRSPEED_UAVCAN_LOWPASS_TAU
46#define AIRSPEED_UAVCAN_LOWPASS_TAU 0.15
47#endif
48
49#ifndef AIRSPEED_UAVCAN_LOWPASS_PERIOD
50#define AIRSPEED_UAVCAN_LOWPASS_PERIOD 0.1
51#endif
52
54#endif /* USE_AIRSPEED_UAVCAN_LOWPASS_FILTER */
55
56/* Local variables */
59
60#if PERIODIC_TELEMETRY
62
63static void airspeed_uavcan_downlink(struct transport_tx *trans, struct link_device *dev)
64{
66 uint16_t raw = 0;
67 float offset = 0;
68 float sign = 1.0f;
69 if (airspeed_uavcan.diff_p < 0) {
70 sign = -1.0f;
71 }
72 float airspeed = sqrt(airspeed_uavcan.diff_p * sign * 2.0f / 1.225f) * sign;
74 &dev_id,
75 &raw,
76 &offset,
79 &airspeed);
80}
81#endif /* PERIODIC_TELEMETRY */
82
84
86
88 return; // decode error
89 }
90
91 float diff_p = msg.differential_pressure;
92 float static_air_temp = msg.static_air_temperature;
93
94
95 if(!isnan(diff_p)) {
96 // Remove the offset and apply a scaling factor
99
100 // Filtering
101#ifdef USE_AIRSPEED_UAVCAN_LOWPASS_FILTER
104#else
105 airspeed_uavcan.diff_p = diff_p;
106#endif
107
108 // Send the ABI message
109#if AIRSPEED_UAVCAN_SEND_ABI
111#endif
112 }
113
114 if(!isnan(static_air_temp)) {
116#if AIRSPEED_UAVCAN_SEND_ABI
118#endif
119 }
120}
121
123{
124 // Set the default values
126
127 // Setup the low pass filter
128#ifdef USE_AIRSPEED_UAVCAN_LOWPASS_FILTER
130#endif
131
132 // Bind uavcan RAWAIRDATA message from EQUIPMENT.AIR_DATA
134
135#if PERIODIC_TELEMETRY
137#endif
138}
139
Main include for ABI (AirBorneInterface).
#define UAVCAN_SENDER_ID
float airspeed_filter
static void airspeed_uavcan_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
#define AIRSPEED_UAVCAN_DIFF_P_SCALE
static void airspeed_uavcan_downlink(struct transport_tx *trans, struct link_device *dev)
void airspeed_uavcan_autoset_offset(bool set)
struct airspeed_uavcan_t airspeed_uavcan
static uavcan_event airspeed_uavcan_ev
void airspeed_uavcan_init(void)
Airspeed sensor on the uavcan bus.
float temperature
Temperature in Celsius.
float diff_p_offset
Differential pressure offset.
float diff_p
Differential pressure.
float diff_p_scale
Differential pressure scale.
Main uavcan event structure for registering/calling callbacks.
Definition uavcan.h:60
static const float offset[]
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
Simple first order low pass filter with bilinear transform.
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
Second order low pass filter structure.
uint16_t foo
Definition main_demo5.c:58
static float sign(float x)
sign function
Definition nav_fish.c:232
uavcan interface structure
Definition uavcan.h:34
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_event *ev, uavcan_callback cb)
Bind to a receiving message from uavcan.
Definition uavcan.c:417
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
int transfer(const Mat *from, const image_t *to)