Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
pprz_chirp.c File Reference
#include "pprz_chirp.h"
#include "std.h"
+ Include dependency graph for pprz_chirp.c:

Go to the source code of this file.

Macros

#define CHIRP_C1   4.0f
 
#define CHIRP_C2   1.0f / (expf(CHIRP_C1) - 1)
 

Functions

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. More...
 
void chirp_reset (struct chirp_t *chirp, float current_time_s)
 Reset the time of the chirp. More...
 
bool chirp_is_running (struct chirp_t *chirp, float current_time_s)
 Return if the current_time is within the chirp manoeuvre. More...
 
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. More...
 

Detailed Description

Author
Joost Meulenbeld Mathematical implementation of the chirp
Joost Meulenbeld

Mathematical implementation of the chirp A "chirp" or frequency sweep is a sine wave with in time increasing frequency, and can be used for system identification purposes. This registers a broad frequency spectrum.

Chirps can be made with frequency increasing linearly or exponentially with time. This is set using an argument in the chirp_init method. The latter one is better for system identification, according to [2].

The time length of the chirp is best put at a minimum of 4 / f_minimum such that low-frequency effects can be correctly discovered.

The fade_in argument determines if the chirp fades in with increasing amplitude at constant frequency (the lowest frequency). This makes it much easier to maintain the UAV around the trim position.

Usage example: // Initialize a chirp between 1 and 5 Hz during 2 seconds (for sys. id. use minimum of 4 * 1/f0) struct chirp_t chirp; chirp_init(&chirp, 1, 5, 2, get_current_time());

// During flight loop, add chirp value to stick input while (chirp_is_running(chirp, get_current_time())) { control[YAW] = stick_control + chirp_update(chirp, get_current_time()); }

[1] https://en.wikipedia.org/wiki/Chirp for a derivation of the linear chirp [2] Aircraft and Rotorcraft System Identification, 2nd edition by M. Tischler for a derivation of exponential chirp

Definition in file pprz_chirp.c.

Macro Definition Documentation

◆ CHIRP_C1

#define CHIRP_C1   4.0f

Definition at line 29 of file pprz_chirp.c.

◆ CHIRP_C2

#define CHIRP_C2   1.0f / (expf(CHIRP_C1) - 1)

Definition at line 30 of file pprz_chirp.c.

Function Documentation

◆ chirp_init()

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.

set start_time to the current time

Parameters
f0_hzMinimum frequency of the chirp in Hz
f1_hzMaximum frequency of the chirp in Hz
length_sTime interval in s (starting from start_time_s) in which the chirp should be carried out, excluding fade-in time
current_time_sCurrent time in s, starting point of the chirp
exponential_chirpIf true, use exponential-time chirp, otherwise use linear-time chirp (see wikipedia)
fade_inIf true, begin the chirp with 2 wavelengths of the lowest frequency, with increasing amplitude

Definition at line 34 of file pprz_chirp.c.

References chirp, chirp_t::current_frequency_hz, chirp_t::current_value, chirp_t::exponential_chirp, chirp_t::f0_hz, chirp_t::f1_hz, chirp_t::fade_in, chirp_t::length_s, chirp_t::percentage_done, chirp_t::start_time_s, and chirp_t::total_length_s.

Referenced by sys_id_chirp_activate_handler(), and sys_id_chirp_init().

+ Here is the caller graph for this function:

◆ chirp_is_running()

bool chirp_is_running ( struct chirp_t chirp,
float  current_time_s 
)

Return if the current_time is within the chirp manoeuvre.

Definition at line 65 of file pprz_chirp.c.

References chirp, chirp_t::start_time_s, and chirp_t::total_length_s.

Referenced by chirp_update(), and sys_id_chirp_run().

+ Here is the caller graph for this function:

◆ chirp_reset()

void chirp_reset ( struct chirp_t chirp,
float  current_time_s 
)

Reset the time of the chirp.

Parameters
chirpThe chirp struct pointer to reset
current_time_sThe time to set the chirp start at

Definition at line 56 of file pprz_chirp.c.

References chirp, chirp_t::current_frequency_hz, chirp_t::current_time_s, chirp_t::current_value, chirp_t::percentage_done, and chirp_t::start_time_s.

Referenced by start_chirp(), and stop_chirp().

+ Here is the caller graph for this function:

◆ chirp_update()

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.

Returns
Current value chirp->current_value

Definition at line 71 of file pprz_chirp.c.

References chirp, CHIRP_C1, CHIRP_C2, chirp_is_running(), chirp_t::current_frequency_hz, chirp_t::current_time_s, chirp_t::current_value, chirp_t::exponential_chirp, chirp_t::f0_hz, chirp_t::f1_hz, chirp_t::fade_in, K, chirp_t::length_s, Min, chirp_t::percentage_done, chirp_t::start_time_s, and chirp_t::total_length_s.

Referenced by sys_id_chirp_run().

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