Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
pprz_wave.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Alessandro Collicelli
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  */
27 #include "std.h"
28 #include "math.h"
29 
30 #include "pprz_wave.h"
31 
32 
33 void wave_init(struct wave_t *wave, float start_time_s, float current_time_s, float frequency_hz, float lag_rad)
34 {
35  wave->start_time_s = start_time_s;
36  wave->current_time_s = current_time_s;
37  wave->lag_rad = lag_rad;
38  wave->frequency_hz = frequency_hz;
39  wave->is_running = false;
40  wave->current_value = 0.0f;
41 
42 
43 }
44 
45 void wave_reset(struct wave_t *wave, float current_time_s)
46 {
47  wave->start_time_s = current_time_s;
48  wave->current_time_s = current_time_s;
49  wave->current_value = 0.0f;
50 }
51 
52 bool wave_is_running(struct wave_t *wave){
53 
54  return wave->is_running;
55 }
56 
57 float wave_update(struct wave_t *wave, float current_time_s){
58  float frequency_rad = wave->frequency_hz * 2 * M_PI;
59  float t = current_time_s - wave->start_time_s;
60  wave->current_value = sinf(t*frequency_rad + wave->lag_rad);
61  return wave->current_value;
62 }
void wave_reset(struct wave_t *wave, float current_time_s)
Definition: pprz_wave.c:45
float wave_update(struct wave_t *wave, float current_time_s)
Definition: pprz_wave.c:57
bool wave_is_running(struct wave_t *wave)
Definition: pprz_wave.c:52
void wave_init(struct wave_t *wave, float start_time_s, float current_time_s, float frequency_hz, float lag_rad)
Definition: pprz_wave.c:33
float current_time_s
Definition: pprz_wave.h:36
float current_value
Definition: pprz_wave.h:39
float frequency_hz
Definition: pprz_wave.h:38
float lag_rad
Definition: pprz_wave.h:37
float start_time_s
Definition: pprz_wave.h:35
bool is_running
Definition: pprz_wave.h:40