Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
sys_id_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  */
34 #include "std.h"
35 #include "math.h"
36 #include "pprz_wave.h"
37 
38 #include "sys_id_wave.h"
39 
41 #include "generated/airframe.h"
42 #include "mcu_periph/sys_time.h"
44 #include "math/pprz_random.h"
45 
46 #ifndef WAVE_AXES
47 #define WAVE_AXES {COMMAND_ROLL,COMMAND_PITCH,COMMAND_YAW,COMMAND_THRUST}
48 #endif
49 
50 #ifndef WAVE_ENABLED
51 #define WAVE_ENABLED TRUE
52 #endif
53 
54 
55 
56 static struct wave_t wave_s;
60 float frequency_hz_ = 0.0f;
61 float lag_rad_ = 0.0f;
62 
64 #define WAVE_NB_AXES sizeof ACTIVE_WAVE_AXES / sizeof ACTIVE_WAVE_AXES[0] // Number of items in ACTIVE_WAVE_AXES
65 
66 // Chirp and noise values for all axes (indices correspond to the axes given in WAVE_AXES)
68 
69 static void set_current_wave_values(void){
70  if (wave_active){
72  wave_s.is_running = true;
73  }
74  else{
75  for (uint8_t i = 0; i < WAVE_NB_AXES; i++) {
76  current_wave_values[i] = 0;
77  wave_s.is_running = false;
78  }
79  }
80 }
81 static void send_wave(struct transport_tx *trans, struct link_device *dev){
82  pprz_msg_send_WAVE(trans, dev, AC_ID, &wave_active, &wave_axis, &wave_amplitude, &wave_s.lag_rad, &wave_s.frequency_hz,
84 }
85 
86 static void start_wave(void){
88  wave_active = true;
90 
91 }
92 
93 static void stop_wave(void){
95  wave_active = false;
97 
98 }
99 
101  wave_active = activate;
102  if (wave_active) {
104  start_wave();
105  } else {
106  stop_wave();
107  }
108 }
109 
111 {
112  if (axis < WAVE_NB_AXES) {
113  wave_axis = axis;
114  }
115 }
116 
117 
119  return wave_active;
120 }
121 
122 
123 void sys_id_wave_frequency_hz_set(float frequency_hz_set)
124 {
125  frequency_hz_ = frequency_hz_set;
127 }
128 
129 void sys_id_wave_lag_rad_set(float lag_rad_set)
130 {
131  lag_rad_ = lag_rad_set;
133 }
134 
135 
137 {
141 
142 }
143 
144 void sys_id_wave_run(void)
145 {
146 // #if WAVE_ENABLED
147 
148  if (wave_active) {
149  if (!wave_is_running(&wave_s)) {
150  stop_wave();
151  } else {
154  }
155  }
156 // #endif
157 }
158 
159 void sys_id_wave_add_values(bool motors_on, bool override_on, pprz_t in_cmd[])
160 {
161  (void)(override_on); // Suppress unused parameter warnings
162 
163 #if WAVE_ENABLED
164 
165 if (motors_on) {
166  for (uint8_t i = 0; i < WAVE_NB_AXES; i++) {
167  in_cmd[ACTIVE_WAVE_AXES[i]] += current_wave_values[i];
168  BoundAbs(in_cmd[ACTIVE_WAVE_AXES[i]], MAX_PPRZ);
169  }
170 }
171 
172 #endif
173 }
Simple first order low pass filter with bilinear transform.
int16_t pprz_t
Definition: paparazzi.h:6
#define MAX_PPRZ
Definition: paparazzi.h:8
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_value
Definition: pprz_wave.h:39
float frequency_hz
Definition: pprz_wave.h:38
float lag_rad
Definition: pprz_wave.h:37
bool is_running
Definition: pprz_wave.h:40
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
static void stop_wave(void)
Definition: sys_id_wave.c:93
static pprz_t current_wave_values[WAVE_NB_AXES]
Definition: sys_id_wave.c:67
static void start_wave(void)
Definition: sys_id_wave.c:86
static void set_current_wave_values(void)
Definition: sys_id_wave.c:69
static void send_wave(struct transport_tx *trans, struct link_device *dev)
Definition: sys_id_wave.c:81
float frequency_hz_
Definition: sys_id_wave.c:60
static struct wave_t wave_s
Definition: sys_id_wave.c:56
void sys_id_wave_init(void)
Definition: sys_id_wave.c:136
void sys_id_wave_run(void)
Definition: sys_id_wave.c:144
#define WAVE_AXES
Definition: sys_id_wave.c:47
void sys_id_wave_add_values(bool motors_on, bool override_on, pprz_t in_cmd[])
Definition: sys_id_wave.c:159
void sys_id_wave_lag_rad_set(float lag_rad_set)
Definition: sys_id_wave.c:129
#define WAVE_NB_AXES
Definition: sys_id_wave.c:64
uint8_t wave_active
Definition: sys_id_wave.c:57
uint8_t wave_axis
Definition: sys_id_wave.c:58
pprz_t wave_amplitude
Definition: sys_id_wave.c:59
void sys_id_wave_frequency_hz_set(float frequency_hz_set)
Definition: sys_id_wave.c:123
float lag_rad_
Definition: sys_id_wave.c:61
void sys_id_wave_axis_handler(uint8_t axis)
Definition: sys_id_wave.c:110
uint8_t sys_id_wave_running(void)
Definition: sys_id_wave.c:118
void sys_id_wave_activate_handler(uint8_t activate)
Definition: sys_id_wave.c:100
static const int8_t ACTIVE_WAVE_AXES[]
Definition: sys_id_wave.c:63
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
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103