Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
sys_id_chirp.c
Go to the documentation of this file.
1/*
2 * Copyright (C) Joost Meulenbeld
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, see
18 * <http://www.gnu.org/licenses/>.
19 */
26#include "std.h"
27
28#include "sys_id_chirp.h"
29#include "pprz_chirp.h"
30
32#include "generated/airframe.h"
33#include "mcu_periph/sys_time.h"
35#include "math/pprz_random.h"
36
37
38#ifndef SYS_ID_CHIRP_AXES
39#define SYS_ID_CHIRP_AXES {COMMAND_ROLL,COMMAND_PITCH,COMMAND_YAW,COMMAND_THRUST}
40#endif
41
42#ifndef SYS_ID_CHIRP_ENABLED
43#define SYS_ID_CHIRP_ENABLED TRUE
44#endif
45
46#ifndef SYS_ID_CHIRP_USE_NOISE
47#define SYS_ID_CHIRP_USE_NOISE TRUE
48#endif
49
50#ifdef SYS_ID_CHIRP_RADIO_CHANNEL
53#endif
54
55// #ifndef SYS_ID_CHIRP_EXPONENTIAL
56// #define SYS_ID_CHIRP_EXPONENTIAL TRUE
57// #endif
58
59// #ifndef SYS_ID_CHIRP_FADEIN
60// #define SYS_ID_CHIRP_FADEIN TRUE
61// #endif
62
63
64static struct chirp_t chirp;
70float chirp_fstart_hz = 1.0f;
71float chirp_fstop_hz = 5.0f;
72float chirp_length_s = 20;
73
76
77// The axes on which noise and chirp values can be applied
79#define SYS_ID_CHIRP_NB_AXES sizeof SYS_ID_ACTIVE_CHIRP_AXES / sizeof SYS_ID_ACTIVE_CHIRP_AXES[0] // Number of items in ACTIVE_CHIRP_AXES
80
81// Filters used to cut-off the gaussian noise fed into the actuator channels
83
84// Chirp and noise values for all axes (indices correspond to the axes given in CHIRP_AXES)
86
87static void set_current_chirp_values(void)
88{
89 // initializing at zero the chirp input for every axis
90 for (uint8_t i = 0; i < SYS_ID_CHIRP_NB_AXES; i++) {
92 }
93 // adding values if the chirp is active
94 if (chirp_active) {
95 // adding extra on the chirp signal (both on-axis and off axis)
96 #if SYS_ID_CHIRP_USE_NOISE
97
98 float amplitude, noise;
99 for (uint8_t i = 0; i < SYS_ID_CHIRP_NB_AXES; i++) {
102 current_chirp_values[i] += (int32_t)(noise * amplitude);
103 }
104
105 #endif
106 // adding nominal chirp value
108 } else {
109 for (uint8_t i = 0; i < SYS_ID_CHIRP_NB_AXES; i++) {
111 }
112 }
113}
114
122
129
136
138{
140 #ifdef SYS_ID_CHIRP_RADIO_CHANNEL
141 // Don't activate chirp when radio signal is low
143 {
144 chirp_active = 0;
145 }
146 #endif
147 if (chirp_active) {
150 start_chirp();
151 } else {
152 stop_chirp();
153 }
154}
155
157{
158 return chirp_active;
159}
160
162{
165 }
166}
167
169{
170 if (fstart < chirp_fstop_hz) {
172 }
173}
174
176{
177 if (fstop > chirp_fstart_hz) {
179 }
180}
181
183{
184 chirp_fade_in = fade_in;
185}
186
191
193{
194#if SYS_ID_CHIRP_USE_NOISE
195
196 init_random();
197
198#endif
199
204
205 // Filter cutoff frequency is the chirp maximum frequency
206 float tau = 1 / (chirp_fstop_hz * 2 * M_PI);
207 for (uint8_t i = 0; i < SYS_ID_CHIRP_NB_AXES; i++) {
210 }
211}
212
214{
215#if SYS_ID_CHIRP_ENABLED
216
217 #ifdef SYS_ID_CHIRP_RADIO_CHANNEL
218 // Check if chirp switched on when off before
220 {
222 {
223 // Activate chirp
225 }
226 }
227 // Check if chirp switched off when on before
229 {
231 {
232 // Deactivate chirp
234 }
235 }
237 #endif
238
239 if (chirp_active) {
241 stop_chirp();
242 } else {
245 }
246 }
247
248#endif
249}
250
252{
253
254#if SYS_ID_CHIRP_ENABLED
255
256 if (motors_on) {
257 for (uint8_t i = 0; i < SYS_ID_CHIRP_NB_AXES; i++) {
260 }
261 }
262
263#endif
264}
#define UNUSED(x)
Simple first order low pass filter with bilinear transform.
static float update_first_order_low_pass(struct FirstOrderLowPass *filter, float value)
Update first order low pass filter state with a new value.
static void init_first_order_low_pass(struct FirstOrderLowPass *filter, float tau, float sample_time, float value)
Init first order low pass filter.
First order low pass filter structure.
uint16_t foo
Definition main_demo5.c:58
int16_t pprz_t
Definition paparazzi.h:6
#define MAX_PPRZ
Definition paparazzi.h:8
bool chirp_is_running(struct chirp_t *chirp, float current_time_s)
Return if the current_time is within the chirp manoeuvre.
Definition pprz_chirp.c:65
void chirp_init(struct chirp_t *chirp, float f0_hz, float f1_hz, float length_s, float current_time_s, bool exponential_chirp, bool fade_in)
Allocate and initialize a new chirp struct.
Definition pprz_chirp.c:34
float chirp_update(struct chirp_t *chirp, float current_time_s)
Calculate the value at current_time_s and update the struct with current frequency and value.
Definition pprz_chirp.c:71
void chirp_reset(struct chirp_t *chirp, float current_time_s)
Reset the time of the chirp.
Definition pprz_chirp.c:56
float current_frequency_hz
Definition pprz_chirp.h:66
float percentage_done
Definition pprz_chirp.h:69
float current_value
Definition pprz_chirp.h:67
Initialize with chirp_init.
Definition pprz_chirp.h:59
void init_random(void)
Definition pprz_random.c:35
double rand_gaussian(void)
Definition pprz_random.c:53
struct RadioControl radio_control
Generic interface for radio control modules.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
#define TRUE
Definition std.h:4
#define FALSE
Definition std.h:5
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
void sys_id_chirp_fstart_handler(float fstart)
static struct chirp_t chirp
float chirp_noise_stdv_onaxis_ratio
float chirp_length_s
#define SYS_ID_CHIRP_AXES
void sys_id_chirp_add_values(bool UNUSED motors_on, bool UNUSED override_on, pprz_t UNUSED in_cmd[])
void sys_id_chirp_activate_handler(uint8_t activate)
void sys_id_chirp_exponential_activate_handler(uint8_t exponential)
uint8_t chirp_active
void sys_id_chirp_run(void)
float chirp_noise_stdv_offaxis
static void stop_chirp(void)
float chirp_fstop_hz
pprz_t chirp_amplitude
float chirp_fstart_hz
uint8_t chirp_axis
void sys_id_chirp_axis_handler(uint8_t axis)
static void send_chirp(struct transport_tx *trans, struct link_device *dev)
uint8_t chirp_exponential
static pprz_t current_chirp_values[SYS_ID_CHIRP_NB_AXES]
uint8_t chirp_fade_in
static void set_current_chirp_values(void)
static struct FirstOrderLowPass filters[SYS_ID_CHIRP_NB_AXES]
uint8_t sys_id_chirp_running(void)
static const int8_t SYS_ID_ACTIVE_CHIRP_AXES[]
static void start_chirp(void)
#define SYS_ID_CHIRP_NB_AXES
void sys_id_chirp_fstop_handler(float fstop)
void sys_id_chirp_init(void)
void sys_id_chirp_fade_in_activate_handler(uint8_t fade_in)
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition sys_time.h:138
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
int int32_t
Typedef defining 32 bit int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.