Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
transport_delay.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Justin Dubois <j.p.g.dubois@student.tudelft.nl>
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 */
24#ifndef TRANSPORT_DELAY_H
25#define TRANSPORT_DELAY_H
26
27#include "paparazzi.h"
28
29#define TRANSPORT_DELAY_BUFFER_SIZE 20
30
32 uint8_t delay_samples; // Number of samples to delay
33 uint8_t write_index; // Current write index
35};
36
37
49static inline void init_transport_delay(struct TransportDelay *td, uint8_t delay_samples, const float initial_value)
50{
51 if (delay_samples > TRANSPORT_DELAY_BUFFER_SIZE) {
52 delay_samples = TRANSPORT_DELAY_BUFFER_SIZE;
53 }
54 td->delay_samples = delay_samples;
55 td->write_index = 0;
56 for (uint8_t i = 0; i < TRANSPORT_DELAY_BUFFER_SIZE; i++) {
57 td->buffer[i] = initial_value;
58 }
59}
60
68static inline float update_transport_delay(struct TransportDelay *td, const float input)
69{
70 td->buffer[td->write_index] = input;
72 float output = td->buffer[read_index];
73 td->write_index = (td->write_index + 1) % TRANSPORT_DELAY_BUFFER_SIZE;
74 return output;
75}
76
83static inline void reset_transport_delay(struct TransportDelay *td, const float initial_value)
84{
85 td->write_index = 0;
86 for (uint8_t i = 0; i < TRANSPORT_DELAY_BUFFER_SIZE; i++) {
87 td->buffer[i] = initial_value;
88 }
89}
90
97static inline float get_transport_delay(const struct TransportDelay *td)
98{
99 uint8_t read_index = (td->write_index + TRANSPORT_DELAY_BUFFER_SIZE - td->delay_samples - 1) %
101 return td->buffer[read_index];
102}
103
104#endif // TRANSPORT_DELAY_H
uint16_t foo
Definition main_demo5.c:58
static float get_transport_delay(const struct TransportDelay *td)
Get the current output value from the transport delay buffer without updating it.
static void init_transport_delay(struct TransportDelay *td, uint8_t delay_samples, const float initial_value)
Initialize a transport delay buffer.
float buffer[TRANSPORT_DELAY_BUFFER_SIZE]
static void reset_transport_delay(struct TransportDelay *td, const float initial_value)
Reset the transport delay buffer to a specific initial value.
static float update_transport_delay(struct TransportDelay *td, const float input)
Propagate a new input value through the transport delay buffer.
#define TRANSPORT_DELAY_BUFFER_SIZE
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.